public class Point2
extends java.lang.Object
Point2D
instance has an
x and y coordinate.Constructor and Description |
---|
Point2()
Create a point with coordinates
(0, 0) . |
Point2(double newX,
double newY)
Create a point with coordinates
(newX, newY) . |
Point2(Point2 other)
Create a point with the same coordinates as
other . |
Modifier and Type | Method and Description |
---|---|
Point2 |
add(Vector2 v)
Adds a vector to this point changing the coordinates of this point.
|
boolean |
equals(java.lang.Object obj)
Compares this point with the given object.
|
double |
getX()
Returns the x-coordinate of this point.
|
double |
getY()
Returns the y-coordinate of this point.
|
int |
hashCode()
Returns a hash code for this point
|
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).
|
static Vector2 |
subtract(Point2 a,
Point2 b)
Returns a new
Point2 equal to a - b . |
java.lang.String |
toString()
Returns a string representation of this point.
|
public Point2()
(0, 0)
.public Point2(double newX, double newY)
(newX, newY)
.newX
- the x-coordinate of the pointnewY
- 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 Point2 add(Vector2 v)
Mathematically, if this point is a
and the vector is
v
then invoking this method is equivalent to computing
a + v
and assigning the value back to a
.
v
- a vectorPoint2
objectpublic static Vector2 subtract(Point2 a, Point2 b)
Point2
equal to a - b
.a
- a pointb
- another pointPoint2
equal to a - b
public java.lang.String toString()
toString
in class java.lang.Object
Object.toString()
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
true
if and only if the argument is not null
and is a Point2
object having the same coordinates as this
object.equals
in class java.lang.Object
obj
- the object to compare this vector againsttrue
if the given object represents a
Point2
equivalent to this point,
false
otherwisepublic boolean similarTo(Point2 other, double tol)
other
- the other point to comparetol
- the threshold length of the vector difference
(this - other)
true
if the length of (this - other)
is
less than tol
, and false
otherwise