Class PGS_SegmentSet
Methods in this class output segments as collections of
PEdges
; such collections can be converted
into LINES PShapes with toPShape(edges)
.
- Since:
- 1.3.0
- Author:
- Michael Carleton
-
Method Summary
Modifier and TypeMethodDescriptionstatic processing.core.PShape
dissolve
(Collection<PEdge> segments) Dissolves the edges from a collection ofPEdges
into a set of maximal-length LineStrings in which each unique segment appears only once.filterAxisAligned
(List<PEdge> segments, double angleDelta) Removes axis-aligned (horizontal and vertical) segments (within a given angle tolerance) from a collection of segments.filterByAverageLength
(List<PEdge> segments, double fraction) Removes segments having a length either less than some fraction or more than1/fraction
of the mean segment length from a collection of segments.filterByMinLength
(List<PEdge> segments, double minLength) Removes segments having a length less than the given length from a collection of segmensts.fromPShape
(processing.core.PShape shape) Extracts a list of unique PEdge segments representing the given shape.getPolygonInteriorSegments
(List<PEdge> segments, processing.core.PShape shape) Retains line segments from a set of line segments that are wholly contained within a given shape.graphMatchedSegments
(double width, double height, int n, long seed) Generates N non-intersecting segments via a Perfect matching algorithm applied to a triangulation populated with random points.graphMatchedSegments
(List<processing.core.PVector> points) Generates non-intersecting segments via a Perfect matching algorithm applied to a triangulation populated with the given points.graphMatchedSegments
(org.tinfour.common.IIncrementalTin triangulation) Generates non-intersecting segments via a Perfect matching algorithm applied to the given triangulation.nodedSegments
(double width, double height, int n, long seed) Generates N non-intersecting segments via intersection and noding.parallelSegments
(double centerX, double centerY, double length, double spacing, double angle, int n) Generates a set of N straight parallel segments, centered on a given point.stochasticSegments
(double width, double height, int n) Generates a set of N random non-intersecting line segments via brute-forcing.stochasticSegments
(double width, double height, int n, double length) Generates a set of N random non-intersecting line segments of the given length via brute-forcing.stochasticSegments
(double width, double height, int n, double minLength, double maxLength, long seed) Generates a set of N random non-intersecting line segments via brute-forcing.Stretches each PEdge segment in the provided list by a specified factor.static processing.core.PShape
toPShape
(Collection<PEdge> segments) Converts a collection ofPEdges
into aLINES
shape.static processing.core.PShape
Converts a collection ofPEdges
into aLINES
shape, having the (optional) styling provided.
-
Method Details
-
nodedSegments
Generates N non-intersecting segments via intersection and noding.The segments are generated within a bounding box anchored at (0, 0) having the width and height specified.
Algorithm:
- Generate a set of N random segments (will have many intersections)
- Node the random segment set and split segments at intersections
- Shrink split segments by ~30% (to increase distance between each other)
- The split segments will be very numerous; sort by length and return the longest N segments
- Parameters:
width
- width of the bounds in which to generate segments; segment x coordinates will not be greater than this valueheight
- height of the bounds in which to generate segments; segment y coordinates will not be greater than this valuen
- number of segments to generateseed
- number used to initialize the underlying pseudorandom number generator- Returns:
- set of N random non-intersecting line segments
-
graphMatchedSegments
Generates N non-intersecting segments via a Perfect matching algorithm applied to a triangulation populated with random points.The segments are generated within a bounding box anchored at (0, 0) having the width and height specified.
The
graphMatchedSegments
methods are arguably the best approaches for random segment set generation.- Parameters:
width
- width of the bounds in which to generate segments; segment x coordinates will not be greater than this valueheight
- height of the bounds in which to generate segments; segment y coordinates will not be greater than this valuen
- number of segments to generateseed
- number used to initialize the underlying pseudorandom number generator- Returns:
- set of N random non-intersecting line segments
-
graphMatchedSegments
Generates non-intersecting segments via a Perfect matching algorithm applied to a triangulation populated with the given points.Generates N/2 segments, where N is the number of points in the input. If the number of points is odd, the last point is discarded.
The
graphMatchedSegments
methods are arguably the best approaches for random segment set generation.- Parameters:
points
- point set from which to compute segments- Returns:
- set of non-intersecting line segments
-
graphMatchedSegments
Generates non-intersecting segments via a Perfect matching algorithm applied to the given triangulation.Generates N/2 segments, where N is the number of vertices in the triangulation. If the number of points is odd, the last point is discarded.
The
graphMatchedSegments
methods are arguably the best approaches for random segment set generation.- Parameters:
triangulation
- triangulation object to use for vertices and graph connectivity- Returns:
- set of non-intersecting line segments
-
stochasticSegments
Generates a set of N random non-intersecting line segments via brute-forcing. Plentifully fast enough for many applications.The segments are generated within a bounding box anchored at (0, 0) having the width and height specified.
- Parameters:
width
- width of the bounds in which to generate segments; segment x coordinates will not be greater than this valueheight
- height of the bounds in which to generate segments; segment y coordinates will not be greater than this valuen
- number of segments to generate- Returns:
- set of N random non-intersecting line segments
- See Also:
-
stochasticSegments
Generates a set of N random non-intersecting line segments of the given length via brute-forcing. Plentifully fast enough for many applications.The segments are generated within a bounding box anchored at (0, 0) having the width and height specified.
- Parameters:
width
- width of the bounds in which to generate segments; segment x coordinates will not be greater than this valueheight
- height of the bounds in which to generate segments; segment y coordinates will not be greater than this valuen
- number of segments to generatelength
- segment length (for all segments)- Returns:
- set of N random non-intersecting line segments
- See Also:
-
stochasticSegments
public static List<PEdge> stochasticSegments(double width, double height, int n, double minLength, double maxLength, long seed) Generates a set of N random non-intersecting line segments via brute-forcing. Plentifully fast enough for many applications.The segments are generated within a bounding box anchored at (0, 0) having the width and height specified.
- Parameters:
width
- width of the bounds in which to generate segments; segment x coordinates will not be greater than this valueheight
- height of the bounds in which to generate segments; segment y coordinates will not be greater than this valuen
- number of segments to generateminLength
- minimum segment length (inclusive)maxLength
- maximum segment length (exclusive)seed
- number used to initialize the underlying pseudorandom number generator- Returns:
- set of N random non-intersecting line segments
-
parallelSegments
public static List<PEdge> parallelSegments(double centerX, double centerY, double length, double spacing, double angle, int n) Generates a set of N straight parallel segments, centered on a given point.- Parameters:
centerX
- the x coordinate of the center of the segments arrangmentcenterY
- the y coordinate of the center of the segments arrangmentlength
- length of each segmentspacing
- distance between successive segmentsangle
- line angle in radians, where 0 is parallel to x-axis (horizontal)n
- number of segments to generate. if odd then the middle segment lies on the center point; if even, then the first two segments are spaced evenly from the center point- Returns:
- set of N parallel line segments
-
toPShape
Converts a collection ofPEdges
into aLINES
shape.- Parameters:
segments
- collection of segments- Returns:
LINES
shape representing segments
-
toPShape
public static processing.core.PShape toPShape(Collection<PEdge> segments, @Nullable Integer strokeColor, @Nullable Integer strokeCap, @Nullable Integer strokeWeight) Converts a collection ofPEdges
into aLINES
shape, having the (optional) styling provided.- Parameters:
segments
- collection of PEdge segmentsstrokeColor
- nullable/optional (default =Colors.PINK
)strokeCap
- nullable/optional (default =ROUND
)strokeWeight
- nullable/optional (default =2
)- Returns:
- shape representing segments
-
dissolve
Dissolves the edges from a collection ofPEdges
into a set of maximal-length LineStrings in which each unique segment appears only once. This method works by fusing segments that share endpoints into longer linear strings.This method may be preferred to
toPShape()
when the input segments form a linear string(s).- Parameters:
segments
- Collection of PEdge objects to dissolve into maximal-length LineStrings- Returns:
- A PShape object representing the dissolved LineStrings
- Since:
- 1.4.0
-
fromPShape
Extracts a list of unique PEdge segments representing the given shape.This method iterates through all the child shapes of the input shape, creating PEdge segments for each pair of consecutive vertices.
- Parameters:
shape
- The shape from which to extract the edges. Supports holes and GROUP shapes.- Returns:
- A list of unique PEdge segments representing the edges of the input shape and its child shapes.
- Since:
- 1.4.0
-
stretch
Stretches each PEdge segment in the provided list by a specified factor. The stretch is applied by scaling the distance between the edge's vertices, while keeping the midpoint of the edge constant.- Parameters:
segments
- The list of PEdges to be stretched.factor
- The factor by which to stretch each PEdge. A value greater than 1 will stretch the edges, while a value between 0 and 1 will shrink them.- Returns:
- A new List of PEdges representing the stretched edges.
- Since:
- 1.4.0
-
filterByMinLength
Removes segments having a length less than the given length from a collection of segmensts.- Parameters:
segments
- list of segments to filterminLength
- the minimum segment length to keep- Returns:
- a filtered copy of input collection
-
filterByAverageLength
Removes segments having a length either less than some fraction or more than1/fraction
of the mean segment length from a collection of segments.This method can be used to homogenise a segment set.
- Parameters:
segments
- list of segments to filterfraction
- fraction of mean length to keep segments- Returns:
- a filtered copy of input collection
-
filterAxisAligned
Removes axis-aligned (horizontal and vertical) segments (within a given angle tolerance) from a collection of segments.- Parameters:
segments
- list of segments to filterangleDelta
- angle tolerance, in radians- Returns:
- a filtered copy of the input where axis-aligned segments have been removed
-
getPolygonInteriorSegments
public static List<PEdge> getPolygonInteriorSegments(List<PEdge> segments, processing.core.PShape shape) Retains line segments from a set of line segments that are wholly contained within a given shape.- Parameters:
segments
- a list of line segments to check for containment within the shapeshape
- the polygonal shape to check for interior segments- Returns:
- a list of interior segments contained within the shape
- Since:
- 1.4.0
-