public class PGS_SegmentSet extends Object
Methods in this class output segments as collections of
PEdges
; such collections can be converted
into LINES PShapes with toPShape(Collection
.
Modifier and Type | Method and Description |
---|---|
static processing.core.PShape |
dissolve(Collection<PEdge> segments)
Dissolves the edges from a collection of
PEdges into a set of maximal-length LineStrings in which each unique segment
appears only once. |
static List<PEdge> |
filterAxisAligned(List<PEdge> segments,
double angleDelta)
Removes axis-aligned (horizontal and vertical) segments (within a given angle
tolerance) from a collection of segments.
|
static List<PEdge> |
filterByAverageLength(List<PEdge> segments,
double fraction)
Removes segments having a length either less than some fraction or more than
1/fraction of the mean segment length from a collection of
segments. |
static List<PEdge> |
filterByMinLength(List<PEdge> segments,
double minLength)
Removes segments having a length less than the given length from a collection
of segmensts.
|
static List<PEdge> |
fromPShape(processing.core.PShape shape)
Extracts a list of unique PEdge segments representing the given shape.
|
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.
|
static List<PEdge> |
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.
|
static List<PEdge> |
graphMatchedSegments(org.tinfour.common.IIncrementalTin triangulation)
Generates non-intersecting segments via a Perfect matching algorithm
applied to the given triangulation.
|
static List<PEdge> |
graphMatchedSegments(List<processing.core.PVector> points)
Generates non-intersecting segments via a Perfect matching algorithm
applied to a triangulation populated with the given points.
|
static List<PEdge> |
nodedSegments(double width,
double height,
int n,
long seed)
Generates N non-intersecting segments via intersection and noding.
|
static List<PEdge> |
parallelSegments(double centerX,
double centerY,
double length,
double d,
double angle,
int n)
Generates a set of N straight parallel segments, centered on a given point.
|
static List<PEdge> |
stochasticSegments(double width,
double height,
int n)
Generates a set of N random non-intersecting line segments via brute-forcing.
|
static List<PEdge> |
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.
|
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.
|
static List<PEdge> |
stretch(List<PEdge> segments,
double factor)
Stretches each PEdge segment in the provided list by a specified factor.
|
static processing.core.PShape |
toPShape(Collection<PEdge> segments)
Converts a collection of
PEdges into a
LINES shape. |
static processing.core.PShape |
toPShape(Collection<PEdge> segments,
Integer strokeColor,
Integer strokeCap,
Integer strokeWeight)
Converts a collection of
PEdges into a
LINES shape, having the (optional) styling provided. |
public static List<PEdge> nodedSegments(double width, double height, int n, long seed)
The segments are generated within a bounding box anchored at (0, 0) having the width and height specified.
Algorithm:
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
generatorpublic static List<PEdge> graphMatchedSegments(double width, double height, int n, long seed)
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.
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
generatorpublic static List<PEdge> graphMatchedSegments(List<processing.core.PVector> 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.
points
- point set from which to compute segmentspublic static List<PEdge> graphMatchedSegments(org.tinfour.common.IIncrementalTin 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.
points
- point set from which to compute segmentspublic static List<PEdge> stochasticSegments(double width, double height, int n)
The segments are generated within a bounding box anchored at (0, 0) having the width and height specified.
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 generatestochasticSegments(double, double, int, double, double, long)
public static List<PEdge> stochasticSegments(double width, double height, int n, double length)
The segments are generated within a bounding box anchored at (0, 0) having the width and height specified.
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)stochasticSegments(double, double, int, double, double, long)
public static List<PEdge> stochasticSegments(double width, double height, int n, double minLength, double maxLength, long seed)
The segments are generated within a bounding box anchored at (0, 0) having the width and height specified.
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
generatorpublic static List<PEdge> parallelSegments(double centerX, double centerY, double length, double d, double angle, int n)
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 segmentsrotation
- 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 pointpublic static processing.core.PShape toPShape(Collection<PEdge> segments)
PEdges
into a
LINES
shape.segments
- collection of segmentsLINES
shape representing segmentspublic static processing.core.PShape toPShape(Collection<PEdge> segments, @Nullable Integer strokeColor, @Nullable Integer strokeCap, @Nullable Integer strokeWeight)
PEdges
into a
LINES
shape, having the (optional) styling provided.segments
- collection of PEdge segmentsstrokeColor
- nullable/optional (default = Colors.PINK
)strokeCap
- nullable/optional (default = ROUND
)strokeWeight
- nullable/optional (default = 2
)public static processing.core.PShape dissolve(Collection<PEdge> segments)
PEdges
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).
segments
- Collection of PEdge objects to dissolve into maximal-length
LineStringspublic static List<PEdge> fromPShape(processing.core.PShape shape)
This method iterates through all the child shapes of the input shape, creating PEdge segments for each pair of consecutive vertices.
shape
- The shape from which to extract the edges. Supports holes and
GROUP shapes.public static List<PEdge> stretch(List<PEdge> segments, double factor)
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.public static List<PEdge> filterByMinLength(List<PEdge> segments, double minLength)
segments
- list of segments to filterminLength
- the minimum segment length to keeppublic static List<PEdge> filterByAverageLength(List<PEdge> segments, double fraction)
1/fraction
of the mean segment length from a collection of
segments.
This method can be used to homogenise a segment set.
segments
- list of segments to filterfraction
- fraction of mean length to keep segmentspublic static List<PEdge> filterAxisAligned(List<PEdge> segments, double angleDelta)
segments
- list of segments to filterangleDelta
- angle tolerance, in radianspublic static List<PEdge> getPolygonInteriorSegments(List<PEdge> segments, processing.core.PShape shape)
segments
- a list of line segments to check for containment within the
shapeshape
- the polygonal shape to check for interior segmentsCopyright © 2023. All rights reserved.