Class Point2D
- javafx.geometry.Point2D
public class Point2D extends Object
Since:
JavaFX 2.0
-
Field Summary
Fields Modifier and Type Field and Description static Point2DZEROPoint or vector with both coordinates set to 0.
-
Constructor Summary
Constructors Constructor and Description Point2D(double x, double y)Creates a new instance ofPoint2D.
-
Method Summary
All MethodsInstance MethodsConcrete Methods Modifier and Type Method and Description Point2Dadd(double x, double y)Returns a point with the specified coordinates added to the coordinates of this point.Point2Dadd(Point2D point)Returns a point with the coordinates of the specified point added to the coordinates of this point.doubleangle(double x, double y)Computes the angle (in degrees) between the vector represented by this point and the specified vector.doubleangle(Point2D point)Computes the angle (in degrees) between the vector represented by this point and the vector represented by the specified point.doubleangle(Point2D p1, Point2D p2)Computes the angle (in degrees) between the three points with this point as a vertex.Point3DcrossProduct(double x, double y)Computes cross product of the vector represented by this instance and the specified vector.Point3DcrossProduct(Point2D vector)Computes cross product of the vector represented by this instance and the specified vector.doubledistance(double x1, double y1)Computes the distance between this point and point(x1, y1).doubledistance(Point2D point)Computes the distance between this point and the specifiedpoint.doubledotProduct(double x, double y)Computes dot (scalar) product of the vector represented by this instance and the specified vector.doubledotProduct(Point2D vector)Computes dot (scalar) product of the vector represented by this instance and the specified vector.booleanequals(Object obj)Indicates whether some other object is "equal to" this one.doublegetX()The x coordinate.doublegetY()The y coordinate.inthashCode()Returns a hash code value for the point.doublemagnitude()Computes magnitude (length) of the relative magnitude vector represented by this instance.Point2Dmidpoint(double x, double y)Returns a point which lies in the middle between this point and the specified coordinates.Point2Dmidpoint(Point2D point)Returns a point which lies in the middle between this point and the specified point.Point2Dmultiply(double factor)Returns a point with the coordinates of this point multiplied by the specified factorPoint2Dnormalize()Normalizes the relative magnitude vector represented by this instance.Point2Dsubtract(double x, double y)Returns a point with the specified coordinates subtracted from the coordinates of this point.Point2Dsubtract(Point2D point)Returns a point with the coordinates of the specified point subtracted from the coordinates of this point.StringtoString()Returns a string representation of thisPoint2D.
-
Field Detail
-
ZERO
public static final Point2D ZERO
Point or vector with both coordinates set to 0.
-
-
Constructor Detail
-
Point2D
public Point2D(double x, double y)Creates a new instance ofPoint2D.Parameters:
x- the x coordinate of the point
-
-
Method Detail
-
getX
public final double getX()
The x coordinate.Returns:
the x coordinate
-
getY
public final double getY()
The y coordinate.Returns:
the y coordinate
-
distance
public double distance(double x1, double y1)Computes the distance between this point and point(x1, y1).Parameters:
x1- the x coordinate of other pointReturns:
the distance between this point and point
(x1, y1).
-
distance
public double distance(Point2D point)
Computes the distance between this point and the specifiedpoint.Parameters:
point- the other pointReturns:
the distance between this point and the specified
point.Throws:
NullPointerException- if the specifiedpointis null
-
add
public Point2D add(double x, double y)Returns a point with the specified coordinates added to the coordinates of this point.Parameters:
x- the X coordinate additionReturns:
the point with added coordinates
Since:
JavaFX 8.0
-
add
public Point2D add(Point2D point)
Returns a point with the coordinates of the specified point added to the coordinates of this point.Parameters:
point- the point whose coordinates are to be addedReturns:
the point with added coordinates
Throws:
NullPointerException- if the specifiedpointis nullSince:
JavaFX 8.0
-
subtract
public Point2D subtract(double x, double y)Returns a point with the specified coordinates subtracted from the coordinates of this point.Parameters:
x- the X coordinate subtractionReturns:
the point with subtracted coordinates
Since:
JavaFX 8.0
-
multiply
public Point2D multiply(double factor)
Returns a point with the coordinates of this point multiplied by the specified factorParameters:
factor- the factor multiplying the coordinatesReturns:
the point with multiplied coordinates
Since:
JavaFX 8.0
-
subtract
public Point2D subtract(Point2D point)
Returns a point with the coordinates of the specified point subtracted from the coordinates of this point.Parameters:
point- the point whose coordinates are to be subtractedReturns:
the point with subtracted coordinates
Throws:
NullPointerException- if the specifiedpointis nullSince:
JavaFX 8.0
-
normalize
public Point2D normalize()
Normalizes the relative magnitude vector represented by this instance. Returns a vector with the same direction and magnitude equal to 1. If this is a zero vector, a zero vector is returned.Returns:
the normalized vector represented by a
Point2DinstanceSince:
JavaFX 8.0
-
midpoint
public Point2D midpoint(double x, double y)Returns a point which lies in the middle between this point and the specified coordinates.Parameters:
x- the X coordinate of the second endpointReturns:
the point in the middle
Since:
JavaFX 8.0
-
midpoint
public Point2D midpoint(Point2D point)
Returns a point which lies in the middle between this point and the specified point.Parameters:
point- the other endpointReturns:
the point in the middle
Throws:
NullPointerException- if the specifiedpointis nullSince:
JavaFX 8.0
-
angle
public double angle(double x, double y)Computes the angle (in degrees) between the vector represented by this point and the specified vector.Parameters:
x- the X magnitude of the other vectorReturns:
the angle between the two vectors measured in degrees
Since:
JavaFX 8.0
-
angle
public double angle(Point2D point)
Computes the angle (in degrees) between the vector represented by this point and the vector represented by the specified point.Parameters:
point- the other vectorReturns:
the angle between the two vectors measured in degrees,
NaNif any of the two vectors is a zero vectorThrows:
NullPointerException- if the specifiedpointis nullSince:
JavaFX 8.0
-
angle
public double angle(Point2D p1, Point2D p2)Computes the angle (in degrees) between the three points with this point as a vertex.Parameters:
p1- one pointReturns:
angle between the vectors (this, p1) and (this, p2) measured in degrees,
NaNif the three points are not different from one anotherThrows:
NullPointerException- ifp1orp2is nullSince:
JavaFX 8.0
-
magnitude
public double magnitude()
Computes magnitude (length) of the relative magnitude vector represented by this instance.Returns:
magnitude of the vector
Since:
JavaFX 8.0
-
dotProduct
public double dotProduct(double x, double y)Computes dot (scalar) product of the vector represented by this instance and the specified vector.Parameters:
x- the X magnitude of the other vectorReturns:
the dot product of the two vectors
Since:
JavaFX 8.0
-
dotProduct
public double dotProduct(Point2D vector)
Computes dot (scalar) product of the vector represented by this instance and the specified vector.Parameters:
vector- the other vectorReturns:
the dot product of the two vectors
Throws:
NullPointerException- if the specifiedvectoris nullSince:
JavaFX 8.0
-
crossProduct
public Point3D crossProduct(double x, double y)Computes cross product of the vector represented by this instance and the specified vector.Parameters:
x- the X magnitude of the other vectorReturns:
the cross product of the two vectors
Since:
JavaFX 8.0
-
crossProduct
public Point3D crossProduct(Point2D vector)
Computes cross product of the vector represented by this instance and the specified vector.Parameters:
vector- the other vectorReturns:
the cross product of the two vectors
Throws:
NullPointerException- if the specifiedvectoris nullSince:
JavaFX 8.0
-
equals
public boolean equals(Object obj)
Indicates whether some other object is "equal to" this one.
-
hashCode
public int hashCode()
Returns a hash code value for the point.
-
toString
public String toString()
Returns a string representation of thisPoint2D. 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 benull.
-
© 2008, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from JavaFX API Documentation.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Java, JavaFX and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.