Package org.djutils.draw.point
Interface Point<P extends Point<P,S>,S extends Space>
-
- Type Parameters:
P
- The point typeS
- The space type (2d or 3d)
- All Superinterfaces:
Drawable<P,S>
,Serializable
- All Known Implementing Classes:
OrientedPoint2d
,OrientedPoint3d
,Point2d
,Point3d
,Ray2d
,Ray3d
public interface Point<P extends Point<P,S>,S extends Space> extends Drawable<P,S>, Serializable
Point is the interface for the Point2d and Point3d implementations, standardizing as many of the methods as possible.Copyright (c) 2020-2021 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See DJUTILS License.- Author:
- Alexander Verbraeck, Peter Knoppers
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description P
abs()
Return a new Point with absolute coordinate values.P
closestPointOnLine(P linePoint1, P linePoint2)
Project a point on a line.P
closestPointOnSegment(P segmentPoint1, P segmentPoint2)
Project a point on a line segment.double
distance(P otherPoint)
Return the distance to another point.double
distanceSquared(P otherPoint)
Return the squared distance between this point and the provided point.boolean
epsilonEquals(P other, double epsilon)
A comparison with another point that returns true of each of the coordinates is less than epsilon apart.double
getX()
Return the x-coordinate.double
getY()
Return the y-coordinate.P
interpolate(P point, double fraction)
Interpolate towards another Point with a fraction.P
neg()
Return a new Point with negated coordinate values.P
normalize()
Return a new Point with a distance of 1 to the origin.P
scale(double factor)
Return a new Point with the coordinates of this point scaled by the provided factor.String
toString()
Return a string representation of the point.String
toString(int fractionDigits)
Return a string representation of the point with a certain number of fraction digits for the coordinates.
-
-
-
Method Detail
-
getX
double getX()
Return the x-coordinate. When the point is not in Cartesian space, a calculation to Cartesian space has to be made.- Returns:
- double; the x-coordinate
-
getY
double getY()
Return the y-coordinate. When the point is not in Cartesian space, a calculation to Cartesian space has to be made.- Returns:
- double; the y-coordinate
-
scale
P scale(double factor) throws IllegalArgumentException
Return a new Point with the coordinates of this point scaled by the provided factor.- Parameters:
factor
- double; the scale factor- Returns:
- Point; a new point with the coordinates of this point scaled by the provided factor
- Throws:
IllegalArgumentException
- when factor is NaN
-
neg
P neg()
Return a new Point with negated coordinate values.- Returns:
- Point; a new point with negated coordinate values
-
abs
P abs()
Return a new Point with absolute coordinate values.- Returns:
- Point; a new point with absolute coordinate values
-
normalize
P normalize() throws DrawRuntimeException
Return a new Point with a distance of 1 to the origin.- Returns:
- Point; the normalized point
- Throws:
DrawRuntimeException
- when point is the origin, and no length can be established for scaling
-
distance
double distance(P otherPoint)
Return the distance to another point.- Parameters:
otherPoint
- P; P the other point- Returns:
- double; the distance (2d or 3d as applicable) to the other point
-
distanceSquared
double distanceSquared(P otherPoint) throws NullPointerException
Return the squared distance between this point and the provided point.- Parameters:
otherPoint
- P; the other point- Returns:
- double; the squared distance between this point and the other point
- Throws:
NullPointerException
- when otherPoint is null
-
interpolate
P interpolate(P point, double fraction)
Interpolate towards another Point with a fraction. It is allowed for fraction to be less than zero or larger than 1. In that case the interpolation turns into an extrapolation.- Parameters:
point
- P; the other pointfraction
- double; the factor for interpolation towards the other point. When <code>fraction</code> is between 0 and 1, it is an interpolation, otherwise an extrapolation. Iffraction
is 0;this
Point is returned; iffraction
is 1, the otherpoint
is returned- Returns:
- P; the point that is
fraction
away on the line between this point and the other point - Throws:
NullPointerException
- when point is nullIllegalArgumentException
- when fraction is NaN
-
closestPointOnSegment
P closestPointOnSegment(P segmentPoint1, P segmentPoint2)
Project a point on a line segment. If the the projected points lies outside the line segment, the nearest end point of the line segment is returned. Otherwise the returned point lies between the end points of the line segment.
Adapted from example code provided by Paul Bourke.- Parameters:
segmentPoint1
- P; start of line segmentsegmentPoint2
- P; end of line segment- Returns:
- P; either segmentPoint1, or segmentPoint2 or a new Point2d that lies somewhere in between those two.
-
closestPointOnLine
P closestPointOnLine(P linePoint1, P linePoint2) throws DrawRuntimeException
Project a point on a line.
Adapted from example code provided by Paul Bourke.- Parameters:
linePoint1
- P; point on the linelinePoint2
- P; another point on the line- Returns:
- Point2d; a point on the line that goes through linePoint1 and linePoint2
- Throws:
DrawRuntimeException
- when linePoint1 is at the same location as linePoint2
-
epsilonEquals
boolean epsilonEquals(P other, double epsilon)
A comparison with another point that returns true of each of the coordinates is less than epsilon apart.- Parameters:
other
- P; the point to compare withepsilon
- double; the upper bound of difference for one of the coordinates- Returns:
- boolean; true if both x, y and z (if a Point3d) are less than epsilon apart, otherwise false
- Throws:
NullPointerException
- when point is null
-
toString
String toString(int fractionDigits)
Return a string representation of the point with a certain number of fraction digits for the coordinates.- Parameters:
fractionDigits
- int; the number of fraction digits. Should be 0 or a positive number- Returns:
- String; a formatted string with a certain number of fraction digits for the coordinates
-
-