Package org.djutils.draw.point
Class DirectedPoint2d
java.lang.Object
org.djutils.draw.point.Point2d
org.djutils.draw.point.DirectedPoint2d
- All Implemented Interfaces:
Serializable
,Directed<DirectedPoint2d>
,Directed2d<DirectedPoint2d>
,Drawable<Point2d>
,Drawable2d
,Point<Point2d>
- Direct Known Subclasses:
Ray2d
DirectedPoint2d.java.
Copyright (c) 2023-2024 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
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionfinal double
The counter-clockwise rotation around the point in radians. -
Constructor Summary
ConstructorDescriptionDirectedPoint2d
(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. -
Method Summary
Modifier and TypeMethodDescriptionabs()
Return a new Point with absolute coordinate values.boolean
epsilonEquals
(DirectedPoint2d other, double epsilonCoordinate, double epsilonRotation) Compare this Directed with another Directed with specified tolerances in the coordinates and the angles.boolean
double
getDirZ()
Retrieve the angle from the positive x-axis.Iterator<? extends DirectedPoint2d>
Retrieve, or generate all points that make up the object.int
hashCode()
interpolate
(DirectedPoint2d otherPoint, double fraction) Interpolate towards another DirectedPoint2d with a fraction.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, getBounds, getX, getY, interpolate, intersectionOfLines, intersectionOfLines, intersectionOfLines, intersectionOfLineSegments, intersectionOfLineSegments, intersectionOfLineSegments, size, toPoint2D
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.Drawable2d
getDimensions
-
Field Details
-
dirZ
public final double dirZThe counter-clockwise rotation around the point in radians.
-
-
Constructor Details
-
DirectedPoint2d
Construct a new DirectedPoint2d with an x and y coordinate and a direction.- Parameters:
x
- double; the x coordinatey
- double; the y coordinatedirZ
- double; the counter-clockwise rotation around the point in radians- Throws:
IllegalArgumentException
- when any coordinate or dirZ is NaN
-
DirectedPoint2d
Construct a new DirectedPoint2d from an x and y coordinates in a double[] and a direction.- Parameters:
xy
- double[]; the x and y coordinates in that orderdirZ
- double; the counter-clockwise rotation around the point in radians- Throws:
NullPointerException
- when xy is nullIllegalArgumentException
- when the dimension of xy is not 2 or any value in xy is NaN or rotZ is NaN
-
DirectedPoint2d
Construct a new DirectedPoint2d from an AWT Point2D and a direction.- Parameters:
point
- Point2D; an AWT Point2DdirZ
- double; the counter-clockwise rotation around the point in radians- Throws:
IllegalArgumentException
- when any coordinate in point is NaN, or rotZ is NaN
-
DirectedPoint2d
Construct a new DirectedPoint2d from a Point2d and a direction.- Parameters:
point
- Point2d; a point (with or without orientation)dirZ
- double; the counter-clockwise rotation around the point in radians- Throws:
IllegalArgumentException
- when rotZ is NaN
-
DirectedPoint2d
public DirectedPoint2d(double x, double y, double throughX, double throughY) throws DrawRuntimeException Construct a new DirectedPoint2d from two coordinates and the coordinates of a point that the direction goes through.- Parameters:
x
- double; the x coordinate of the of the new DirectedPointy
- double; the y coordinate of the of the new DirectedPointthroughX
- double; the x-coordinate of a point that the direction goes throughthroughY
- double; the y-coordinate of a point that the direction goes through- Throws:
DrawRuntimeException
- when throughX == x and throughY == y, or any through-value is NaN
-
DirectedPoint2d
public DirectedPoint2d(Point2d point, double throughX, double throughY) throws NullPointerException, DrawRuntimeException Construct a new DirectedPoint2d from a Point2d and the coordinates of a point that the direction goes through.- Parameters:
point
- Point2d; the pointthroughX
- double; the x coordinate of a point that the direction goes throughthroughY
- double; the y coordinate of a point that the direction goes through- Throws:
NullPointerException
- when point is nullDrawRuntimeException
- when throughX == point.x and throughY == point.y, or any through-value is NaN
-
-
Method Details
-
translate
Description copied from class:Point2d
Return a new Point2d with a translation by the provided dx and dy.- Overrides:
translate
in classPoint2d
- Parameters:
dx
- double; the x translationdy
- double; the y translation- Returns:
- P; a new point with the translated coordinates
- Throws:
IllegalArgumentException
- when dx, or dy is NaN
-
translate
Description copied from class:Point2d
Return 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:
translate
in classPoint2d
- Parameters:
dx
- double; the x translationdy
- double; the y translationz
- double; the z translation- Returns:
- Point2d; 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. -
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. -
interpolate
public DirectedPoint2d interpolate(DirectedPoint2d otherPoint, double fraction) throws NullPointerException, IllegalArgumentException 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
- DirectedPoint2d; 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, theotherPoint
is returned- Returns:
- DirectedPoint2d; a new OrientedPoint2d at the requested fraction
- Throws:
NullPointerException
- when otherPoint is nullIllegalArgumentException
- when fraction is NaN
-
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
- double; the rotation around the z-axis- Returns:
- DirectedPoint2d; a new point with the same coordinates and applied rotation
- Throws:
IllegalArgumentException
- when deltaRotZ is NaN
-
getDirZ
public double getDirZ()Description copied from interface:Directed2d
Retrieve the angle from the positive x-axis. Positive rotates towards the positive y-axis (and beyond).- Specified by:
getDirZ
in interfaceDirected2d<DirectedPoint2d>
- Returns:
- double; dirZ
-
getPoints
Description copied from interface:Drawable
Retrieve, or generate all points that make up the object. -
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<Point2d>
- Overrides:
toString
in classPoint2d
- 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
-
epsilonEquals
public boolean epsilonEquals(DirectedPoint2d other, double epsilonCoordinate, double epsilonRotation) throws NullPointerException, IllegalArgumentException Description copied from interface:Directed
Compare this Directed with another Directed with specified tolerances in the coordinates and the angles.- Specified by:
epsilonEquals
in interfaceDirected<DirectedPoint2d>
- Parameters:
other
- D; the Directed to compare toepsilonCoordinate
- double; the upper bound of difference for one of the coordinates; use Double.POSITIVE_INFINITY if you do not want to check the coordinatesepsilonRotation
- double; the upper bound of difference for the direction(s); use Double.POSITIVE_INFINITY if you do not want to check the angles- Returns:
- boolean; true if x, y, and z are less than epsilonCoordinate apart, and rotX, rotY and rotZ are less than epsilonRotation apart, otherwise false
- Throws:
NullPointerException
- when point is nullIllegalArgumentException
- epsilonCoordinate or epsilonRotation is NaN or negative
-
hashCode
public int hashCode() -
equals
-