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.
Classes defined in module curve
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
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.
Return the directions at values t in part j
t can be an array of parameter values, j is a single segment number.
Return the directions at values,parts given by zip(t,j)
t and j can both be arrays, but should have the same length.
Return 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 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 Curve.
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.
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.
The control parameter has the same meaning as coords and is added for symmetry with other Curve classes. If specified, it will override the coords argument.
Methods
Return the polyline as a Formex.
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 points at values t in part j
Return the points at value,part pairs (t,j)
Return the unit direction vectors at values t in part j.
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.
Return the length of the parts of the curve.
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.
Return the same curve with the parameter direction reversed.
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.
Find the distances of points p, perpendicular to the vectors n.
p is a (np,3) shaped array of points. n is a (np,3) shaped array of vectors.
The return value is a tuple OKpid,OKdist,OKpoints where: - OKpid is an array with the point numbers having a distance; - OKdist is an array with the distances for these points; - OKpoints is an array with the footpoints for these points and is only returned if return_points = True.
Find the distances of the PolyLine PL.
PL is first discretised by calculating a set of points p and direction vectors n at equal distance of approximately ds along PL. The distance of PL is then calculated as the distances of the set (p,n).
If return_points = True, two extra values are returned: an array with the points p and an array with the footpoints matching p.
A Polygon is a closed PolyLine.
Methods
A class representing a cubic Bezier spline curve.
A cubic Bezier spline is a continuous curve consisting of nparts successive parts and where each part is a cubic Bezier curve described by four control points (two end points which are on the curve, and two intermediate control points which are off the curve). Since the end point of one part is the begin point of the next part, a BezierSpline is described by ncontrol=3*nparts+1 control points if the curve is open, or ncontrol=3*nparts if the curve is closed.
The constructor provides different ways to initialize the full set of control points. In many cases the off-curve control points can be generated automatically.
Parameters : | coords : array_like (npoints,3)
deriv : array_like (npoints,3) or (2,3)
curl : float
control : array(nparts,2,3) or array(ncontrol,3)
closed : boolean
|
---|
Methods
Return the points on the curve.
This returns a Coords object of shape [nparts+1]. For a closed curve, the last point will be equal to the first.
Return the points off the curve (the control points)
This returns a Coords object of shape [nparts,ndegree-1], or an empty Coords if degree <= 1.
Returns the points defining part j of the curve.
Return the points at values t in part j.
Return the unit direction vectors at values t in part j.
Return the arc length integrand at value t in part j.
Return the length of the parts of the curve.
Return a PolyLine approximation of the curve.
tol is a tolerance value for the flatness of the curve. The flatness of each part is calculated as the maximum orthogonal distance of its intermediate control points from the straight segment through its end points.
Parts for which the distance is larger than tol are subdivided using de Casteljau’s algorithm. The subdivision stops if all parts are sufficiently flat. The return value is a PolyLine connecting the end points of all parts.
Extend the curve beyond its endpoints.
This function will add a Bezier curve before the first part and/or after the last part by applying de Casteljau’s algorithm on this part.
Return the same curve with the parameter direction reversed.
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
A class representing a cardinal spline.
Methods
A class representing a natural spline.
Methods
A class representing a circular arc.
Methods
A class representing a circular arc.
Methods
A class representing a spiral curve.
Methods
A class representing a Quadratic Bezier spline curve.
This is a (deprecated) convenience class for BezierSpline with fixed value of degree=2. The constructor takes the same parameters as BezierSpline, except for degree, which is fixed to a value 2.
Methods
Functions defined in module curve
Create a spline approximation of a circle.
The returned circle lies in the x,y plane, has its center at (0,0,0) and has a radius 1.
In the current implementation it is approximated by a bezier spline with curl 0.375058 through 8 points.
Return the angle between the vectors v1 and v2.
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