Package org.djutils.draw.line
Class Polygon3d
- java.lang.Object
-
- org.djutils.draw.line.PolyLine3d
-
- org.djutils.draw.line.Polygon3d
-
- All Implemented Interfaces:
Serializable
,Drawable<Point3d>
,Drawable3d
,PolyLine<PolyLine3d,Point3d,Ray3d,LineSegment3d>
,Project<Point3d>
public class Polygon3d extends PolyLine3d
Polygon3d.java. Closed PolyLine3d. The actual closing point (which is the same as the starting point) is NOT included in the super PolyLine3d. The constructors automatically remove the last point if it is a at the same location as the first point.Copyright (c) 2020-2023 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:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.djutils.draw.line.PolyLine
PolyLine.TransitionFunction
-
-
Field Summary
-
Fields inherited from interface org.djutils.draw.line.PolyLine
DEFAULT_CIRCLE_PRECISION, DEFAULT_OFFSET_FILTER_RATIO, DEFAULT_OFFSET_MAXIMUM_FILTER_VALUE, DEFAULT_OFFSET_MINIMUM_FILTER_VALUE, DEFAULT_OFFSET_PRECISION
-
-
Constructor Summary
Constructors Constructor Description Polygon3d(boolean filterDuplicates, List<Point3d> pointList)
Create a new Polygon3d, optionally filtering out repeating successive points.Polygon3d(boolean filterDuplicates, Point3d... points)
Create a new Polygon3d, optionally filtering out repeating successive points.Polygon3d(double[] x, double[] y, double[] z)
Construct a new Polygon3d.Polygon3d(Iterator<Point3d> iterator)
Construct a new Polygon3d from an iterator that yields Point3d.Polygon3d(List<Point3d> points)
Construct a new Polygon3d from a list of Point3d objects.Polygon3d(Point3d[] points)
Construct a new Polygon3d.Polygon3d(Point3d point1, Point3d point2, Point3d... otherPoints)
Construct a new Polygon3d.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) static double[]
fixClosingPointX(double[] x, double[] y, double[] z)
Ensure that the last point is not equal to the first.(package private) static double[]
fixClosingPointY(double[] x, double[] y, double[] z)
Ensure that the last point is not equal to the first.(package private) static double[]
fixClosingPointZ(double[] x, double[] y, double[] z)
Ensure that the last point is not equal to the first.double
getLength()
Return the length of this line.LineSegment3d
getSegment(int index)
Extract one LineSegment of this PolyLine, or Polygon.Polygon2d
project()
Project the object onto the z=0 plane.Polygon3d
reverse()
Construct a new PolyLine with all points of this PolyLine in reverse order.String
toExcel()
Convert this PolyLine to something that MS-Excel can plot.String
toString()
Produce a string describing the Drawable using default conversion for the (double) coordinate values.String
toString(String doubleFormat, boolean doNotIncludeClassName)
Produce a String describing the Drawable.-
Methods inherited from class org.djutils.draw.line.PolyLine3d
cleanPoints, closestPointOnPolyLine, concatenate, concatenate, concatenate, equals, extract, get, getBounds, getLocation, getLocationExtended, getPoints, getX, getY, getZ, hashCode, instantiate, iteratorToList, lengthAtIndex, makeArray, noiseFilteredLine, offsetLine, offsetLine, projectOrthogonal, projectOrthogonalExtended, projectOrthogonalFractional, projectOrthogonalFractionalExtended, size, transitionLine, truncate
-
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
-
Methods inherited from interface org.djutils.draw.line.PolyLine
extractFractional, find, getFirst, getLast, getLocationFraction, getLocationFraction, getLocationFractionExtended, offsetLine, offsetLine
-
-
-
-
Constructor Detail
-
Polygon3d
public Polygon3d(double[] x, double[] y, double[] z) throws DrawRuntimeException
Construct a new Polygon3d.- Parameters:
x
- double[]; the x coordinates of the pointsy
- double[]; the y coordinates of the pointsz
- double[]; the z coordinates of the points- Throws:
DrawRuntimeException
- when any two successive points are equal, or when there are too few points
-
Polygon3d
public Polygon3d(Point3d[] points) throws NullPointerException, DrawRuntimeException
Construct a new Polygon3d.- Parameters:
points
- Point3d[]; array of Point3d objects.- Throws:
NullPointerException
- when points is nullDrawRuntimeException
- when points is too short, or contains successive duplicate points
-
Polygon3d
public Polygon3d(Point3d point1, Point3d point2, Point3d... otherPoints) throws NullPointerException, DrawRuntimeException
Construct a new Polygon3d.- Parameters:
point1
- Point3d; the first point of the new Polygon3dpoint2
- Point3d; the second point of the new Polygon3dotherPoints
- Point3d[]; all remaining points of the new Polygon3d (may be null)- Throws:
NullPointerException
- when point1 or point2 is nullDrawRuntimeException
- when point1 is equal to the last point of otherPoints, or any two successive points are equal
-
Polygon3d
public Polygon3d(List<Point3d> points) throws NullPointerException, DrawRuntimeException
Construct a new Polygon3d from a list of Point3d objects.- Parameters:
points
- List<Point3d>; the list of points- Throws:
NullPointerException
- when points is nullDrawRuntimeException
- when points is too short, or the last two points are at the same location
-
Polygon3d
public Polygon3d(Iterator<Point3d> iterator)
Construct a new Polygon3d from an iterator that yields Point3d.- Parameters:
iterator
- Iterator<Point3d>; the iterator
-
Polygon3d
public Polygon3d(boolean filterDuplicates, Point3d... points) throws DrawRuntimeException
Create a new Polygon3d, optionally filtering out repeating successive points.- Parameters:
filterDuplicates
- boolean; if true; filter out successive repeated points; otherwise do not filterpoints
- Point3d...; the coordinates of the polygon as Point3d- Throws:
DrawRuntimeException
- when number of points < 2
-
Polygon3d
public Polygon3d(boolean filterDuplicates, List<Point3d> pointList) throws DrawRuntimeException
Create a new Polygon3d, optionally filtering out repeating successive points.- Parameters:
filterDuplicates
- boolean; if true; filter out successive repeated points; otherwise do not filterpointList
- List<Point3d>; list of the coordinates of the line as Point3d; any duplicate points in this list are removed (this method may modify the provided list)- Throws:
DrawRuntimeException
- when number of non-equal points < 2
-
-
Method Detail
-
fixClosingPointX
static double[] fixClosingPointX(double[] x, double[] y, double[] z)
Ensure that the last point is not equal to the first. Remove the last point if necessary.- Parameters:
x
- double[]; the x coordinates of the pointsy
- double[]; the y coordinates of the pointsz
- double[]; the z coordinates of the points- Returns:
- double[]; the y coordinates of the points (possibly a copy with the last element removed)
-
fixClosingPointY
static double[] fixClosingPointY(double[] x, double[] y, double[] z)
Ensure that the last point is not equal to the first. Remove the last point if necessary.- Parameters:
x
- double[]; the x coordinates of the pointsy
- double[]; the y coordinates of the pointsz
- double[]; the z coordinates of the points- Returns:
- double[]; the y coordinates of the points (possibly a copy with the last element removed)
-
fixClosingPointZ
static double[] fixClosingPointZ(double[] x, double[] y, double[] z)
Ensure that the last point is not equal to the first. Remove the last point if necessary.- Parameters:
x
- double[]; the x coordinates of the pointsy
- double[]; the y coordinates of the pointsz
- double[]; the z coordinates of the points- Returns:
- double[]; the y coordinates of the points (possibly a copy with the last element removed)
-
getLength
public double getLength()
Return the length of this line. This is NOT the number of points; it is the sum of the lengths of the segments.- Specified by:
getLength
in interfacePolyLine<PolyLine3d,Point3d,Ray3d,LineSegment3d>
- Overrides:
getLength
in classPolyLine3d
- Returns:
- double; the length of this line
-
getSegment
public LineSegment3d getSegment(int index)
Extract one LineSegment of this PolyLine, or Polygon.- Specified by:
getSegment
in interfacePolyLine<PolyLine3d,Point3d,Ray3d,LineSegment3d>
- Overrides:
getSegment
in classPolyLine3d
- Parameters:
index
- int; the rank number of the segment; must be in range 0..Size() - 2 for PolyLine, or 0.. Size() - 1 for Polygon.- Returns:
- LS; the LineSegment that connects point index to point index + 1
-
project
public Polygon2d project() throws DrawRuntimeException
Project the object onto the z=0 plane.- Specified by:
project
in interfaceDrawable3d
- Overrides:
project
in classPolyLine3d
- Returns:
- Drawable2d; the projected object
- Throws:
DrawRuntimeException
- 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.
-
reverse
public Polygon3d reverse()
Construct a new PolyLine with all points of this PolyLine in reverse order.- Returns:
- L; the new PolyLine
-
toExcel
public final String toExcel()
Convert this PolyLine to something that MS-Excel can plot.- Specified by:
toExcel
in interfacePolyLine<PolyLine3d,Point3d,Ray3d,LineSegment3d>
- Overrides:
toExcel
in classPolyLine3d
- Returns:
- String MS-excel XY, or XYZ plottable output
-
toString
public final String toString()
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.- Specified by:
toString
in interfaceDrawable<Point3d>
- Overrides:
toString
in classPolyLine3d
- Returns:
- String; a string describing the Drawable
-
toString
public String toString(String doubleFormat, boolean doNotIncludeClassName)
Produce a String describing the Drawable.- Specified by:
toString
in interfaceDrawable<Point3d>
- Overrides:
toString
in classPolyLine3d
- 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
-
-