Package org.djutils.draw.point
Interface Point<P extends Point<P>>
- Type Parameters:
P
- The point type
- All Superinterfaces:
Drawable<P>
,Iterable<P>
,Serializable
- All Known Implementing Classes:
DirectedPoint2d
,DirectedPoint3d
,OrientedPoint3d
,Point2d
,Point3d
,Ray2d
,Ray3d
Point is the interface for the Point2d and Point3d implementations, standardizing as many of the methods as possible.
Copyright (c) 2020-2025 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, Wouter Schakel
-
Method Summary
Modifier and TypeMethodDescriptionabs()
Return a new Point with absolute coordinate values.closestPointOnLine
(P linePoint1, P linePoint2) Project a point on a line.closestPointOnSegment
(P segmentPoint1, P segmentPoint2) Project a point on a line segment.double
Return the distance to another point.double
distanceSquared
(P otherPoint) Return the squared distance between this point and the provided point.boolean
epsilonEquals
(P otherPoint, double epsilon) A comparison with another point that returnstrue
of each of the coordinates is less than epsilon apart.double
getX()
Return the x-coordinate.double
getY()
Return the y-coordinate.interpolate
(P otherPoint, double fraction) Interpolate towards another Point with a fraction.neg()
Return a new Point with negated coordinate values.Return a new Point with a distance of 1 to the origin.scale
(double factor) Return a new Point with the coordinates of this point scaled by the provided factor.Methods inherited from interface org.djutils.draw.Drawable
getDimensions, getPointList, size, toString, toString, toString, toString
Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
Method Details
-
getX
double getX()Return the x-coordinate.- Returns:
- the x-coordinate
-
getY
double getY()Return the y-coordinate.- Returns:
- the y-coordinate
-
scale
Return a new Point with the coordinates of this point scaled by the provided factor.- Parameters:
factor
- the scale factor- Returns:
- a new point with the coordinates of this point scaled by the provided factor
- Throws:
ArithmeticException
- whenfactor
isNaN
-
neg
P neg()Return a new Point with negated coordinate values. If this is aDirectedPoint
,dirY
(in case this is aDirectedPoint3d
anddirZ
are negated.- Returns:
- a new point with negated coordinate values
-
abs
P abs()Return a new Point with absolute coordinate values. If this is aDirectedPoint
,dirY
(in case this is aDirectedPoint3d
anddirZ
are copied unchanged.- Returns:
- a new point with absolute coordinate values
-
normalize
Return a new Point with a distance of 1 to the origin.- Returns:
- the normalized point
- Throws:
DrawRuntimeException
- when point is the origin, and no length can be established for scaling
-
distance
Return the distance to another point.- Parameters:
otherPoint
- P the other point- Returns:
- the distance (2d or 3d as applicable) to the other point
-
distanceSquared
Return the squared distance between this point and the provided point.- Parameters:
otherPoint
- the other point- Returns:
- the squared distance between this point and the other point
- Throws:
NullPointerException
- whenotherPoint
isnull
-
interpolate
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:
otherPoint
- the other pointfraction
- 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:
- the point that is
fraction
away on the line between this point and the other point - Throws:
NullPointerException
- whenpoint
isnull
ArithmeticException
- whenfraction
isNaN
-
closestPointOnSegment
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
- start of line segmentsegmentPoint2
- end of line segment- Returns:
- either
segmentPoint1
, orsegmentPoint2
or a new Point2d that lies somewhere in between those two. - Throws:
NullPointerException
- whensegmentPoint2
, orsegmentPoint2
isnull
-
closestPointOnLine
Project a point on a line.
Adapted from example code provided by Paul Bourke.- Parameters:
linePoint1
- point on the linelinePoint2
- another point on the line- Returns:
- a point on the line that goes through
linePoint1
andlinePoint2
- Throws:
NullPointerException
- whenlinePoint1
isnull
, orlinePoint2
isnull
IllegalArgumentException
- whenlinePoint1
is at the same location aslinePoint2
-
epsilonEquals
A comparison with another point that returnstrue
of each of the coordinates is less than epsilon apart.- Parameters:
otherPoint
- the point to compare withepsilon
- 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, otherwisefalse
- Throws:
NullPointerException
- whenotherPoint
isnull
ArithmeticException
- whenepsilon
isNaN
IllegalArgumentException
- whenepsilon
<0.0
-