Package org.djutils.draw.line
Class Ray3d
java.lang.Object
org.djutils.draw.point.Point3d
org.djutils.draw.point.DirectedPoint3d
org.djutils.draw.line.Ray3d
- All Implemented Interfaces:
Iterable<Point3d>,Directed,Directed3d,Drawable<Point3d>,Drawable3d,Project<Point3d>,Ray<Ray3d,,DirectedPoint3d, Point3d> Point<Point3d>
public class Ray3d
extends DirectedPoint3d
implements Drawable3d, Ray<Ray3d,DirectedPoint3d,Point3d>
Ray3d is a half-line in 3d; it has one end point with non-infinite coordinates; the other end point is infinitely far away.
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 inherited from class org.djutils.draw.point.DirectedPoint3d
dirY, dirZ -
Constructor Summary
ConstructorsConstructorDescriptionRay3d(double[] xyz, double[] directionVector) Create a new Ray3d from x, y, and z coordinates packed in a double array of three elements and direction dirY,dirZ.Ray3d(double[] xyz, double dirY, double dirZ) Create a new Ray3d from x, y, and z coordinates packed in a double array of three elements and direction dirY,dirZ.Ray3d(double[] xyz, Direction3d dir) Create a new Rayt3d from x, y, and z coordinates packed in a double array of three elements and a direction specified using a double array of two elements.Ray3d(double x, double y, double z, double[] directionVector) Create a new Ray3d with x, y, and z coordinates and orientation specified using a double array of three elements (containing dirX,dirY,dirZ in that order).Ray3d(double x, double y, double z, double dirY, double dirZ) Construct a new Ray3d.Ray3d(double x, double y, double z, double throughX, double throughY, double throughZ) Construct a new Ray3d.Ray3d(double x, double y, double z, Direction3d dir) Construct a new Ray3d.Construct a new Ray3d.Ray3d(DirectedPoint3d directedPoint) Construct a new Ray3d.Construct a new Ray3d.Construct a new Ray3d.Ray3d(Point3d point, Direction3d dir) Construct a new Ray3d.Construct a new Ray3d. -
Method Summary
Modifier and TypeMethodDescriptionclosestPointOnRay(Point3d point) Project a Point on a Ray.booleanflip()Flip the direction of the Ray (creates and returns a new Ray instance).Retrieve the bounding box of the object in absolute coordinates.final doublegetDirY()Retrieve the angle from the positive z axis to the direction.final doublegetDirZ()Retrieve the angle from the positive x-axis.Get the finite end point of this Ray.getLocationExtended(double position) Get the location at a position on the line, with its direction.inthashCode()iterator()neg()Return a new Point with negated coordinate values.projectOrthogonal(Point3d point) Project a point onto this object.projectOrthogonalExtended(Point3d point) Project a point onto this object.doubleProject a point onto this object.doubleProject a point onto this object.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.Methods inherited from class org.djutils.draw.point.DirectedPoint3d
abs, epsilonEquals, interpolate, normalize, rotate, rotate, scale, translate, translateMethods inherited from class org.djutils.draw.point.Point3d
closestPointOnLine, closestPointOnLine, closestPointOnLine, closestPointOnSegment, closestPointOnSegment, directionTo, distance, distanceSquared, epsilonEquals, fractionalPositionOnLine, getX, getY, getZ, interpolate, projectMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.djutils.draw.Directed3d
getDirMethods inherited from interface org.djutils.draw.Drawable
getPointList, toString, toStringMethods inherited from interface org.djutils.draw.Drawable3d
getDimensions, projectMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods inherited from interface org.djutils.draw.line.Ray
getLocation
-
Constructor Details
-
Ray3d
public Ray3d(double x, double y, double z, double dirY, double dirZ) Construct a new Ray3d.- Parameters:
x- the x coordinate of the finite end point of the rayy- the y coordinate of the finite end point of the rayz- the z coordinate of the finite end point of the raydirY- the angle from the positive Z axis direction in radians (the complement of the slope)dirZ- the angle from the positive X axis direction in radians- Throws:
IllegalArgumentException- whendirY, ordirZisNaN(should be impossible)
-
Ray3d
public Ray3d(double x, double y, double z, double[] directionVector) Create a new Ray3d with x, y, and z coordinates and orientation specified using a double array of three elements (containing dirX,dirY,dirZ in that order).- Parameters:
x- the x coordinatey- the y coordinatez- the z coordinatedirectionVector- the two direction angles in a double array containing dirY and dirZ in that order. DirY is the rotation from the positive z-axis to the direction. DirZ is the angle from the positive x-axis to the projection of the direction in the x-y-plane.- Throws:
NullPointerException- whendirectionisnullArithmeticException- when thedirectionVectorarray contains aNaNvalueIllegalArgumentException- when the length of thedirectionVectorarray is not 2
-
Ray3d
Construct a new Ray3d.- Parameters:
x- the x coordinate of the finite end point of the rayy- the y coordinate of the finite end point of the rayz- the z coordinate of the finite end point of the raydir- the direction- Throws:
IllegalArgumentException- whendirY, ordirZisNaN(should be impossible)
-
Ray3d
public Ray3d(double x, double y, double z, double throughX, double throughY, double throughZ) Construct a new Ray3d.- Parameters:
x- the x coordinate of the finite end point of the rayy- the y coordinate of the finite end point of the rayz- the z coordinate of the finite end point of the raythroughX- the x coordinate of another point on the raythroughY- the y coordinate of another point on the raythroughZ- the z coordinate of another point on the ray- Throws:
ArithmeticException- whenthroughX, orthroughY, orthroughZisNaNIllegalArgumentException- whenthroughX> == xandthroughY == yandthroughZ == z
-
Ray3d
Construct a new Ray3d.- Parameters:
x- the x coordinate of the finite end point of the rayy- the y coordinate of the finite end point of the rayz- the z coordinate of the finite end point of the raythroughPoint- another point on the ray- Throws:
NullPointerException- whenthroughPointisnullArithmeticException- whenx,y, orzisNaNIllegalArgumentException- whenthroughPointis exactly at(x, y)
-
Ray3d
public Ray3d(double[] xyz, double dirY, double dirZ) Create a new Ray3d from x, y, and z coordinates packed in a double array of three elements and direction dirY,dirZ.- Parameters:
xyz- thex,yandzcoordinates in that orderdirY- the angle from the positive Z axis direction in radians (the complement of the slope)dirZ- the angle from the positive X axis direction in radians- Throws:
NullPointerException- whenxyxisnullIllegalArgumentException- when the length of thexyzarray is not 3, or contains aNaNvalue, ordirY, ordirZisNaN
-
Ray3d
public Ray3d(double[] xyz, double[] directionVector) Create a new Ray3d from x, y, and z coordinates packed in a double array of three elements and direction dirY,dirZ.- Parameters:
xyz- thex,yandzcoordinates in that orderdirectionVector- the two direction anglesdirYanddirZin that order- Throws:
NullPointerException- whenxyz, ordirectionVectorisnullArithmeticException- whenxyz, ordirectionVectorcontains aNaNvalueIllegalArgumentException- when the length of thexyxis not 3 or the length of thedirectionVectoris not 2
-
Ray3d
Create a new Rayt3d from x, y, and z coordinates packed in a double array of three elements and a direction specified using a double array of two elements.- Parameters:
xyz- thex,yandzcoordinates in that orderdir- the direction- Throws:
NullPointerException- whenxyxarray ordirisnullArithmeticException- when thexyzarraycontains aNaNvalueIllegalArgumentException- when the length of thexyxarray is not 3
-
Ray3d
Construct a new Ray3d.- Parameters:
point- the finite end point of the raydirY- the angle from the positive Z axis direction in radians (the complement of the slope)dirZ- the angle from the positive X axis direction in radians- Throws:
NullPointerException- whenpointisnullIllegalArgumentException- whendirY, ordirZisNaN
-
Ray3d
Construct a new Ray3d.- Parameters:
point- the finite end point of the raydir- the direction- Throws:
NullPointerException- whenpointisnull, ordirisnull
-
Ray3d
Construct a new Ray3d.- Parameters:
point- the finite end point of the raythroughX- the x coordinate of another point on the raythroughY- the y coordinate of another point on the raythroughZ- the z coordinate of another point on the ray- Throws:
NullPointerException- whenpointisnullArithmeticException- whenthroughX, orthroughY, orthroughZisNaNIllegalArgumentException- whenthroughX == xandthroughY == yandthroughZ == z
-
Ray3d
public Ray3d(Point3d point, Point3d throughPoint) throws NullPointerException, IllegalArgumentException Construct a new Ray3d.- Parameters:
point- the finite end point of the raythroughPoint- another point on the ray- Throws:
NullPointerException- whenpointisnullorthroughPointisnullIllegalArgumentException- whenthroughPointis exactly atpoint
-
Ray3d
Construct a new Ray3d.- Parameters:
directedPoint- point and direction of the new Ray3d- Throws:
NullPointerException- whendirectedPointisnull
-
-
Method Details
-
getDirY
public final double getDirY()Description copied from interface:Directed3dRetrieve the angle from the positive z axis to the direction. Normally these are values between [0:π]. Angles ≤ π/2 indicate above the x-y-plane; positive slope, angles > π/2 indicate angles below this plane; negative slope.- Specified by:
getDirYin interfaceDirected3d- Overrides:
getDirYin classDirectedPoint3d- Returns:
- dirY
-
getDirZ
public final double getDirZ()Description copied from interface:DirectedRetrieve the angle from the positive x-axis. Positive rotates towards the positive y-axis (and beyond).- Specified by:
getDirZin interfaceDirected- Overrides:
getDirZin classDirectedPoint3d- Returns:
- the angle from the positive x-axis
-
getEndPoint
Description copied from interface:RayGet the finite end point of this Ray.- Specified by:
getEndPointin interfaceRay<Ray3d,DirectedPoint3d, Point3d> - Returns:
- the finite end point of this Ray
-
size
public int size()Description copied from interface:DrawableRetrieve the number of points that make up the object. -
iterator
- Specified by:
iteratorin interfaceIterable<Point3d>- Overrides:
iteratorin classDirectedPoint3d
-
getAbsoluteBounds
Description copied from interface:Drawable3dRetrieve the bounding box of the object in absolute coordinates.- Specified by:
getAbsoluteBoundsin interfaceDrawable3d- Overrides:
getAbsoluteBoundsin classPoint3d- Returns:
- the bounding box of the object in absolute coordinates
-
neg
Description copied from interface:PointReturn a new Point with negated coordinate values. If this is aDirectedPoint,dirY(in case this is aDirectedPoint3danddirZare negated.- Specified by:
negin interfacePoint<Point3d>- Overrides:
negin classDirectedPoint3d- Returns:
- a new point with negated coordinate values
-
flip
Description copied from interface:RayFlip the direction of the Ray (creates and returns a new Ray instance).- Specified by:
flipin interfaceRay<Ray3d,DirectedPoint3d, Point3d> - Returns:
- Ray at the same location, but with
dirZ(in case of a Ray3d) incremented by π anddirYsubtracted from π
-
getLocationExtended
public Ray3d getLocationExtended(double position) throws ArithmeticException, IllegalArgumentException Description copied from interface:RayGet the location at a position on the line, with its direction. Position must be a finite value- Specified by:
getLocationExtendedin interfaceRay<Ray3d,DirectedPoint3d, Point3d> - Parameters:
position- the position on the line for which to calculate the point on the line- Returns:
- a ray with the same direction as this ray
- Throws:
ArithmeticException- whenpositionisNaNIllegalArgumentException- whenpositioninfinite
-
closestPointOnRay
Description copied from interface:RayProject a Point on a Ray. If the the projected points lies outside the ray, the start point of the ray is returned. Otherwise the closest point on the ray is returned.
Adapted from example code published by Paul Bourke.- Specified by:
closestPointOnRayin interfaceRay<Ray3d,DirectedPoint3d, Point3d> - Parameters:
point- the point to project onto the segment- Returns:
- either the start point, or DirectedPoint that lies somewhere on this Ray
- Throws:
NullPointerException- whenpointisnull
-
projectOrthogonal
Description copied from interface:ProjectProject a point onto this object. For PolyLines and Polygons, there may be multiple valid solutions. In that case the solution that lies on the closest segment is returned. If there is no valid solution on the closest segment,nullis returned.- Specified by:
projectOrthogonalin interfaceProject<Point3d>- Parameters:
point- the point- Returns:
- the projection of the point (may be null if no sensible projection is possible). If the result is not
null; the result lies somewhere on this object. - Throws:
NullPointerException- whenpointisnull
-
projectOrthogonalExtended
Description copied from interface:ProjectProject a point onto this object. For PolyLines and Polygons, there may be multiple valid solutions. In that case the solution that lies on the closest segment is returned.- Specified by:
projectOrthogonalExtendedin interfaceProject<Point3d>- Parameters:
point- the point- Returns:
- the projection of the point. This result cannot be
null, but it may not lie on this object, but, in stead, lie on a line, or plane that extends this object
-
projectOrthogonalFractional
Description copied from interface:ProjectProject a point onto this object. For PolyLines and Polygons, there may be multiple valid solutions. In that case the solution that lies on the closest segment is returned. If there is no valid solution on the closest segment,NaNis returned.- Specified by:
projectOrthogonalFractionalin interfaceProject<Point3d>- Parameters:
point- the point- Returns:
- the fractional position of the projection of the point (may be
NaNif no sensible projection is possible). If the result is notNaN; the result lies somewhere on this object. - Throws:
NullPointerException- whenpointisnull
-
projectOrthogonalFractionalExtended
Description copied from interface:ProjectProject a point onto this object. For PolyLines and Polygons, there may be multiple valid solutions. In that case the solution that lies on the closest segment is returned.- Specified by:
projectOrthogonalFractionalExtendedin interfaceProject<Point3d>- Parameters:
point- the point- Returns:
- the fractional position of the projection of the point. This result cannot be
NaN, but it may be outside the range 0.0 .. 1.0. - Throws:
NullPointerException- whenpointisnull
-
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.- Specified by:
toStringin interfaceDrawable<Point3d>- Overrides:
toStringin classDirectedPoint3d- Returns:
- a string describing the Drawable
-
toString
Description copied from interface:DrawableProduce a String describing the Drawable.- Specified by:
toStringin interfaceDrawable<Point3d>- Overrides:
toStringin classDirectedPoint3d- 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()- Overrides:
hashCodein classDirectedPoint3d
-
equals
- Overrides:
equalsin classDirectedPoint3d
-