public class Point2D
extends java.lang.Object
NOTE: This class requires Sedgewick's and Wayne's StdDraw library.
Constructor and Description |
---|
Point2D(double x,
double y)
Construct a point with given x and y coordinate values.
|
Point2D(Point2D p)
Copy constructor - makes a copy of the specified point.
|
Modifier and Type | Method and Description |
---|---|
static int |
collinearMid(Point2D[] pts,
int i,
int j,
int k)
If the three points at the specified indices in pts are collinear,
return index of 'middle' point, otherwise return -1 |
static int |
collinearMid(Point2D[] pts,
int i,
int j,
int k,
double delta)
If the three points at the specified indices in pts are collinear (within a given precision error),
return index of 'middle' point, otherwise return -1 |
double |
distanceTo(Point2D p)
Distance from this point to another point p.
|
void |
draw()
Draw this point using the current StdDraw color and pen width.
|
void |
draw(java.awt.Color clr)
Draw this point with a specified color.
|
void |
draw(java.awt.Color clr,
double penWidth)
Draw this point with a specified color and pen width.
|
void |
drawTo(Point2D p)
Draw a line from this point to anther point p using the current StdDraw color and pen width.
|
void |
drawTo(Point2D p,
java.awt.Color clr)
Draw a line from this point to anther point p using a specified color.
|
void |
drawTo(Point2D p,
java.awt.Color clr,
double penWidth)
Draw a line from this point to anther point p using a specified color and pen width.
|
boolean |
isEqual(Point2D p)
Test if this point is coincident with another point p.
|
Point2D |
midPoint(Point2D p)
Get mid-point of this point and another point p.
|
static void |
polyDemo(int numSides)
Demonstrator for the Point2D class.
|
java.lang.String |
toString()
Get string representation of this point in the form "(x,y)".
|
double |
X()
Get x-coordinate of this point.
|
double |
Y()
Get y-coordinate of this point.
|
public Point2D(double x, double y)
x
- coordinate of pointy
- coordinate of pointpublic Point2D(Point2D p)
p
- point to copypublic static int collinearMid(Point2D[] pts, int i, int j, int k)
pts
- array of Point2Di
- index of first pointj
- index of second pointk
- index of third pointpublic static int collinearMid(Point2D[] pts, int i, int j, int k, double delta)
pts
- array of Point2Di
- index of first pointj
- index of second pointk
- index of third pointdelta
- allowable precision errorpublic double distanceTo(Point2D p)
p
- other pointpublic void draw()
public void draw(java.awt.Color clr)
clr
- the pen color to usepublic void draw(java.awt.Color clr, double penWidth)
clr
- the pen color to usepenWidth
- width of the pen to usepublic void drawTo(Point2D p)
p
- other pointpublic void drawTo(Point2D p, java.awt.Color clr)
p
- the point to drawclr
- the pen color to usepublic void drawTo(Point2D p, java.awt.Color clr, double penWidth)
p
- the point to drawclr
- the pen color to usepenWidth
- width of the pen to usepublic boolean isEqual(Point2D p)
p
- point to compare this point topublic Point2D midPoint(Point2D p)
p
- other pointpublic static void polyDemo(int numSides)
numSides
- number of sides of polygonjava.lang.IllegalArgumentException
- if numSides is less than 3public java.lang.String toString()
toString
in class java.lang.Object
public double X()
public double Y()