PointXY
A 2D coordinate with X and Y values. This is the foundation upon which Pathfinder's geometry is based. As a Pathfinder-specific notice: these points should almost never be negative. The library assumes that everything takes place in the first quadrant. You can try to use negative values if you want, but the library has not been tested with them.
A point is defined as a pair of X and Y values. These values are stored as doubles. Points are immutable objects, meaning they cannot be modified once created. Many methods in the PointXY class will return a new PointXY based on whatever modifications you will have made.
Points are one of the most important concepts in using Pathfinder - all of the advanced geometry (rectangles, circles, shapes, etc) is based on lines and points. And lines are based on points.
The concept of a point is relatively straightforward - it's literally just a pair of X and Y values. There are many methods available for use, even for very niche situations. Some of the most important methods are:
distance(PointXY)inDirection(double, Angle)angleTo(PointXY)
Additionally, it's worth noting that most (possibly all) of the methods in this class have a corresponding static method.
Fields
ZERO
A static PointXY with X and Y values of 0.
COUNT
A static counter for how many instances of PointXY have been created.
Methods
PointXY()
Creates a new PointXY with 0 for X and Y values.
PointXY(PointXY point)
Creates a new PointXY by copying an existing point.
PointXY(double x, double y)
Creates a new PointXY with the specified X and Y values.
parse(String string)
Parses a PointXY from a String. Examples: "0, 0", "1.0, .5".
fromMetersToInches(double xMeters, double yMeters)
Creates a new PointXY and converts the provided X and Y values from meters to inches.
fromInchesToMeters(double xInches, double yInches)
Creates a new PointXY and converts the provided X and Y values from inches to meters.
fromMetersToCentimeters(double xMeters, double yMeters)
Creates a new PointXY and converts the provided X and Y values from meters to centimeters.
fromCentimetersToInches(double xCentimeters, double yCentimeters)
Creates a new PointXY and converts the provided X and Y values from centimeters to inches.
fromInchesToCentimeters(double xInches, double yInches)
Creates a new PointXY and converts the provided X and Y values from inches to centimeters.
add(PointXY a, PointXY b)
Static method. Adds two PointXY objects together (component-wise addition).
add(PointXY a, double x, double y)
Static method. Adds X and Y values to a PointXY.
subtract(PointXY a, PointXY b)
Static method. Subtracts point b from point a.
multiply(PointXY a, PointXY b)
Static method. Multiplies two PointXY objects together (component-wise multiplication).
multiply(PointXY a, double b)
Static method. Multiplies a PointXY by a double value (scales X and Y).
equalsX(PointXY a, Object object)
Static method. Checks if an object has the same X value as a PointXY.
equalsY(PointXY a, Object object)
Static method. Checks if an object has the same Y value as a PointXY.
equals(PointXY a, Object object)
Static method. Checks if two PointXY objects are equal within a tolerance.
avg(PointXY a, PointXY b)
Static method. Gets the average (midpoint) of two PointXY objects.
zero()
Static method. Returns a new PointXY with X and Y values of 0.
slope(PointXY a, PointXY b)
Static method. Gets the slope between two PointXY objects.
distance(PointXY a, PointXY b)
Static method. Gets the Euclidean distance between two PointXY objects.
distanceX(PointXY a, PointXY b)
Static method. Gets the difference in X values between two PointXY objects.
distanceY(PointXY a, PointXY b)
Static method. Gets the difference in Y values between two PointXY objects.
angleTo(PointXY a, PointXY b)
Static method. Calculates the angle from point a to point b.
angleFrom(PointXY a, PointXY b)
Static method. Calculates the angle from point b to point a.
areDuplicatesPresent(PointXY... points)
Static method. Checks a set of points for any duplicates within a tolerance.
inDirection(PointXY base, double distance, Angle angle)
Static method. Creates a new PointXY a given distance away from a base point in a specified angle.
applyTranslation(PointXY base, Translation translation)
Static method. Applies a Translation to a base PointXY.
isNear(PointXY a, PointXY b, double tolerance)
Static method. Checks if two PointXY objects are near each other within a specified tolerance.
isNear(PointXY a, double tolerance, PointXY... points)
Static method. Checks if a PointXY is near any of a set of other PointXY objects.
rotate(PointXY point, PointXY center, Angle angle)
Static method. Rotates a PointXY around a center PointXY by a specified angle.
rotate(Collection<PointXY> points, PointXY center, Angle angle)
Static method. Rotates a Collection of PointXY objects around a center PointXY by a specified angle.
rotate(PointXY[] points, PointXY center, Angle angle)
Static method. Rotates an array of PointXY objects around a center PointXY by a specified angle.
areCollinear(PointXY a, PointXY b, PointXY c)
Static method. Determines if three points are collinear within a tolerance.
areCollinear(PointXY a, PointXY b, PointXY c, double tolerance)
Static method. Determines if three points are collinear within a specified tolerance.
areCollinear(PointXY... points)
Static method. Checks if a set of points are collinear.
areCollinear(double tolerance, PointXY... points)
Static method. Checks if a set of points are collinear within a specified tolerance.
towards(PointXY origin, PointXY target, double distance)
Static method. Creates a new point distance away from origin towards target.
midpoint(PointXY a, PointXY b)
Static method. Gets the midpoint between two PointXY objects.
zeroIfNull(PointXY point)
Static method. If the provided point is null, returns PointXY.ZERO. Otherwise, returns the provided point.
getClosestPoint(PointXY reference, PointXY... points)
Static method. Returns the point from a set of points that is closest to the reference point.
getClosestPoint(PointXY reference, List<PointXY> points)
Static method. Returns the point from a list of points that is closest to the reference point.
getFurthestPoint(PointXY reference, PointXY... points)
Static method. Returns the point from a set of points that is furthest from the reference point.
getFurthestPoint(PointXY reference, List<PointXY> points)
Static method. Returns the point from a list of points that is furthest from the reference point.
avg(List<PointXY> points)
Static method. Gets a point by averaging all the X and Y values in a list of points.
avg(PointXY... points)
Static method. Gets a point by averaging all the X and Y values in a set of points.
minimumX(PointXY... points)
Static method. For a set of points, gets the minimum X value.
minimumY(PointXY... points)
Static method. For a set of points, gets the minimum Y value.
maximumX(PointXY... points)
Static method. For a set of points, gets the maximum X value.
maximumY(PointXY... points)
Static method. For a set of points, gets the maximum Y value.
minimumPoint(PointXY... points)
Static method. Gets the "minimum point" (minimum X and Y values) from a set of points.
maximumPoint(PointXY... points)
Static method. Gets the "maximum point" (maximum X and Y values) from a set of points.
checkArgument(PointXY point, String message)
Static method. Validates a PointXY for nullity and finite X/Y values.
checkArgument(PointXY point)
Static method. Validates a PointXY for nullity and finite X/Y values with a default message.
closestPoint(PointXY reference, Shape<?> shape)
Static method. Gets the closest point in a Shape to a reference point.
shift(PointXY reference, double shiftX, double shiftY)
Static method. Shifts a PointXY by X and Y offsets.
shiftX(PointXY reference, double shiftX)
Static method. Shifts a PointXY by an X offset.
shiftY(PointXY reference, double shiftY)
Static method. Shifts a PointXY by a Y offset.
shift(double shiftX, double shiftY, List<PointXY> points)
Static method. Shifts a list of PointXY objects by X and Y offsets.
shift(double shiftX, double shiftY, PointXY... points)
Static method. Shifts an array of PointXY objects by X and Y offsets.
isPointNearPoints(PointXY reference, double tolerance, PointXY... points)
Static method. Checks if a reference point is near any point in a set of points.
isPointNearShape(PointXY reference, Shape<?> shape, double tolerance)
Static method. Checks if a reference point is near a given Shape.
towards(PointXY target, double distance)
Creates a new point distance away from this point towards the target point.
x()
Returns the point's X value.
y()
Returns the point's Y value.
absX()
Returns the absolute value of the point's X value.
absY()
Returns the absolute value of the point's Y value.
add(PointXY a)
Adds another PointXY to this point.
addX(double x)
Returns a new PointXY with the X component incremented by x.
addY(double y)
Returns a new PointXY with the Y component incremented by y.
subtract(PointXY b)
Subtracts another PointXY from this point.
multiply(PointXY a)
Multiplies this point with another point.
multiply(double a)
Multiplies the X and Y values of this point by a single coefficient.
avg(PointXY a)
Gets the average between this point and another point.
withHeading(Angle angle)
Creates a PointXYZ by adding a heading Angle to this point.
withHeading(PointXYZ point)
Creates a PointXYZ by adding the heading of another PointXYZ to this point.
withHeadingDegrees(double degrees)
Creates a PointXYZ by adding a heading in degrees to this point.
withHeadingRadians(double radians)
Creates a PointXYZ by adding a heading in radians to this point.
distance(PointXY a)
Gets the Euclidean distance between this point and a.
absDistance(PointXY a)
Gets the absolute value of the distance from a given point.
distanceX(PointXY a)
Gets the X difference between this point and a.
absDistanceX(PointXY a)
Gets the absolute value of the X difference from a given point.
distanceY(PointXY a)
Gets the Y difference between this point and a.
absDistanceY(PointXY a)
Gets the absolute value of the Y difference from a given point.
angleTo(PointXY a)
Determines the angle from this point to a.
angleFrom(PointXY a)
Determines the angle to this point from a.
inDirection(double distance, Angle angle)
Creates a new point a specified distance and direction away from this point.
applyTranslation(Translation translation)
Applies a Translation to this point.
isNear(PointXY a, double tolerance)
Determines if a is near to this point within a tolerance.
rotate(PointXY center, Angle angle)
Rotates this point around a center point.
isCollinearWith(PointXY a, PointXY b)
Checks if this point is collinear with a and b.
midpoint(PointXY a)
Gets the midpoint between this point and a.
withX(double x)
Creates a new point with the same Y value as this point and the provided X value.
withY(double y)
Creates a new point with the same X value as this point and the provided Y value.
withZ(Angle z)
Creates a PointXYZ by adding a heading Angle to this point.
isInside(Shape<?> shape)
Checks if this point is inside a given Shape.
isCollinearWithLine(Line line)
Checks if this point is collinear with a given Line's start and end points.
isOnLineSegment(Line line)
Checks if a point is on a given Line segment.
closestPoint(Shape<?> shape)
Gets the closest point in the Shape to this point.
shift(double shiftX, double shiftY)
Shifts this point by an X and Y offset.
shiftX(double shiftX)
Shifts this point by an X offset.
shiftY(double shiftY)
Shifts this point by a Y offset.
isPointNearPoints(double tolerance, PointXY... points)
Checks if this point is close to any point in a set of points.
isPointNearShape(Shape<?> shape, double tolerance)
Checks if this point is close to a given Shape.
multiplyX(double multiplier)
Multiplies the X value of this point by multiplier.
multiplyY(double multiplier)
Multiplies the Y value of this point by multiplier.
equals(Object obj)
Compares two PointXY objects for equality within a tolerance.
toString()
Converts this PointXY into a string representation.
compareTo(PointXY o)
Compares two PointXY objects based on their distance from the origin.
clone()
Creates and returns a clone of this PointXY.