Package org.djutils.draw.point
Class Point3d
java.lang.Object
org.djutils.draw.point.Point3d
- Direct Known Subclasses:
DirectedPoint3d
A Point3d is an immutable point with an x, y, and z coordinate, stored with double precision. It differs from many Point
implementations by being immutable.
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
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionPoint3d(double[] xyz) Create a new Point3d from x, y and z coordinates provided as values in a double array.Point3d(double x, double y, double z) Create a new Point from x, y and z coordinates provided as double arguments.Create an immutable point from x, y obtained from a AWT Point2D and double z.Create a new Point3d from x, y stored in a java.awt.geom.Point2D and double z. -
Method Summary
Modifier and TypeMethodDescriptionabs()Return a new Point with absolute coordinate values.final Point3dclosestPointOnLine(double p1X, double p1Y, double p1Z, double p2X, double p2Y, double p2Z) Project a point on a line.closestPointOnLine(double p1X, double p1Y, double p1Z, double p2X, double p2Y, double p2Z, Boolean lowLimitHandling, Boolean highLimitHandling) Compute the closest point on a line with optional limiting of the result on either end.final Point3dclosestPointOnLine(Point3d linePoint1, Point3d linePoint2) Project a point on a line.final Point3dclosestPointOnSegment(double p1X, double p1Y, double p1Z, double p2X, double p2Y, double p2Z) Project a point on a line segment.final Point3dclosestPointOnSegment(Point3d segmentPoint1, Point3d segmentPoint2) Project a point on a line segment.directionTo(Point3d otherPoint) Return the direction to another Point3d.doubleReturn the distance to another point.doubledistanceSquared(Point3d otherPoint) Return the squared distance between this point and the provided point.booleanepsilonEquals(Point3d otherPoint, double epsilon) A comparison with another point that returnstrueof each of the coordinates is less than epsilon apart.booleandoublefractionalPositionOnLine(double p1X, double p1Y, double p1Z, double p2X, double p2Y, double p2Z, Boolean lowLimitHandling, Boolean highLimitHandling) Compute the fractional position of the closest point on a line with optional limiting of the result on either end.Retrieve the bounding box of the object in absolute coordinates.final doublegetX()Return the x-coordinate.final doublegetY()Return the y-coordinate.final doublegetZ()Return the z-coordinate.inthashCode()(package private) final doubleReturn the direction of the point in radians with respect to the origin, ignoring the z-coordinate.(package private) final doublehorizontalDirection(Point3d otherPoint) Return the direction to another point, in radians, ignoring the z-coordinate.(package private) final doublehorizontalDistance(Point3d otherPoint) Return the Euclidean distance between this point and the provided point, ignoring the z-coordinate.(package private) final doublehorizontalDistanceSquared(Point3d otherPoint) Return the squared distance between the coordinates of this point and the provided point, ignoring the z-coordinate.interpolate(Point3d point, double fraction) Interpolate towards another Point with a fraction.iterator()neg()Return a new Point with negated coordinate values.Return a new Point with a distance of 1 to the origin.project()Project the object onto the z=0 plane.scale(double factor) Return a new Point with the coordinates of this point scaled by the provided factor.intsize()Retrieve the number of points that make up the object.toString()Produce a string describing the Drawable using default conversion for the (double) coordinate values.Produce a String describing the Drawable.translate(double dX, double dY) Return a new Point3d with a translation by the provided dX and dY and preserved z value.translate(double dX, double dY, double dZ) Return a new Point3d with a translation by the provided dx, dy and dz.(package private) final doubleverticalDirection(Point3d otherPoint) Return the direction with respect to the Z axis to another point, in radians.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.djutils.draw.Drawable
getPointList, toString, toStringMethods inherited from interface org.djutils.draw.Drawable3d
getDimensionsMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
x
public final double xThe x-coordinate. -
y
public final double yThe y-coordinate. -
z
public final double zThe z-coordinate.
-
-
Constructor Details
-
Point3d
public Point3d(double x, double y, double z) Create a new Point from x, y and z coordinates provided as double arguments.- Parameters:
x- the x coordinatey- the y coordinatez- the z coordinate- Throws:
ArithmeticException- whenxoryorzisNaN
-
Point3d
Create a new Point3d from x, y and z coordinates provided as values in a double array.- Parameters:
xyz- the x, y and z coordinates- Throws:
NullPointerException- whenxyzisnullIllegalArgumentException- when the length ofxyzis not 3ArithmeticException- whenxyzcontains aNaNvalue
-
Point3d
Create a new Point3d from x, y stored in a java.awt.geom.Point2D and double z.- Parameters:
point- a java.awt.geom.Point2Dz- the z coordinate- Throws:
NullPointerException- whenpointisnullArithmeticException- whenzisNaN
-
Point3d
Create an immutable point from x, y obtained from a AWT Point2D and double z.- Parameters:
point- a java.awt.geom.Point2Dz- the z coordinate- Throws:
NullPointerException- whenpointisnullArithmeticException- whenpointhas aNaNcoordinate, orzisNaN
-
-
Method Details
-
getX
public final double getX()Description copied from interface:PointReturn the x-coordinate. -
getY
public final double getY()Description copied from interface:PointReturn the y-coordinate. -
getZ
public final double getZ()Return the z-coordinate.- Returns:
- the z-coordinate
-
distanceSquared
Description copied from interface:PointReturn the squared distance between this point and the provided point.- Specified by:
distanceSquaredin interfacePoint<Point3d>- Parameters:
otherPoint- the other point- Returns:
- the squared distance between this point and the other point
- Throws:
NullPointerException- whenotherPointisnull
-
distance
Description copied from interface:PointReturn the distance to another point.- Specified by:
distancein interfacePoint<Point3d>- Parameters:
otherPoint- P the other point- Returns:
- the distance (2d or 3d as applicable) to the other point
- Throws:
NullPointerException
-
size
public int size()Description copied from interface:DrawableRetrieve the number of points that make up the object. -
iterator
-
project
Description copied from interface:Drawable3dProject the object onto the z=0 plane.- Specified by:
projectin interfaceDrawable3d- Returns:
- the projected object
- Throws:
InvalidProjectionException- when projecting onto thez=0plane results in an invalid object. E.g. a Line3d that consists of points that all have the exact samexandycoordinates cannot be a line after projecting on thez=0plane.
-
translate
Return a new Point3d with a translation by the provided dX and dY and preserved z value.- Parameters:
dX- the x translationdY- the y translation- Returns:
- a new point with the translated coordinates and the same
zvalue - Throws:
ArithmeticException- whendX, ordYisNaN
-
translate
Return a new Point3d with a translation by the provided dx, dy and dz.- Parameters:
dX- the x translationdY- the y translationdZ- the z translation- Returns:
- a new point with the translated coordinates
- Throws:
ArithmeticException- whendX,dY, ordZisNaN
-
scale
Description copied from interface:PointReturn a new Point with the coordinates of this point scaled by the provided factor. -
neg
Description copied from interface:PointReturn a new Point with negated coordinate values. If this is aDirectedPoint,dirY(in case this is aDirectedPoint3danddirZare negated. -
abs
Description copied from interface:PointReturn a new Point with absolute coordinate values. If this is aDirectedPoint,dirY(in case this is aDirectedPoint3danddirZare copied unchanged. -
normalize
Description copied from interface:PointReturn a new Point with a distance of 1 to the origin.- Specified by:
normalizein interfacePoint<Point3d>- Returns:
- the normalized point
- Throws:
IllegalArgumentException- when point is the origin, and no length can be established for scaling
-
interpolate
Description copied from interface:PointInterpolate 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.- Specified by:
interpolatein interfacePoint<Point3d>- Parameters:
point- 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. Iffractionis 0;thisPoint is returned; iffractionis 1, the otherpointis returned- Returns:
- the point that is
fractionaway on the line between this point and the other point
-
epsilonEquals
Description copied from interface:PointA comparison with another point that returnstrueof each of the coordinates is less than epsilon apart.- Specified by:
epsilonEqualsin interfacePoint<Point3d>- Parameters:
otherPoint- the point to compare withepsilon- the upper bound of difference for one of the coordinates- Returns:
- boolean;
trueif both x, y and z (if a Point3d) are less than epsilon apart, otherwisefalse
-
getAbsoluteBounds
Description copied from interface:Drawable3dRetrieve the bounding box of the object in absolute coordinates.- Specified by:
getAbsoluteBoundsin interfaceDrawable3d- Returns:
- the bounding box of the object in absolute coordinates
-
directionTo
Return the direction to another Point3d.- Parameters:
otherPoint- the other point- Returns:
- the direction to the other point in Radians (towards infinite X is 0; towards infinite Y is π / 2; etc.). If
the points are identical; this method returns
NaN.
-
closestPointOnSegment
Description copied from interface:PointProject 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.- Specified by:
closestPointOnSegmentin interfacePoint<Point3d>- Parameters:
segmentPoint1- start of line segmentsegmentPoint2- end of line segment- Returns:
- either
segmentPoint1, orsegmentPoint2or a new Point2d that lies somewhere in between those two.
-
closestPointOnLine
public Point3d closestPointOnLine(double p1X, double p1Y, double p1Z, double p2X, double p2Y, double p2Z, Boolean lowLimitHandling, Boolean highLimitHandling) Compute the closest point on a line with optional limiting of the result on either end.- Parameters:
p1X- the x coordinate of the first point on the linep1Y- the y coordinate of the first point on the linep1Z- the z coordinate of the first point on the linep2X- the x coordinate of the second point on the linep2Y- the y coordinate of the second point on the linep2Z- the z coordinate of the second point on the linelowLimitHandling- controls handling of results that lie before the first point of the line. Ifnull; this method returnsnull; else iftrue; this method returns (p1X,p1Y); else (lowLimitHandling isfalse); this method will return the closest point on the linehighLimitHandling- controls the handling of results that lie beyond the second point of the line. Ifnull; this method returnsnull; else iftrue; this method returns (p2X,p2Y); else (highLimitHandling isfalse); this method will return the closest point on the line- Returns:
- the closest point on the line after applying the indicated limit handling; so the result can be
null - Throws:
ArithmeticException- when any of the arguments isNaN
-
fractionalPositionOnLine
public double fractionalPositionOnLine(double p1X, double p1Y, double p1Z, double p2X, double p2Y, double p2Z, Boolean lowLimitHandling, Boolean highLimitHandling) Compute the fractional position of the closest point on a line with optional limiting of the result on either end. If the line has length 0; this method returns 0.0.- Parameters:
p1X- the x coordinate of the first point on the linep1Y- the y coordinate of the first point on the linep1Z- the z coordinate of the first point on the linep2X- the x coordinate of the second point on the linep2Y- the y coordinate of the second point on the linep2Z- the z coordinate of the second point on the linelowLimitHandling- controls handling of results that lie before the first point of the line. If null; this method returnsNaN; else iftrue; this method returns 0.0; else (lowLimitHandling is false); this results < 0.0 are returnedhighLimitHandling- controls the handling of results that lie beyond the second point of the line. If null; this method returnsNaN; else iftrue; this method returns 1.0; else (highLimitHandling isfalse); results > 1.0 are returned- Returns:
- the fractional position of the closest point on the line. Results within the range 0.0 .. 1.0 are always returned as is.. A result < 0.0 is subject to lowLimitHandling. A result > 1.0 is subject to highLimitHandling
- Throws:
IllegalArgumentException- when any of the arguments isNaN
-
closestPointOnSegment
public final Point3d closestPointOnSegment(double p1X, double p1Y, double p1Z, double p2X, double p2Y, double p2Z) 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:
p1X- the x coordinate of the start point of the line segmentp1Y- the y coordinate of the start point of the line segmentp1Z- the z coordinate of the start point of the line segmentp2X- the x coordinate of the end point of the line segmentp2Y- the y coordinate of the end point of the line segmentp2Z- the y coordinate of the end point of the line segment- Returns:
- either
segmentPoint1, orsegmentPoint2or a new Point2d that lies somewhere in between those two. - Throws:
ArithmeticException- when any of the parameters isNaN
-
closestPointOnLine
Description copied from interface:PointProject a point on a line.
Adapted from example code provided by Paul Bourke.- Specified by:
closestPointOnLinein interfacePoint<Point3d>- Parameters:
linePoint1- point on the linelinePoint2- another point on the line- Returns:
- a point on the line that goes through
linePoint1andlinePoint2
-
closestPointOnLine
public final Point3d closestPointOnLine(double p1X, double p1Y, double p1Z, double p2X, double p2Y, double p2Z) Project a point on a line.
Adapted from example code provided by Paul Bourke.- Parameters:
p1X- the x coordinate of a point of the linep1Y- the y coordinate of a point of the linep1Z- the z coordinate of a point on the linep2X- the x coordinate of another point on the linep2Y- the y coordinate of another point on the linep2Z- the z coordinate of another point on the line- Returns:
- a point on the line that goes through the points
- Throws:
IllegalArgumentException- when the points on the line are identical
-
horizontalDirection
final double horizontalDirection()Return the direction of the point in radians with respect to the origin, ignoring the z-coordinate.- Returns:
- the direction of the projection of the point in the x-y plane with respect to the origin, in radians
-
horizontalDirection
Return the direction to another point, in radians, ignoring the z-coordinate.- Parameters:
otherPoint- the other point- Returns:
- the direction of the projection of the point in the x-y plane to another point, in radians
- Throws:
NullPointerException- whenotherPointisnull
-
verticalDirection
Return the direction with respect to the Z axis to another point, in radians.- Parameters:
otherPoint- the other point- Returns:
- the direction with respect to the Z axis to another point, in radians
- Throws:
NullPointerException- whenotherPointisnull
-
horizontalDistanceSquared
Return the squared distance between the coordinates of this point and the provided point, ignoring the z-coordinate.- Parameters:
otherPoint- the other point- Returns:
- the squared distance between this point and the other point, ignoring the z-coordinate
- Throws:
NullPointerException- whenotherPointisnull
-
horizontalDistance
Return the Euclidean distance between this point and the provided point, ignoring the z-coordinate.- Parameters:
otherPoint- the other point- Returns:
- the Euclidean distance between this point and the other point, ignoring the z-coordinate
- Throws:
NullPointerException- whenotherPointisnull
-
toString
Description copied from interface:DrawableProduce a string describing the Drawable using default conversion for the (double) coordinate values. Regrettably, it is not allowed to provide a default implementation here. -
toString
Description copied from interface:DrawableProduce a String describing the Drawable.- Specified by:
toStringin interfaceDrawable<Point3d>- Parameters:
doubleFormat- a format string (something like "%6.3f") which will be used to render every coordinate value)doNotIncludeClassName- iftrue; the output oftoStringis not prefixed by the class name. This is useful for concatenating the textual representation of lots of Drawables (e.g. an array, or a List).- Returns:
- textual representation of the Drawable
-
hashCode
public int hashCode() -
equals
-