X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=gps%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fgps%2Fgeometry%2FSphericalCoordinateSystem.java;fp=gps%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fgps%2Fgeometry%2FSphericalCoordinateSystem.java;h=d62cef8815394fef4da64396f98a45901dcb8064;hb=4a27bb58a18d180cfd21ba0d59c35d775dec064c;hp=0000000000000000000000000000000000000000;hpb=c2ca8438bcaa20bfe3e90bb379343c019c33f339;p=utils diff --git a/gps/src/main/java/org/wamblee/gps/geometry/SphericalCoordinateSystem.java b/gps/src/main/java/org/wamblee/gps/geometry/SphericalCoordinateSystem.java new file mode 100644 index 00000000..d62cef88 --- /dev/null +++ b/gps/src/main/java/org/wamblee/gps/geometry/SphericalCoordinateSystem.java @@ -0,0 +1,61 @@ +/* + * Copyright 2006 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.wamblee.gps.geometry; + +import static java.lang.Math.PI; +import static java.lang.Math.cos; +import static java.lang.Math.sin; + + +/** + * Represents the coordinate system for a GPS measurement identified by + * + * This coordinate system models the earth as a sphere of a specific radius. + */ +public class SphericalCoordinateSystem implements CoordinateSystem { + /** + * Earth radius in meters. + */ + private static final double EARTH_RADIUS = 6371000; + + + /* (non-Javadoc) + * @see org.wamblee.gpx.CoordinateSystem#toReferenceSystem(org.wamblee.gpx.Coordinates) + */ + public Coordinates toReferenceSystem(Coordinates aCoordinates) { + double latrad = radians(aCoordinates.getX1()); + double lonrad = radians(aCoordinates.getX2()); + double coslat = cos(latrad); + double sinlat = sin(latrad); + double coslon = cos(lonrad); + double sinlon = sin(lonrad); + + double trueElevation = EARTH_RADIUS + aCoordinates.getX3(); + return new Coordinates(trueElevation*coslat*coslon, + trueElevation*coslat*sinlon, + trueElevation*sinlat); + + } + + private double radians(double aDegrees) { + return aDegrees/180.0*PI; + } +}