public class Point2D extends java.lang.Object implements java.lang.Comparable<Point2D>
For additional documentation, see Section 1.2 of Algorithms, 4th Edition, by Robert Sedgewick and Kevin Wayne.
Modifier and Type | Field and Description |
---|---|
java.util.Comparator<Point2D> |
ATAN2_ORDER
Compares two points by atan2() angle (between -pi and pi) with respect to this point.
|
java.util.Comparator<Point2D> |
DISTANCE_TO_ORDER
Compares two points by distance to this point.
|
java.util.Comparator<Point2D> |
POLAR_ORDER
Compares two points by polar angle (between 0 and 2pi) with respect to this point.
|
static java.util.Comparator<Point2D> |
R_ORDER
Compares two points by polar radius.
|
static java.util.Comparator<Point2D> |
X_ORDER
Compares two points by x-coordinate.
|
static java.util.Comparator<Point2D> |
Y_ORDER
Compares two points by y-coordinate.
|
Constructor and Description |
---|
Point2D(double x,
double y)
Initializes a new point (x, y).
|
Modifier and Type | Method and Description |
---|---|
static double |
area2(Point2D a,
Point2D b,
Point2D c)
Returns twice the signed area of the triangle a-b-c.
|
static int |
ccw(Point2D a,
Point2D b,
Point2D c)
Is a->b->c a counterclockwise turn?
|
int |
compareTo(Point2D that)
Compares this point to that point by y-coordinate, breaking ties by x-coordinate.
|
double |
distanceSquaredTo(Point2D that)
Returns the square of the Euclidean distance between this point and that point.
|
double |
distanceTo(Point2D that)
Returns the Euclidean distance between this point and that point.
|
void |
draw()
Plot this point using standard draw.
|
void |
drawTo(Point2D that)
Plot a line from this point to that point using standard draw.
|
boolean |
equals(java.lang.Object other)
Does this point equal y?
|
int |
hashCode()
Returns an integer hash code for this point.
|
static void |
main(java.lang.String[] args)
Unit tests the point data type.
|
double |
r()
Returns the polar radius of this point.
|
double |
theta()
Returns the angle of this point in polar coordinates.
|
java.lang.String |
toString()
Return a string representation of this point.
|
double |
x()
Returns the x-coordinate.
|
double |
y()
Returns the y-coordinate.
|
public static final java.util.Comparator<Point2D> X_ORDER
public static final java.util.Comparator<Point2D> Y_ORDER
public static final java.util.Comparator<Point2D> R_ORDER
public final java.util.Comparator<Point2D> POLAR_ORDER
public final java.util.Comparator<Point2D> ATAN2_ORDER
public final java.util.Comparator<Point2D> DISTANCE_TO_ORDER
public Point2D(double x, double y)
x
- the x-coordinatey
- the y-coordinatejava.lang.IllegalArgumentException
- if either x or y
is Double.NaN, Double.POSITIVE_INFINITY or
Double.NEGATIVE_INFINITYpublic double x()
public double y()
public double r()
public double theta()
public static int ccw(Point2D a, Point2D b, Point2D c)
a
- first pointb
- second pointc
- third pointpublic static double area2(Point2D a, Point2D b, Point2D c)
a
- first pointb
- second pointc
- third pointpublic double distanceTo(Point2D that)
that
- the other pointpublic double distanceSquaredTo(Point2D that)
that
- the other pointpublic int compareTo(Point2D that)
compareTo
in interface java.lang.Comparable<Point2D>
that
- the other pointpublic boolean equals(java.lang.Object other)
equals
in class java.lang.Object
other
- the other pointpublic java.lang.String toString()
toString
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public void draw()
public void drawTo(Point2D that)
that
- the other pointpublic static void main(java.lang.String[] args)