Package org.djutils.draw.point
Class Point3d
java.lang.Object
org.djutils.draw.point.Point3d
- All Implemented Interfaces:
Serializable
,Drawable<Point3d>
,Drawable3d
,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-2024 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
- See Also:
-
Field Summary
-
Constructor Summary
ConstructorDescriptionPoint3d
(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 Point3d
closestPointOnLine
(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 Point3d
closestPointOnLine
(Point3d linePoint1, Point3d linePoint2) Project a point on a line.final Point3d
closestPointOnSegment
(double p1X, double p1Y, double p1Z, double p2X, double p2Y, double p2Z) Project a point on a line segment.final Point3d
closestPointOnSegment
(Point3d segmentPoint1, Point3d segmentPoint2) Project a point on a line segment.double
Return the distance to another point.double
distanceSquared
(Point3d otherPoint) Return the squared distance between this point and the provided point.boolean
epsilonEquals
(Point3d otherPoint, double epsilon) A comparison with another point that returns true of each of the coordinates is less than epsilon apart.boolean
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.Retrieve the bounding box of the object.Retrieve, or generate all points that make up the object.final double
getX()
Return the x-coordinate.final double
getY()
Return the y-coordinate.final double
getZ()
Return the z-coordinate.int
hashCode()
(package private) final double
Return the direction of the point in radians with respect to the origin, ignoring the z-coordinate.(package private) final double
horizontalDirection
(Point3d otherPoint) Return the direction to another point, in radians, ignoring the z-coordinate.(package private) final double
horizontalDistance
(Point3d otherPoint) Return the Euclidean distance between this point and the provided point, ignoring the z-coordinate.(package private) final double
horizontalDistanceSquared
(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.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.int
size()
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.translate
(double dx, double dy, double dz) Return a new Point3d with a translation by the provided dx, dy and dz.(package private) final double
verticalDirection
(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, wait
Methods inherited from interface org.djutils.draw.Drawable
getPointList, toString, toString
Methods inherited from interface org.djutils.draw.Drawable3d
getDimensions
-
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
- double; the x coordinatey
- double; the y coordinatez
- double; the z coordinate- Throws:
IllegalArgumentException
- when x or y or z is NaN
-
Point3d
Create a new Point3d from x, y and z coordinates provided as values in a double array.- Parameters:
xyz
- double[]; the x, y and z coordinates- Throws:
NullPointerException
- when xyz is nullIllegalArgumentException
- when the length of xyz is not 3, or a coordinate is NaN
-
Point3d
Create a new Point3d from x, y stored in a java.awt.geom.Point2D and double z.- Parameters:
point
- Point2d; a java.awt.geom.Point2Dz
- double; the z coordinate- Throws:
NullPointerException
- when point is nullIllegalArgumentException
- when z is NaN
-
Point3d
Create an immutable point from x, y obtained from a AWT Point2D and double z.- Parameters:
point
- Point2D; an AWT Point2Dz
- double; the z coordinate- Throws:
NullPointerException
- when point is nullIllegalArgumentException
- when point has a NaN coordinate, or z is NaN
-
-
Method Details
-
getX
public final double getX()Description copied from interface:Point
Return the x-coordinate. When the point is not in Cartesian space, a calculation to Cartesian space has to be made. -
getY
public final double getY()Description copied from interface:Point
Return the y-coordinate. When the point is not in Cartesian space, a calculation to Cartesian space has to be made. -
getZ
public final double getZ()Return the z-coordinate.- Returns:
- double; the z-coordinate
-
distanceSquared
Description copied from interface:Point
Return the squared distance between this point and the provided point.- Specified by:
distanceSquared
in interfacePoint<Point3d>
- Parameters:
otherPoint
- P; the other point- Returns:
- double; the squared distance between this point and the other point
- Throws:
NullPointerException
- when otherPoint is null
-
distance
Description copied from interface:Point
Return the distance to another point.- Specified by:
distance
in interfacePoint<Point3d>
- Parameters:
otherPoint
- P; P the other point- Returns:
- double; the distance (2d or 3d as applicable) to the other point
- Throws:
NullPointerException
-
size
public int size()Description copied from interface:Drawable
Retrieve the number of points that make up the object. -
getPoints
Description copied from interface:Drawable
Retrieve, or generate all points that make up the object. -
project
Description copied from interface:Drawable3d
Project the object onto the z=0 plane.- Specified by:
project
in interfaceDrawable3d
- Returns:
- Drawable2d; the projected object
- Throws:
InvalidProjectionException
- when projecting onto the z=0 plane results in an invalid object. E.g. a Line3d that consists of points that all have the exact same x and y coordinates cannot be a line after projecting on the z=0 plane.DrawRuntimeException
-
translate
Return a new Point3d with a translation by the provided dx and dy.- Parameters:
dx
- double; the x translationdy
- double; the y translation- Returns:
- Point3D; a new point with the translated coordinates
- Throws:
IllegalArgumentException
- when dx, or dy is NaN
-
translate
Return a new Point3d with a translation by the provided dx, dy and dz.- Parameters:
dx
- double; the x translationdy
- double; the y translationdz
- double; the z translation- Returns:
- Point3d; a new point with the translated coordinates
- Throws:
IllegalArgumentException
- when dx, dy, or dz is NaN
-
scale
Description copied from interface:Point
Return a new Point with the coordinates of this point scaled by the provided factor.- Specified by:
scale
in interfacePoint<Point3d>
- 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
Description copied from interface:Point
Return a new Point with negated coordinate values. If this is a DirectedPoint, dirY and dirZ are negated. -
abs
Description copied from interface:Point
Return a new Point with absolute coordinate values. If this is a DirectedPoint, dirY and dirZ are copied unchanged. -
normalize
Description copied from interface:Point
Return a new Point with a distance of 1 to the origin.- Specified by:
normalize
in interfacePoint<Point3d>
- Returns:
- Point; the normalized point
- Throws:
DrawRuntimeException
- when point is the origin, and no length can be established for scaling
-
interpolate
Description copied from interface:Point
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.- Specified by:
interpolate
in interfacePoint<Point3d>
- 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
-
epsilonEquals
Description copied from interface:Point
A comparison with another point that returns true of each of the coordinates is less than epsilon apart.- Specified by:
epsilonEquals
in interfacePoint<Point3d>
- Parameters:
otherPoint
- 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
-
getBounds
Description copied from interface:Drawable3d
Retrieve the bounding box of the object.- Specified by:
getBounds
in interfaceDrawable3d
- Returns:
- Bounds3d; the bounding box of the object
-
closestPointOnSegment
Description copied from interface:Point
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.- Specified by:
closestPointOnSegment
in interfacePoint<Point3d>
- 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
public Point3d closestPointOnLine(double p1X, double p1Y, double p1Z, double p2X, double p2Y, double p2Z, Boolean lowLimitHandling, Boolean highLimitHandling) throws DrawRuntimeException Compute the closest point on a line with optional limiting of the result on either end.- Parameters:
p1X
- double; the x coordinate of the first point on the linep1Y
- double; the y coordinate of the first point on the linep1Z
- double; the z coordinate of the first point on the linep2X
- double; the x coordinate of the second point on the linep2Y
- double; the y coordinate of the second point on the linep2Z
- double; the z coordinate of the second point on the linelowLimitHandling
- Boolean; controls handling of results that lie before the first point of the line. If null; this method returns null; else if true; this method returns (p1X,p1Y); else (lowLimitHandling is false); this method will return the closest point on the linehighLimitHandling
- Boolean; controls the handling of results that lie beyond the second point of the line. If null; this method returns null; else if true; this method returns (p2X,p2Y); else (highLimitHandling is false); this method will return the closest point on the line- Returns:
- Point3d; the closest point on the line after applying the indicated limit handling; so the result can be null
- Throws:
DrawRuntimeException
- when any of the arguments is NaN
-
fractionalPositionOnLine
public double fractionalPositionOnLine(double p1X, double p1Y, double p1Z, double p2X, double p2Y, double p2Z, Boolean lowLimitHandling, Boolean highLimitHandling) throws DrawRuntimeException 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
- double; the x coordinate of the first point on the linep1Y
- double; the y coordinate of the first point on the linep1Z
- double; the z coordinate of the first point on the linep2X
- double; the x coordinate of the second point on the linep2Y
- double; the y coordinate of the second point on the linep2Z
- double; the z coordinate of the second point on the linelowLimitHandling
- Boolean; controls handling of results that lie before the first point of the line. If null; this method returns NaN; else if true; this method returns 0.0; else (lowLimitHandling is false); this results < 0.0 are returnedhighLimitHandling
- Boolean; controls the handling of results that lie beyond the second point of the line. If null; this method returns NaN; else if true; this method returns 1.0; else (highLimitHandling is false); results > 1.0 are returned- Returns:
- double; 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:
DrawRuntimeException
- when any of the arguments is NaN
-
closestPointOnSegment
public final Point3d closestPointOnSegment(double p1X, double p1Y, double p1Z, double p2X, double p2Y, double p2Z) throws DrawRuntimeException 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
- double; the x coordinate of the start point of the line segmentp1Y
- double; the y coordinate of the start point of the line segmentp1Z
- double; the z coordinate of the start point of the line segmentp2X
- double; the x coordinate of the end point of the line segmentp2Y
- double; the y coordinate of the end point of the line segmentp2Z
- double; the y coordinate of the end point of the line segment- Returns:
- P; either segmentPoint1, or segmentPoint2 or a new Point2d that lies somewhere in between those two.
- Throws:
DrawRuntimeException
- when any of the parameters is NaN
-
closestPointOnLine
public final Point3d closestPointOnLine(Point3d linePoint1, Point3d linePoint2) throws NullPointerException, DrawRuntimeException Description copied from interface:Point
Project a point on a line.
Adapted from example code provided by Paul Bourke.- Specified by:
closestPointOnLine
in interfacePoint<Point3d>
- 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:
NullPointerException
- when linePoint1 is null, or linePoint2 is nullDrawRuntimeException
- when linePoint1 is at the same location as linePoint2
-
closestPointOnLine
public final Point3d closestPointOnLine(double p1X, double p1Y, double p1Z, double p2X, double p2Y, double p2Z) throws DrawRuntimeException Project a point on a line.
Adapted from example code provided by Paul Bourke.- Parameters:
p1X
- double; the x coordinate of a point of the linep1Y
- double; the y coordinate of a point of the linep1Z
- double; the z coordinate of a point on the linep2X
- double; the x coordinate of another point on the linep2Y
- double; the y coordinate of another point on the linep2Z
- double; the z coordinate of another point on the line- Returns:
- Point3d; a point on the line that goes through the points
- Throws:
DrawRuntimeException
- 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:
- double; 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
- Point3d; the other point- Returns:
- double; the direction of the projection of the point in the x-y plane to another point, in radians
- Throws:
NullPointerException
- whenpoint
is null
-
verticalDirection
Return the direction with respect to the Z axis to another point, in radians.- Parameters:
otherPoint
- Point3d; the other point- Returns:
- double; the direction with respect to the Z axis to another point, in radians
- Throws:
NullPointerException
- whenpoint
is null
-
horizontalDistanceSquared
Return the squared distance between the coordinates of this point and the provided point, ignoring the z-coordinate.- Parameters:
otherPoint
- Point3d; the other point- Returns:
- double; the squared distance between this point and the other point, ignoring the z-coordinate
- Throws:
NullPointerException
- when point is null
-
horizontalDistance
Return the Euclidean distance between this point and the provided point, ignoring the z-coordinate.- Parameters:
otherPoint
- Point3d; the other point- Returns:
- double; the Euclidean distance between this point and the other point, ignoring the z-coordinate
- Throws:
NullPointerException
- when point is null
-
toString
Description copied from interface:Drawable
Produce 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:Drawable
Produce a String describing the Drawable.- Specified by:
toString
in interfaceDrawable<Point3d>
- Parameters:
doubleFormat
- String; a format string (something like "%6.3f") which will be used to render every coordinate value)doNotIncludeClassName
- boolean; if true; the output of toString is 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:
- String; textual representation of the Drawable
-
hashCode
public int hashCode() -
equals
-