Package org.djutils.draw.point
Class DirectedPoint2d
java.lang.Object
org.djutils.draw.point.Point2d
org.djutils.draw.point.DirectedPoint2d
- All Implemented Interfaces:
Serializable,Iterable<Point2d>,Directed,Drawable<Point2d>,Drawable2d,Point<Point2d>
- Direct Known Subclasses:
Ray2d
A DirectedPoint2d is a Point2d that additionally carries a direction in 2d-space (dirZ). This is not the direction
that the point is when viewed from the origin (0,0).
Copyright (c) 2023-2025 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://djutils.org. The DJUTILS project is distributed under a three-clause BSD-style license, which can be found at https://djutils.org/docs/license.html.
- Author:
- Alexander Verbraeck, Peter Knoppers, Wouter Schakel
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal doubleThe counter-clockwise rotation around the point in radians. -
Constructor Summary
ConstructorsConstructorDescriptionDirectedPoint2d(double[] xy, double dirZ) Construct a new DirectedPoint2d from an x and y coordinates in a double[] and a direction.DirectedPoint2d(double x, double y, double dirZ) Construct a new DirectedPoint2d with an x and y coordinate and a direction.DirectedPoint2d(double x, double y, double throughX, double throughY) Construct a new DirectedPoint2d from two coordinates and the coordinates of a point that the direction goes through.DirectedPoint2d(Point2D point, double dirZ) Construct a new DirectedPoint2d from an AWT Point2D and a direction.DirectedPoint2d(Point2d point, double dirZ) Construct a new DirectedPoint2d from a Point2d and a direction.DirectedPoint2d(Point2d point, double throughX, double throughY) Construct a new DirectedPoint2d from a Point2d and the coordinates of a point that the direction goes through.DirectedPoint2d(Point2d point, Point2d throughPoint) Construct a new DirectedPoint2d from a Point2d and a point that the direction goes through. -
Method Summary
Modifier and TypeMethodDescriptionabs()Return a new Point with absolute coordinate values.booleanepsilonEquals(DirectedPoint2d other, double epsilonCoordinate, double epsilonDirection) Compare this Directed with another Directed with specified tolerances in the coordinates and the angles.booleandoublegetDirZ()Retrieve the angle from the positive x-axis.inthashCode()interpolate(DirectedPoint2d otherPoint, double fraction) Interpolate towards another DirectedPoint2d 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.rotate(double rotateZ) Return a new DirectedPoint2d with an in-place rotation around the z-axis by the provided rotateZ.scale(double factor) Return a new Point with the coordinates of this point scaled by the provided factor.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 Point2d with a translation by the provided dx and dy.translate(double dX, double dY, double z) Return a new Point3d with a translation by the provided dx, dy and dz.Methods inherited from class org.djutils.draw.point.Point2d
circleIntersections, closestPointOnLine, closestPointOnLine, closestPointOnLine, closestPointOnSegment, closestPointOnSegment, directionTo, distance, distanceSquared, epsilonEquals, fractionalPositionOnLine, getAbsoluteBounds, getX, getY, interpolate, intersectionOfLines, intersectionOfLines, intersectionOfLines, intersectionOfLineSegments, intersectionOfLineSegments, intersectionOfLineSegments, size, toPoint2DMethods 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.Drawable2d
getDimensionsMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
dirZ
public final double dirZThe counter-clockwise rotation around the point in radians.
-
-
Constructor Details
-
DirectedPoint2d
public DirectedPoint2d(double x, double y, double dirZ) Construct a new DirectedPoint2d with an x and y coordinate and a direction.- Parameters:
x- the x coordinatey- the y coordinatedirZ- the counter-clockwise rotation around the point in radians- Throws:
IllegalArgumentException- when any coordinate ordirZisNaN
-
DirectedPoint2d
public DirectedPoint2d(double[] xy, double dirZ) Construct a new DirectedPoint2d from an x and y coordinates in a double[] and a direction.- Parameters:
xy- thexandycoordinates in that orderdirZ- the counter-clockwise rotation around the point in radians- Throws:
NullPointerException- whenxyisnullArithmeticException- when any value inxyisNaNorrotZisNaNIllegalArgumentException- when the length ofxyis not 2
-
DirectedPoint2d
Construct a new DirectedPoint2d from an AWT Point2D and a direction.- Parameters:
point- java.awt.geom.Point2DdirZ- the counter-clockwise rotation around the point in radians- Throws:
NullPointerException- whenpointisnullArithmeticException- whenrotZisNaN
-
DirectedPoint2d
Construct a new DirectedPoint2d from a Point2d and a direction.- Parameters:
point- a point (with or without orientation)dirZ- the counter-clockwise rotation around the point in radians- Throws:
NullPointerException- whenpointisnullArithmeticException- whenrotZisNaN
-
DirectedPoint2d
public DirectedPoint2d(double x, double y, double throughX, double throughY) Construct a new DirectedPoint2d from two coordinates and the coordinates of a point that the direction goes through.- Parameters:
x- the x coordinate of the of the new DirectedPointy- the y coordinate of the of the new DirectedPointthroughX- the x-coordinate of a point that the direction goes throughthroughY- the y-coordinate of a point that the direction goes through- Throws:
ArithmeticException- whenthroughX, orthroughYisnullIllegalArgumentException- whenthroughX == xandthroughY == y
-
DirectedPoint2d
Construct a new DirectedPoint2d from a Point2d and a point that the direction goes through.- Parameters:
point- the pointthroughPoint- the point that the direction goes through- Throws:
NullPointerException- whenpointisnull, orthroughPoint==nullIllegalArgumentException- whenthroughX == point.xandthroughY == point.y
-
DirectedPoint2d
Construct a new DirectedPoint2d from a Point2d and the coordinates of a point that the direction goes through.- Parameters:
point- the pointthroughX- the x coordinate of a point that the direction goes throughthroughY- the y coordinate of a point that the direction goes through- Throws:
NullPointerException- whenpointisnullArithmeticException- whenthroughX, orthroughYisNaNIllegalArgumentException- whenthroughX == point.xandthroughY == point.y
-
-
Method Details
-
translate
Description copied from class:Point2dReturn a new Point2d with a translation by the provided dx and dy. -
translate
public DirectedPoint3d translate(double dX, double dY, double z) throws ArithmeticException, IllegalArgumentException Description copied from class:Point2dReturn a new Point3d with a translation by the provided dx, dy and dz. If this is an OrientedPoint2d, then the result is an OrientedPoint3d with rotX copied from this and rotY and rotZ are set to 0.0.- Overrides:
translatein classPoint2d- Parameters:
dX- the x translationdY- the y translationz- the z translation- Returns:
- a new point with the translated coordinates
- Throws:
IllegalArgumentException- whendX,dY, ordZisNaNArithmeticException
-
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. -
interpolate
Interpolate towards another DirectedPoint2d 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. DirZ is interpolated using the AngleUtil.interpolateShortest method.- 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. Iffractionis 0;thisPoint is returned; iffractionis 1, theotherPointis returned- Returns:
- a new OrientedPoint2d at the requested fraction
- Throws:
NullPointerException- whenotherPointisnullArithmeticException- whenfractionisNaN
-
rotate
Return a new DirectedPoint2d with an in-place rotation around the z-axis by the provided rotateZ. The resulting rotation is normalized between -π and π.- Parameters:
rotateZ- the rotation around the z-axis- Returns:
- a new point with the same coordinates and applied rotation
- Throws:
ArithmeticException- whenrotateZisNaN
-
getDirZ
public double getDirZ()Description copied from interface:DirectedRetrieve the angle from the positive x-axis. Positive rotates towards the positive y-axis (and beyond). -
iterator
-
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<Point2d>- Overrides:
toStringin classPoint2d- 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
-
epsilonEquals
public boolean epsilonEquals(DirectedPoint2d other, double epsilonCoordinate, double epsilonDirection) throws NullPointerException, IllegalArgumentException Compare this Directed with another Directed with specified tolerances in the coordinates and the angles.- Parameters:
other- the Directed to compare toepsilonCoordinate- the upper bound of difference for one of the coordinates; use Double.POSITIVE_INFINITY if you do not want to check the coordinatesepsilonDirection- the upper bound of difference for the direction(s); use Double.POSITIVE_INFINITY if you do not want to check the angles- Returns:
- boolean;
trueifxandyare less thanepsilonCoordinateapart, androtZis less thanepsilonDirectionapart, otherwisefalse - Throws:
NullPointerException- whenotherisnullArithmeticException- whenepsilonCoordinateorepsilonDirectionisNaNIllegalArgumentException-epsilonCoordinateorepsilonDirectionisnegative
-
hashCode
public int hashCode() -
equals
-