public class Point2
extends java.lang.Object
Constructor and Description |
---|
Point2()
Initialize the point to have coordinates
(0, 0) . |
Point2(double x,
double y)
Initialize the point to have coordinates
(x, y) . |
Point2(Point2 other)
Initialize a point to have the same coordinates as
other . |
Modifier and Type | Method and Description |
---|---|
double |
distanceTo(Point2 other)
Returns the distance between this point and another point.
|
double |
getX()
Returns the x-coordinate of this point.
|
double |
getY()
Returns the y-coordinate of this point.
|
void |
moveX(double dx)
Move the point in the x direction by an amount dx.
|
void |
moveY(double dy)
Move the point in the y direction by an amount dy.
|
void |
set(double newX,
double newY)
Sets the x-coordinate and y-coordinate of this point to
newX
and newY , respectively. |
void |
setX(double newX)
Sets the x-coordinate of this point to
newX . |
void |
setY(double newY)
Sets the y-coordinate of this point to
newY . |
boolean |
similarTo(Point2 other,
double tol)
Determines if two points are almost equal (similar).
|
java.lang.String |
toString()
Returns a string representation of this point.
|
public Point2()
(0, 0)
.public Point2(double x, double y)
(x, y)
.x
- the x-coordinate of the pointy
- the y-coordinate of the pointpublic Point2(Point2 other)
other
.other
- another pointpublic double getX()
public double getY()
public void setX(double newX)
newX
.newX
- the new x-coordinate of this pointpublic void setY(double newY)
newY
.newY
- the new y-coordinate of this pointpublic void set(double newX, double newY)
newX
and newY
, respectively.newX
- the new x-coordinate of this pointnewY
- the new y-coordinate of this pointpublic void moveX(double dx)
(this.getX() + dx)
.dx
- the change in the x coordinate of this pointpublic void moveY(double dy)
(this.getY() + dy)
.dy
- the change in the y coordinate of this pointpublic double distanceTo(Point2 other)
other
- another pointpublic boolean similarTo(Point2 other, double tol)
other
- the other point to comparetol
- the threshold distance between this point and otherpublic java.lang.String toString()
toString
in class java.lang.Object