Definition of curves in pyFormex.
This module defines classes and functions specialized for handling one-dimensional geometry in pyFormex. These may be straight lines, polylines, higher order curves and collections thereof. In general, the curves are 3D, but special cases may be created for handling plane curves.
Base class for curve type classes.
This is a virtual class intended to be subclassed. It defines the common definitions for all curve types. The subclasses should at least define the following:
sub_points(t,j)
Methods
Curve objects have the following methods:
Return the points at values t in part j
t can be an array of parameter values, j is a single segment number.
Return the points at values,parts given by zip(t,j)
t and j can both be arrays, but should have the same length.
Returns the points at parameter values t.
Parameter values are floating point values. Their integer part is interpreted as the curve segment number, and the decimal part goes from 0 to 1 over the segment.
Return a series of points on the PolyLine.
The parameter space of each segment is divided into ndiv parts. The coordinates of the points at these parameter values are returned as a Coords object. The extend parameter allows to extend the curve beyond the endpoints. The normal parameter space of each part is [0.0 .. 1.0]. The extend parameter will add a curve with parameter space [-extend[0] .. 0.0] for the first part, and a curve with parameter space [1.0 .. 1 + extend[0]] for the last part. The parameter step in the extensions will be adjusted slightly so that the specified extension is a multiple of the step size. If the curve is closed, the extend parameter is disregarded.
Return the total length of the curve.
This is only available for curves that implement the ‘lengths’ method.
Return a PolyLine approximation of the curve
If no ntot is given, the curve is approximated by ndiv straight segments over each part of the curve. If ntot is given, the curve is approximated by ntot straight segments over the total curve. This is based on a first approximation with ndiv segments over each part.
Convert a curve to a Formex.
This creates a polyline approximation as a plex-2 Formex. This is mainly used for drawing curves that do not implement their own drawing routines.
The method can be passed the same arguments as the approx method.
A class representing a series of straight line segments.
Methods
Initialize a PolyLine from a coordinate array.
coords is a (npts,3) shaped array of coordinates of the subsequent vertices of the polyline (or a compatible data object). If closed == True, the polyline is closed by connecting the last point to the first. This does not change the vertex data.
Methods
PolyLine objects have the following methods:
Convert the polyLine to a plex-2 Mesh.
This returned mesh is equivalent with the PolyLine, but does not guarantee the sequential order.
Return the vectors of each point to the next one.
The vectors are returned as a Coords object. If the curve is not closed, the number of vectors returned is one less than the number of points.
Returns unit vectors in the direction of the next point.
This directions are returned as a Coords object with the same number of elements as the point set.
If two subsequent points are identical, the first one gets the direction of the previous segment. If more than two subsequent points are equal, an invalid direction (NaN) will result.
If the curve is not closed, the last direction is set equal to the penultimate.
If return_doubles is True, the return value is a tuple of the direction and an index of the points that are identical with their follower.
Returns the average directions at points.
For each point the returned direction is the average of the direction from the preceding point to the current, and the direction from the current to the next point.
If the curve is open, the first and last direction are equal to the direction of the first, resp. last segment.
Where two subsequent points are identical, the average directions are set equal to those of the segment ending in the first and the segment starting from the last.
Returns the parameter values for relative curve lengths div.
div is a list of relative curve lengths (from 0.0 to 1.0). As a convenience, a single integer value may be specified, in which case the relative curve lengths are found by dividing the interval [0.0,1.0] in the specified number of subintervals.
The function returns a list with the parameter values for the points at the specified relative lengths.
Split the curve at point i.
Returns a list of open PolyLines: one, if the PolyLine is closed or i is one of the endpoints of an open PolyLine, two in other cases.
Return the parts of the polyline at one or both sides of a plane.
If side is ‘+’ or ‘-‘, return a list of PolyLines with the parts at the positive or negative side of the plane.
For any other value, returns a tuple of two lists of PolyLines, the first one being the parts at the positive side.
p is a point specified by 3 coordinates. n is the normal vector to a plane, specified by 3 components.
A Polygon is a closed PolyLine.
Methods
Polygon objects have the following methods:
A class representing a cubic Bezier spline curve.
Methods
Create a cubic spline curve through the given points.
coords: an (npoints,3) array with ordered points on the curve
deriv: an (npoints,3) or (2,3) array with the directions at all the points or at the two endpoints only. For points where the direction is left unspecified or where the specified direction contains a NaN value, the direction is calculated as the average direction of the two line segments ending in the point. This will also be used for points where the specified direction contains a value NaN. In the two endpoints of an open curve however, this average direction can not be calculated: the two control points in these parts are set coincident.
The curl parameter can be set to influence the curliness of the curve in between two subsequent points. A value curl=0.0 results in straight segments.
control: an (nparts,2,3) array of control points, two for each curve segemetn between two consecutive points. For a closed curve, nparts = npoints, while for an open curve nparts = npoints-1. If the control points are specified directly, they override the deriv and curl parameters.
closed: if True, the curve will be continued from the last point to the first to create a closed curve.
Methods
BezierSpline objects have the following methods:
A class representing a Quadratic Bezier spline curve.
Methods
Create a quadratic spline curve through the given points.
Methods
QuadBezierSpline objects have the following methods:
A class representing a cardinal spline.
Create a natural spline through the given points.
The Cardinal Spline with given tension is a Bezier Spline with curl :math: curl = ( 1 - tension) / 3 The separate class name is retained for compatibility and convenience. See CardinalSpline2 for a direct implementation (it misses the end intervals of the point set).
Methods
Create a natural spline through the given points.
Methods
CardinalSpline objects have the following methods:
A class representing a cardinal spline.
Methods
Create a natural spline through the given points.
This is a direct implementation of the Cardinal Spline. For open curves, it misses the interpolation in the two end intervals of the point set.
Methods
CardinalSpline2 objects have the following methods:
A class representing a natural spline.
Methods
Create a natural spline through the given points.
coords specifies the coordinates of a set of points. A natural spline is constructed through this points. endcond specifies the end conditions in the first, resp. last point. It can be ‘notaknot’ or ‘secder’. With ‘notaknot’, maximal continuity (up to the third derivative) is obtained between the first two splines. With ‘secder’, the spline ends with a zero second derivative. If closed is True, the spline is closed, and endcond is ignored.
Methods
NaturalSpline objects have the following methods:
A class representing a circular arc.
Methods
Create a circular arc.
The arc is specified by 3 non-colinear points.
Methods
Arc3 objects have the following methods:
A class representing a circular arc.
Methods
Create a circular arc.
The arc is specified by the center and begin and end-point.
Methods
Arc objects have the following methods:
A class representing a spiral curve.
Methods
Spiral objects have the following methods:
Functions defined in the module curve
- curve.vectorPairAngle(v1, v2)¶
- Return the angle between the vectors v1 and v2.
- curve.convertFormexToCurve(closed=False)¶
Convert a Formex to a Curve.
The following Formices can be converted to a Curve: - plex 2 : to PolyLine - plex 3 : to QuadBezierSpline - plex 4 : to BezierSpline