]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/function/compress/XYpoint.java
Version 13, August 2011
[GpsPrune.git] / tim / prune / function / compress / XYpoint.java
1 package tim.prune.function.compress;
2
3 /**
4  * Basic class to hold x and y coordinates
5  * for a point or a vector
6  */
7 public class XYpoint
8 {
9         // x and y coordinates
10         public double x = 0.0, y = 0.0;
11
12         /**
13          * Empty constructor
14          */
15         public XYpoint() {
16                 this(0.0, 0.0);
17         }
18
19         /**
20          * Constructor
21          * @param inX x value
22          * @param inY y value
23          */
24         public XYpoint(double inX, double inY) {
25                 x = inX; y = inY;
26         }
27
28         /**
29          * @param inOther other vector
30          * @return scalar dot product
31          */
32         public double dot(XYpoint inOther) {
33                 return (x * inOther.x + y * inOther.y);
34         }
35
36         /** @return length of vector */
37         public double len() {return Math.sqrt(len2());}
38
39         /** @return squared length of vector */
40         public double len2() {return (x*x + y*y);}
41
42         /**
43          * @param inOther other point object
44          * @return vector from this one to the other one
45          */
46         public XYpoint vectorTo(XYpoint inOther) {
47                 return new XYpoint(inOther.x - x, inOther.y - y);
48         }
49 }