public class Point2D extends Object
Modifier and Type | Field and Description |
---|---|
static Point2D |
ZERO
Point or vector with both coordinates set to 0.
|
Constructor and Description |
---|
Point2D(double x,
double y)
Creates a new instance of
Point2D . |
Modifier and Type | Method and Description |
---|---|
Point2D |
add(double x,
double y)
Returns a point with the specified coordinates added to the coordinates
of this point.
|
Point2D |
add(Point2D point)
Returns a point with the coordinates of the specified point added to the
coordinates of this point.
|
double |
angle(double x,
double y)
Computes the angle (in degrees) between the vector represented
by this point and the specified vector.
|
double |
angle(Point2D point)
Computes the angle (in degrees) between the vector represented
by this point and the vector represented by the specified point.
|
double |
angle(Point2D p1,
Point2D p2)
Computes the angle (in degrees) between the three points with this point
as a vertex.
|
Point3D |
crossProduct(double x,
double y)
Computes cross product of the vector represented by this instance
and the specified vector.
|
Point3D |
crossProduct(Point2D vector)
Computes cross product of the vector represented by this instance
and the specified vector.
|
double |
distance(double x1,
double y1)
Computes the distance between this point and point
(x1, y1) . |
double |
distance(Point2D point)
Computes the distance between this point and the specified
point . |
double |
dotProduct(double x,
double y)
Computes dot (scalar) product of the vector represented by this instance
and the specified vector.
|
double |
dotProduct(Point2D vector)
Computes dot (scalar) product of the vector represented by this instance
and the specified vector.
|
boolean |
equals(Object obj)
Indicates whether some other object is "equal to" this one.
|
double |
getX()
The x coordinate.
|
double |
getY()
The y coordinate.
|
int |
hashCode()
Returns a hash code value for the point.
|
double |
magnitude()
Computes magnitude (length) of the relative magnitude vector represented
by this instance.
|
Point2D |
midpoint(double x,
double y)
Returns a point which lies in the middle between this point and the
specified coordinates.
|
Point2D |
midpoint(Point2D point)
Returns a point which lies in the middle between this point and the
specified point.
|
Point2D |
multiply(double factor)
Returns a point with the coordinates of this point multiplied
by the specified factor
|
Point2D |
normalize()
Normalizes the relative magnitude vector represented by this instance.
|
Point2D |
subtract(double x,
double y)
Returns a point with the specified coordinates subtracted from
the coordinates of this point.
|
Point2D |
subtract(Point2D point)
Returns a point with the coordinates of the specified point subtracted
from the coordinates of this point.
|
String |
toString()
Returns a string representation of this
Point2D . |
public static final Point2D ZERO
public Point2D(double x, double y)
Point2D
.x
- the x coordinate of the pointy
- the y coordinate of the pointpublic final double getX()
public final double getY()
public double distance(double x1, double y1)
(x1, y1)
.x1
- the x coordinate of other pointy1
- the y coordinate of other point(x1, y1)
.public double distance(Point2D point)
point
.point
- the other pointpoint
.NullPointerException
- if the specified point
is nullpublic Point2D add(double x, double y)
x
- the X coordinate additiony
- the Y coordinate additionpublic Point2D add(Point2D point)
point
- the point whose coordinates are to be addedNullPointerException
- if the specified point
is nullpublic Point2D subtract(double x, double y)
x
- the X coordinate subtractiony
- the Y coordinate subtractionpublic Point2D multiply(double factor)
factor
- the factor multiplying the coordinatespublic Point2D subtract(Point2D point)
point
- the point whose coordinates are to be subtractedNullPointerException
- if the specified point
is nullpublic Point2D normalize()
Point2D
instancepublic Point2D midpoint(double x, double y)
x
- the X coordinate of the second endpointy
- the Y coordinate of the second endpointpublic Point2D midpoint(Point2D point)
point
- the other endpointNullPointerException
- if the specified point
is nullpublic double angle(double x, double y)
x
- the X magnitude of the other vectory
- the Y magnitude of the other vectorpublic double angle(Point2D point)
point
- the other vectorNaN
if any of the two vectors is a zero vectorNullPointerException
- if the specified point
is nullpublic double angle(Point2D p1, Point2D p2)
p1
- one pointp2
- other pointNaN
if the three points are not different
from one anotherNullPointerException
- if p1
or p2
is nullpublic double magnitude()
public double dotProduct(double x, double y)
x
- the X magnitude of the other vectory
- the Y magnitude of the other vectorpublic double dotProduct(Point2D vector)
vector
- the other vectorNullPointerException
- if the specified vector
is nullpublic Point3D crossProduct(double x, double y)
x
- the X magnitude of the other vectory
- the Y magnitude of the other vectorpublic Point3D crossProduct(Point2D vector)
vector
- the other vectorNullPointerException
- if the specified vector
is nullpublic boolean equals(Object obj)
public int hashCode()
public String toString()
Point2D
.
This method is intended to be used only for informational purposes.
The content and format of the returned string might vary between
implementations.
The returned string might be empty but cannot be null
.Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 2008, 2017, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.