001    /**
002     * 
003     */
004    package org.wdssii.core;
005    
006    /**
007     * location in a cartesian grid situated at the earth's center. Based on Thomas
008     * Vaughan's CPoint class in the C++ version.
009     * 
010     * @author Lakshman
011     * @version $Id: CPoint.java,v 1.2 2007/10/12 14:40:58 lakshman Exp $
012     */
013    public class CPoint {
014            public double x;
015    
016            public double y;
017    
018            public double z;
019    
020            /**
021             * everything in kilometers. the z direction is the polar axis. x is from
022             * center through the Greenwich meridian y is from the center of earth
023             * through the Caribbean.
024             */
025            public CPoint(double x, double y, double z) {
026                    this.x = x;
027                    this.y = y;
028                    this.z = z;
029            }
030    
031            public CVector minus(CPoint pt) {
032                    return new CVector(x - pt.x, y - pt.y, z - pt.z);
033            }
034    
035            public Location getLocation() {
036                    double r = Math.sqrt(x * x + y * y + z * z);
037                    double lat = Math.asin(z / r) * 180 / Math.PI;
038                    double lon = Math.atan2(y, x) * 180 / Math.PI;
039                    double h = (r - Location.EarthRadius);
040                    return new Location(lat, lon, h);
041            }
042    
043            public CPoint plus(CVector v) {
044                    return new CPoint(x + v.x, y + v.y, z + v.z);
045            }
046    
047            public String toString() {
048                    return "(point: " + x + "," + y + "," + z + ")";
049            }
050    }