(no commit message)
[utils] / gps / src / main / java / org / wamblee / gps / geometry / ReferenceCoordinateSystem.java
1 /*
2  * Copyright 2006 the original author or authors.
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  * 
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.wamblee.gps.geometry;
18
19
20 /**
21  * Reference coordinate system which is the basis for defining metrics.
22  * This is a Cartesian coordinate system.  
23  *
24  * @author Erik Brakkee
25  */
26 public class ReferenceCoordinateSystem implements CoordinateSystem {
27
28     /**
29      * Constructs the coordinate system. 
30      *
31      */
32     public ReferenceCoordinateSystem() {
33         // Empty
34     }
35
36     /*
37      * (non-Javadoc)
38      * 
39      * @see org.wamblee.gpx.CoordinateSystem#toReferenceSystem(org.wamblee.gpx.Coordinates)
40      */
41     public Coordinates toReferenceSystem(Coordinates aCoordinates) {
42         return aCoordinates;
43     }
44
45     /*
46      * (non-Javadoc)
47      * 
48      * @see org.wamblee.gpx.CoordinateSystem#distance(org.wamblee.gpx.Coordinates,
49      *      org.wamblee.gpx.Coordinates)
50      */
51     private static double distance(Coordinates aC1, Coordinates aC2) {
52         return Math.sqrt(square(aC1.getX1() - aC2.getX1())
53                 + square(aC1.getX2() - aC2.getX2())
54                 + square(aC1.getX3() - aC2.getX3()));
55     }
56
57     private static double square(double x) {
58         return x * x;
59     }
60     
61     /**
62      * Computes the distance between two points in arbitrary coordinate systems. 
63      * @param aP1 First point. 
64      * @param aP2 Second point. 
65      * @return Distance. 
66      */
67     public static double distance(Point aP1, Point aP2) { 
68         return distance( aP1.getCoordinateSystem().toReferenceSystem(aP1.getCoordinates()), 
69                          aP2.getCoordinateSystem().toReferenceSystem(aP2.getCoordinates()));
70     }
71
72 }