2 * Copyright (c) 2002 Erik Rasmussen - All Rights Reserverd
4 package appletbots
.geometry
;
7 * This class represents a point in two-dimensional space
9 * @author Erik Rasmussen
23 * Creates a new point with the given coordinates
25 * @param x The x-coordinate
26 * @param y The y-coordinate
28 public Point(final double x
, final double y
)
35 * Returns the distance between this point and another point
37 * @param point Another point
38 * @return The distance between this point and another point
40 public double distance(final Point point
)
42 final double px
= point
.x
- x
;
43 final double py
= point
.y
- y
;
44 return Math
.sqrt(px
* px
+ py
* py
);
48 * Returns the result of adding a vector to this point
50 * @param vector The vector to add
51 * @return The result of adding a vector to this point
53 public Point
add(final Vector vector
)
55 return new Point(x
+ vector
.x
, y
+ vector
.y
);
59 * Returns whether or not this point equals another point
61 * @param obj Another point
62 * @return Whether or not this point equals another point
64 public boolean equals(final Object obj
)
66 if (obj
instanceof Point
)
68 final Point that
= (Point
) obj
;
69 return this.x
== that
.x
&& this.y
== that
.y
;
75 * Returns a copy of this point
77 * @return A copy of this point
81 return new Point(x
, y
);
85 * Returns a string representation of this point
87 * @return A string representation of this point
89 public String
toString()
91 return "(" + x
+ "," + y
+ ")";