public class Curve extends java.lang.Object implements RShape
| Modifier and Type | Field and Description |
|---|---|
protected processing.core.PApplet |
parent
The PApplet object for drawing thinks.
|
| Constructor and Description |
|---|
Curve(processing.core.PApplet parent)
Builds an empty shape.
|
Curve(processing.core.PApplet parent,
processing.core.PVector[] coordinates)
Builds an curve that follows the given coordinates.
|
| Modifier and Type | Method and Description |
|---|---|
float |
arcLengthToTPlusI(float arclength)
Maps a given arc length factor [0, getArcLength()] to a tplusi. tplusi is
a parameter that describes the position on the curve and the curve
segment. i is the index of the coordinate, t is the parameter that
describes how near the returned normal is to that coordinate.
|
void |
computeMinMax()
Forces to calculate the bounds of this shape and store them.
|
Curve |
copy()
Builds and returns a true copy of this shape.
|
processing.core.PVector |
curvePoint(float tplusi)
Calculates a point on the curve.
|
float |
curveTangent(float tplusi)
Calculates the tangent in a point of the curve.
|
Curve |
draw()
Draws the shape-
|
processing.core.PVector |
get(int i)
Returns the coordinate with index i.
|
java.lang.Float |
getArcLength()
Returns the true length of this curve.
|
Rect |
getBoundingBox()
Returns the bounding box of this shape (will mark the bounds of the
shape).
|
processing.core.PVector |
getCenter()
Returns the center coordinate of this shape.
|
processing.core.PVector[] |
getCoordinates()
Returns all coordinates that defines this shape.
|
processing.core.PVector |
getEnd()
Returns the end coordinate for this shape.
|
float |
getLength()
Returns the length (distance from start to end) of this curve.
|
LineSegments |
getLineSegments()
Converts this shape to a LineSegments.
|
float[] |
getNormal(float tplusi)
Returns the normal information for a given location on the curve.
|
java.lang.Float |
getRotation()
Returns the angle of shape.
|
processing.core.PVector |
getStart()
Returns the start coordinate for this shape.
|
java.lang.Float |
getX()
Returns the x-position of the start coordinate for this shape.
|
java.lang.Float |
getY()
Returns the y-position of the start coordinate for this shape.
|
boolean |
hasIntersection(Line curveSeg,
Line other)
Tests if a curve segment has a intersection with the given line.
|
boolean |
hasIntersection(Line curveSeg,
Line other,
boolean ignoreStartEnd)
Tests if a curve segment has a intersection with the given line.
|
processing.core.PVector |
intersection(Line curveSeg,
Line other)
Returns the location of an intersection a curve segment with a line if
they have an intersection.
|
processing.core.PVector |
intersection(Line curveSeg,
Line other,
boolean ignoreStartEnd)
Returns the location of an intersection a curve segment with a line if
they have an intersection.
|
void |
removeIntersectingLines(java.util.ArrayList<Line> toRemove)
Removes all lines from the given set of lines that intersect with this
shape.
|
void |
removeIntersectingLines(java.util.ArrayList<Line> toRemove,
boolean ignoreStartEnd)
Removes all lines from the given set of lines that intersect with this
shape.
|
Curve |
rotate(float angle)
Turns the shape through the given angle.
|
Curve |
rotate(processing.core.PVector rotationCenter,
float angle)
Turns the shape through the given angle.
|
Curve |
scale(float scale)
Scale the shape by the given scaling factor.
|
Curve |
scale(processing.core.PVector scaleCenter,
float scale)
Scale the shape by the given scaling factor.
|
Curve |
scale(processing.core.PVector scaleCenter,
float scaleX,
float scaleY)
Scales the shape by the given scaling factors.
|
Curve |
setControlPoint(int which,
processing.core.PVector p)
Sets one of the control points, which is not seen, but used to describe
the start or end of the curve.
|
Curve |
setLength(float newLength)
Sets the length (not arclength) of this curve.
|
Curve |
setLength(processing.core.PVector center,
float newLength)
Sets the length (not arclength) of this curve.
|
Curve |
setLocation(float x,
float y)
Translates the shape to the given location.
|
Curve |
setRotation(float angle)
Rotates the shape to the given angle (past rotations will be overridden).
|
Curve |
setRotation(processing.core.PVector rotationCenter,
float angle)
Rotates the shape to the given angle (past rotations will be overridden).
|
Curve |
setX(float x)
Translates the shape to the given x-location.
|
Curve |
setY(float y)
Translates the shape to the given y-location.
|
int |
size()
Returns the number of coordinates for this shape.
|
LineSegments |
toLineSegments()
Converts this shape to a LineSegments.
|
LineSegments |
toLineSegments(float detailScale)
Converts this shape to a LineSegments and optimizes the coordinates.
|
LineSegments |
toLineSegments(int details)
Converts this shape to a LineSegments and optimizes the coordinates.
|
Curve |
toSmoothedCurve()
Smoothens the curve: All coordinates of the returned curve will have a
equal distance to each other.
|
Curve |
toSmoothedCurve(float detailScale)
Smoothens the curve: All coordinates of the returned curve will have a
equal distance to each other.
|
Curve |
toSmoothedCurve(int details)
Smoothens the curve: All coordinates of the returned curve will have a
equal distance to each other.
|
Curve |
translate(float x,
float y)
Translates the coordinates by the given parameters x, y ( "moves
the shape by x, y").
|
public Curve(processing.core.PApplet parent)
parent - The PApplet object.public Curve(processing.core.PApplet parent,
processing.core.PVector[] coordinates)
parent - The PApplet object.coordinates - The coordinates of this curve.public int size()
RShape
for (int i = 0; i < myShape.size(); i++) {
PVector p = myShape.get(i);
}
public processing.core.PVector get(int i)
RShape
for (int i = 0; i < myShape.size(); i++) {
PVector p = myShape.get(i);
}
public processing.core.PVector getStart()
RShapepublic processing.core.PVector getEnd()
public float getLength()
public Rect getBoundingBox()
RShapegetBoundingBox in interface RShapepublic processing.core.PVector getCenter()
RShapepublic java.lang.Float getX()
RShapepublic java.lang.Float getY()
RShapepublic processing.core.PVector[] getCoordinates()
RShapegetCoordinates in interface RShapepublic java.lang.Float getRotation()
RShapegetRotation in interface RShapepublic Curve copy()
RShapepublic java.lang.Float getArcLength()
public Curve setControlPoint(int which, processing.core.PVector p)
which - -1 for first control point (Control point which is needed to
draw a curve between coordinates[0] and coordinates[1]) or 1
for last control point (Control point which is needed to draw
a curve between coordinates[last-1] and coordinates[last]).p - The control point.public Curve setRotation(float angle)
RShapesetRotation in interface RShapeangle - The target rotation angle.public Curve setRotation(processing.core.PVector rotationCenter, float angle)
RShapesetRotation in interface RShaperotationCenter - The rotation center.angle - The target rotation angle.public Curve setX(float x)
RShapepublic Curve setY(float y)
RShapepublic Curve setLocation(float x, float y)
RShapesetLocation in interface RShapex - The new x-position of this shape.y - The new y-position of this shape.public Curve setLength(float newLength)
newLength - The new length of the line (> 0).public Curve setLength(processing.core.PVector center, float newLength)
center - The control point for the scaling.newLength - The new length of the line (> 0).public processing.core.PVector intersection(Line curveSeg, Line other)
curveSeg - A line that represents a curve segment (line between two
points of the curve).other - One line.public processing.core.PVector intersection(Line curveSeg, Line other, boolean ignoreStartEnd)
curveSeg - A line that represents a curve segment (line between two
points of the curve).other - One line.ignoreStartEnd - If true, intersections that happen directly at the start or
the end of the given line will be ignored (i.e. if the
intersection happens at start / end then still null will be
returned). Otherwise all found intersections will be returned.public boolean hasIntersection(Line curveSeg, Line other)
curveSeg - A line that represents a curve segment (line between two
points of the curve).other - One line.public boolean hasIntersection(Line curveSeg, Line other, boolean ignoreStartEnd)
curveSeg - A line that represents a curve segment (line between two
points of the curve).other - One line.ignoreStartEnd - If true, intersections that happen directly at the start or
the end of the given line will be ignored (i.e. if the
intersection happens at start / end then still null will be
returned). Otherwise all found intersections will be returned.public void removeIntersectingLines(java.util.ArrayList<Line> toRemove)
toRemove - A set of lines.public void removeIntersectingLines(java.util.ArrayList<Line> toRemove, boolean ignoreStartEnd)
toRemove - A set of lines.ignoreStartEnd - If true, intersections that happen directly at the start or
the end of any line will be ignored (i.e. if the intersection
happens at start / end then the line will not be removed).public float[] getNormal(float tplusi)
tplusi - A parameter that describes the position on the curve. i is the
index of the coordinate, t is the parameter that describes how
near the returned normal is to that coordinate. If t is 0 the
normal will be directly at the coordinate, if t is 1 the
normal will be directly at the following coordinate. For t=0.5
the normal will be in the middle of the coordinate and the
following coordinate. t and i should be summed for this
parameter, e.g. for the normal which is in the middle (t=0.5)
of coordinate[1] (i=1) and coordinate[2] tplusi should be
1+0.5=0.5public float curveTangent(float tplusi)
tplusi - A parameter that describes the position on the curve and the
curve segment. i is the index of the coordinate, t is the
parameter that describes how near the returned normal is to
that coordinate. If t is 0 the normal will be directly at the
coordinate, if t is 1 the normal will be directly at the
following coordinate. For t=0.5 the normal will be in the
middle of the coordinate and the following coordinate. t and i
should be summed for this parameter, e.g. for the normal which
is in the middle (t=0.5) of coordinate[1] (i=1) and
coordinate[2] tplusi should be 1+0.5=0.5.public processing.core.PVector curvePoint(float tplusi)
tplusi - A parameter that describes the position on the curve and the
curve segment. i is the index of the coordinate, t is the
parameter that describes how near the returned normal is to
that coordinate. If t is 0 the normal will be directly at the
coordinate, if t is 1 the normal will be directly at the
following coordinate. For t=0.5 the normal will be in the
middle of the coordinate and the following coordinate. t and i
should be summed for this parameter, e.g. for the normal which
is in the middle (t=0.5) of coordinate[1] (i=1) and
coordinate[2] tplusi should be 1+0.5=0.5public float arcLengthToTPlusI(float arclength)
arclength - The arclength [0, getArcLength()].public void computeMinMax()
public Curve translate(float x, float y)
RShapepublic Curve rotate(float angle)
RShapepublic Curve rotate(processing.core.PVector rotationCenter, float angle)
RShapepublic Curve scale(float scale)
RShapepublic Curve scale(processing.core.PVector scaleCenter, float scale)
RShapepublic Curve scale(processing.core.PVector scaleCenter, float scaleX, float scaleY)
scaleCenter - The scaling center.scaleX - The horizontal scaling.scaleY - The vertical scaling.public Curve toSmoothedCurve()
public Curve toSmoothedCurve(int details)
details - The number of coordinates for the returned curve.public Curve toSmoothedCurve(float detailScale)
detailScale - A factor that describes the number of coordinates for the
returned smoothend curve. For detailScale < 1 the new curve
will have less coordinates than the input, for detailScale > 1
the curve will have more coordinates. detailScale
should be greater than zero.public LineSegments getLineSegments()
public LineSegments toLineSegments()
public LineSegments toLineSegments(float detailScale)
detailScale - A factor that describes the number of coordinates for the
returned LineSegments. For detailScale < 1 the new
LineSegments will have less coordinates than the input curve,
for detailScale > 1 the LineSegments will have more
coordinates. detailScale should be greater than zero.public LineSegments toLineSegments(int details)
details - The number of coordinates for the returned LineSegments (>=
2).