scallop dome pyformex logo

Previous topic

36. ccxinp

Next topic

38. datareader — Numerical data reader

[FSF Associate Member]

Valid XHTML 1.0 Transitional

37. curve — 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

class curve.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 attributes and methods or override them if the defaults are not suitable.

Attributes:

  • coords: coordinates of points defining the curve
  • parts: number of parts (e.g. straight segments of a polyline)
  • closed: is the curve closed or not
  • range: [min,max], range of the parameter: default 0..1

Methods:

  • sub_points(t,j): returns points at parameter value t,j
  • sub_directions(t,j): returns direction at parameter value t,j
  • pointsOn(): the defining points placed on the curve
  • pointsOff(): the defining points placeded off the curve (control points)
  • parts(j,k):
  • approx(ndiv,ntot):

Furthermore it may define, for efficiency reasons, the following methods:

  • sub_points_2
  • sub_directions_2
endPoints()

Return start and end points of the curve.

Returns a Coords with two points, or None if the curve is closed.

sub_points(t, j)

Return the points at values t in part j

t can be an array of parameter values, j is a single segment number.

sub_points_2(t, j)

Return the points at values,parts given by zip(t,j)

t and j can both be arrays, but should have the same length.

sub_directions(t, j)

Return the directions at values t in part j

t can be an array of parameter values, j is a single segment number.

sub_directions_2(t, j)

Return the directions at values,parts given by zip(t,j)

t and j can both be arrays, but should have the same length.

localParam(t)

Split global parameter value in part number and local parameter

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.

Returns a tuple of arrays i,t, where i are the (integer) part numbers and t the local parameter values (between 0 and 1).

pointsAt(t, normalized=False, return_position=False)

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.

Returns a Coords with the coordinates of the points.

If normalized is True, the parameter values are give in a normalized space where 0 is the start of the curve and 1 is the end.

If return_position is True, also returns the part numbers on which the point are lying and the local parameter values.

directionsAt(t)

Return the directions 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.

subPoints(div=10, extend=[0.0, 0.0])

Return a sequence of points on the Curve.

  • div: int or a list of floats (usually in the range [0.,1.]) If div is an integer, a list of floats is constructed by dividing the range [0.,1.] into div equal parts. The list of floats then specifies a set of parameter values for which points at in each part are returned. The points are returned in a single Coords in order of the parts.

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.

split(split=None)

Split a curve into a list of partial curves

split is a list of integer values specifying the node numbers where the curve is to be split. As a convenience, a single int may be given if the curve is to be split at a single node, or None to split all all nodes.

Returns a list of open curves of the same type as the original.

length()

Return the total length of the curve.

This is only available for curves that implement the ‘lengths’ method.

approx(ndiv=None, ntot=None)

Return a PolyLine approximation of the curve

Parameters:

  • ndiv: int: number of straight segments to use over each part of the curve. This is only used if
  • ntot: int: number of straight segments to use over the total length of the curve.

Returns a PolyLine approximation for the curve. C.approx(ndiv=n) returns an approximation with ndiv segments over each part of the curve. This may results in segments with very different lengths. C.approx(ntot=n) returns an approximation with ntot segments over the total length of the curve. This produces more equally sized segments, but the internal end points of the curve parts may not be on the approximating Polyline.

frenet(ndiv=None, ntot=None, upvector=None, avgdir=True, compensate=False)

Return points and Frenet frame along the curve.

A PolyLine approximation for the curve is constructed, using the Curve.approx() method with the arguments ndiv and ntot. Then Frenet frames are constructed with PolyLine.movingFrenet() using the remaining arguments. The resulting PolyLine points and Frenet frames are returned.

Parameters:

  • upvector: (3,) vector: a vector normal to the (tangent,normal) plane at the first point of the curve. It defines the binormal at the first point. If not specified it is set to the shorted distance through the set of 10 first points.

  • avgdir: bool or array. If True (default), the tangential vector is set to the average direction of the two segments ending at a node. If False, the tangent vectors will be those of the line segment starting at the points. The tangential vector can also be set by the user by specifying an array with the matching number of vectors.

  • compensate: bool: If True, adds a compensation algorithm if the curve is closed. For a closed curve the moving Frenet algorithm can be continued back to the first point. If the resulting binormial does not coincide with the starting one, some torsion is added to the end portions of the curve to make the two binormals coincide.

    This feature is off by default because it is currently experimental and is likely to change in future. It may also form the base for setting the starting as well as the ending binormal.

Returns:

  • X: a Coords with npts points on the curve
  • T: normalized tangent vector to the curve at npts points
  • N: normalized normal vector to the curve at npts points
  • B: normalized binormal vector to the curve at npts points
approximate(nseg, equidistant=True, npre=100)

Approximate a Curve with a PolyLine of n segments

Parameters:

  • nseg: number of straight segments of the resulting PolyLine
  • equidistant: if True (default) the points are spaced almost equidistantly over the curve. If False, the points are spread equally over the parameter space.
  • npre: only used when equidistant is True: number of segments per part of the curve used in the pre-approximation. This pre- approximation is currently required to compute curve lengths.

Note

This is an alternative for Curve.approx, and may replace it in future.

toFormex(*args, **kargs)

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.

setProp(p=None)

Create or destroy the property array for the Formex.

A property array is a rank-1 integer array with dimension equal to the number of elements in the Formex (first dimension of data). You can specify a single value or a list/array of integer values. If the number of passed values is less than the number of elements, they wil be repeated. If you give more, they will be ignored.

If a value None is given, the properties are removed from the Formex.

addNoise(*args, **kargs)

Apply ‘addNoise’ transformation to the Geometry object.

See coords.Coords.addNoise() for details.

affine(*args, **kargs)

Apply ‘affine’ transformation to the Geometry object.

See coords.Coords.affine() for details.

align(*args, **kargs)

Apply ‘align’ transformation to the Geometry object.

See coords.Coords.align() for details.

bump(*args, **kargs)

Apply ‘bump’ transformation to the Geometry object.

See coords.Coords.bump() for details.

bump1(*args, **kargs)

Apply ‘bump1’ transformation to the Geometry object.

See coords.Coords.bump1() for details.

bump2(*args, **kargs)

Apply ‘bump2’ transformation to the Geometry object.

See coords.Coords.bump2() for details.

centered(*args, **kargs)

Apply ‘centered’ transformation to the Geometry object.

See coords.Coords.centered() for details.

cylindrical(*args, **kargs)

Apply ‘cylindrical’ transformation to the Geometry object.

See coords.Coords.cylindrical() for details.

egg(*args, **kargs)

Apply ‘egg’ transformation to the Geometry object.

See coords.Coords.egg() for details.

flare(*args, **kargs)

Apply ‘flare’ transformation to the Geometry object.

See coords.Coords.flare() for details.

hyperCylindrical(*args, **kargs)

Apply ‘hyperCylindrical’ transformation to the Geometry object.

See coords.Coords.hyperCylindrical() for details.

isopar(*args, **kargs)

Apply ‘isopar’ transformation to the Geometry object.

See coords.Coords.isopar() for details.

map(*args, **kargs)

Apply ‘map’ transformation to the Geometry object.

See coords.Coords.map() for details.

map1(*args, **kargs)

Apply ‘map1’ transformation to the Geometry object.

See coords.Coords.map1() for details.

mapd(*args, **kargs)

Apply ‘mapd’ transformation to the Geometry object.

See coords.Coords.mapd() for details.

position(*args, **kargs)

Apply ‘position’ transformation to the Geometry object.

See coords.Coords.position() for details.

projectOnCylinder(*args, **kargs)

Apply ‘projectOnCylinder’ transformation to the Geometry object.

See coords.Coords.projectOnCylinder() for details.

projectOnPlane(*args, **kargs)

Apply ‘projectOnPlane’ transformation to the Geometry object.

See coords.Coords.projectOnPlane() for details.

projectOnSphere(*args, **kargs)

Apply ‘projectOnSphere’ transformation to the Geometry object.

See coords.Coords.projectOnSphere() for details.

reflect(*args, **kargs)

Apply ‘reflect’ transformation to the Geometry object.

See coords.Coords.reflect() for details.

replace(*args, **kargs)

Apply ‘replace’ transformation to the Geometry object.

See coords.Coords.replace() for details.

rollAxes(*args, **kargs)

Apply ‘rollAxes’ transformation to the Geometry object.

See coords.Coords.rollAxes() for details.

rot(*args, **kargs)

Apply ‘rotate’ transformation to the Geometry object.

See coords.Coords.rotate() for details.

rotate(*args, **kargs)

Apply ‘rotate’ transformation to the Geometry object.

See coords.Coords.rotate() for details.

scale(*args, **kargs)

Apply ‘scale’ transformation to the Geometry object.

See coords.Coords.scale() for details.

shear(*args, **kargs)

Apply ‘shear’ transformation to the Geometry object.

See coords.Coords.shear() for details.

spherical(*args, **kargs)

Apply ‘spherical’ transformation to the Geometry object.

See coords.Coords.spherical() for details.

superSpherical(*args, **kargs)

Apply ‘superSpherical’ transformation to the Geometry object.

See coords.Coords.superSpherical() for details.

swapAxes(*args, **kargs)

Apply ‘swapAxes’ transformation to the Geometry object.

See coords.Coords.swapAxes() for details.

toCylindrical(*args, **kargs)

Apply ‘toCylindrical’ transformation to the Geometry object.

See coords.Coords.toCylindrical() for details.

toSpherical(*args, **kargs)

Apply ‘toSpherical’ transformation to the Geometry object.

See coords.Coords.toSpherical() for details.

transformCS(*args, **kargs)

Apply ‘transformCS’ transformation to the Geometry object.

See coords.Coords.transformCS() for details.

translate(*args, **kargs)

Apply ‘translate’ transformation to the Geometry object.

See coords.Coords.translate() for details.

trl(*args, **kargs)

Apply ‘translate’ transformation to the Geometry object.

See coords.Coords.translate() for details.

nelems()

Return the number of elements in the Geometry.

This method should be re-implemented by the derived classes. For the (empty) Geometry class it always returns 0.

toProp(prop)

Converts the argument into a legal set of properties for the object.

The conversion involves resizing the argument to a 1D array of length self.nelems(), and converting the data type to integer.

getCoords()

Get the coords data.

Returns the full array of coordinates stored in the Geometry object. Note that subclasses may store more points in this array than are used to define the geometry.

level()

Return the dimensionality of the Geometry, or -1 if unknown

copy()

Return a deep copy of the Geometry object.

The returned object is an exact copy of the input, but has all of its data independent of the former.

splitProp(prop=None)

Partition a Geometry (Formex/Mesh) according to the values in prop.

Parameters:

  • prop: an int array with length self.nelems(), or None. If None, the prop attribute of the Geometry is used.

Returns a list of Geometry objects of the same type as the input. Each object contains all the elements having the same value of prop. The number of objects in the list is equal to the number of unique values in prop. The list is sorted in ascending order of their prop value.

It prop is None and the the object has no prop attribute, an empty list is returned.

resized(size=1.0, tol=1e-05)

Return a copy of the Geometry scaled to the given size.

size can be a single value or a list of three values for the three coordinate directions. If it is a single value, all directions are scaled to the same size. Directions for which the geometry has a size smaller than tol times the maximum size are not rescaled.

write(fil, sep=' ', mode='w')

Write a Geometry to a .pgf file.

If fil is a string, a file with that name is opened. Else fil should be an open file. The Geometry is then written to that file in a native format, using sep as separator between the coordinates. If fil is a string, the file is closed prior to returning.

class curve.PolyLine(coords=[], control=None, closed=False)

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.

close()

Close a PolyLine.

If the PolyLine is already closed, it is returned unchanged. Else it is closed by adding a segment from the last to the first point (even if these are coincident).

Warning

This method changes the PolyLine inplace.

open()

Open a closed PolyLine.

If the PolyLine is closed, it is opened by removing the last segment. Else, it is returned unchanged.

Warning

This method changes the PolyLine inplace.

Use split() if you want to open the PolyLine without losing a segment.

toFormex()

Return the polyline as a Formex.

toMesh()

Convert the polyLine to a plex-2 Mesh.

The returned Mesh is equivalent with the PolyLine.

sub_points(t, j)

Return the points at values t in part j

sub_points_2(t, j)

Return the points at value,part pairs (t,j)

sub_directions(t, j)

Return the unit direction vectors at values t in part j.

vectors()

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.

directions(return_doubles=False)

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.

avgDirections(return_doubles=False)

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.

approximate(nseg, equidistant=True, npre=100)

Approximate a PolyLine with a PolyLine of n segments

Parameters:

  • nseg: number of straight segments of the resulting PolyLine
  • equidistant: if True (default) the points are spaced almost equidistantly over the curve. If False, the points are spread equally over the parameter space.
  • npre: only used when equidistant is True: number of segments per part of the curve used in the pre-approximation. This pre- approximation is currently required to compute curve lengths.

Note

This is an alternative for Curve.approx, and may replace it in future.

roll(n)

Roll the points of a closed PolyLine.

lengths()

Return the length of the parts of the curve.

atLength(div)

Returns the parameter values at given relative curve length.

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.

reverse()

Return the same curve with the parameter direction reversed.

parts(j, k)

Return a PolyLine containing only segments j to k (k not included).

The resulting PolyLine is always open.

cutWithPlane(p, n, side='')

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.

append(PL, fuse=True, **kargs)

Append another PolyLine to this one.

Returns the concatenation of two open PolyLines. Closed PolyLines cannot be concatenated.

insertPointsAt(t, normalized=False, return_indices=False)

Insert new 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.

Returns a PolyLine with the new points inserted. Note that the parameter values of the points will have changed. If return_indices is True, also returns the indices of the inserted points in the new PolyLine.

splitAt(t, normalized=False)

Split a PolyLine at parametric 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.

Returns a list of open Polylines.

endPoints()

Return start and end points of the curve.

Returns a Coords with two points, or None if the curve is closed.

sub_directions_2(t, j)

Return the directions at values,parts given by zip(t,j)

t and j can both be arrays, but should have the same length.

localParam(t)

Split global parameter value in part number and local parameter

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.

Returns a tuple of arrays i,t, where i are the (integer) part numbers and t the local parameter values (between 0 and 1).

addNoise(*args, **kargs)

Apply ‘addNoise’ transformation to the Geometry object.

See coords.Coords.addNoise() for details.

affine(*args, **kargs)

Apply ‘affine’ transformation to the Geometry object.

See coords.Coords.affine() for details.

align(*args, **kargs)

Apply ‘align’ transformation to the Geometry object.

See coords.Coords.align() for details.

bump(*args, **kargs)

Apply ‘bump’ transformation to the Geometry object.

See coords.Coords.bump() for details.

bump1(*args, **kargs)

Apply ‘bump1’ transformation to the Geometry object.

See coords.Coords.bump1() for details.

bump2(*args, **kargs)

Apply ‘bump2’ transformation to the Geometry object.

See coords.Coords.bump2() for details.

centered(*args, **kargs)

Apply ‘centered’ transformation to the Geometry object.

See coords.Coords.centered() for details.

cylindrical(*args, **kargs)

Apply ‘cylindrical’ transformation to the Geometry object.

See coords.Coords.cylindrical() for details.

egg(*args, **kargs)

Apply ‘egg’ transformation to the Geometry object.

See coords.Coords.egg() for details.

flare(*args, **kargs)

Apply ‘flare’ transformation to the Geometry object.

See coords.Coords.flare() for details.

hyperCylindrical(*args, **kargs)

Apply ‘hyperCylindrical’ transformation to the Geometry object.

See coords.Coords.hyperCylindrical() for details.

isopar(*args, **kargs)

Apply ‘isopar’ transformation to the Geometry object.

See coords.Coords.isopar() for details.

map(*args, **kargs)

Apply ‘map’ transformation to the Geometry object.

See coords.Coords.map() for details.

map1(*args, **kargs)

Apply ‘map1’ transformation to the Geometry object.

See coords.Coords.map1() for details.

mapd(*args, **kargs)

Apply ‘mapd’ transformation to the Geometry object.

See coords.Coords.mapd() for details.

position(*args, **kargs)

Apply ‘position’ transformation to the Geometry object.

See coords.Coords.position() for details.

projectOnCylinder(*args, **kargs)

Apply ‘projectOnCylinder’ transformation to the Geometry object.

See coords.Coords.projectOnCylinder() for details.

projectOnPlane(*args, **kargs)

Apply ‘projectOnPlane’ transformation to the Geometry object.

See coords.Coords.projectOnPlane() for details.

projectOnSphere(*args, **kargs)

Apply ‘projectOnSphere’ transformation to the Geometry object.

See coords.Coords.projectOnSphere() for details.

reflect(*args, **kargs)

Apply ‘reflect’ transformation to the Geometry object.

See coords.Coords.reflect() for details.

replace(*args, **kargs)

Apply ‘replace’ transformation to the Geometry object.

See coords.Coords.replace() for details.

rollAxes(*args, **kargs)

Apply ‘rollAxes’ transformation to the Geometry object.

See coords.Coords.rollAxes() for details.

rot(*args, **kargs)

Apply ‘rotate’ transformation to the Geometry object.

See coords.Coords.rotate() for details.

rotate(*args, **kargs)

Apply ‘rotate’ transformation to the Geometry object.

See coords.Coords.rotate() for details.

scale(*args, **kargs)

Apply ‘scale’ transformation to the Geometry object.

See coords.Coords.scale() for details.

shear(*args, **kargs)

Apply ‘shear’ transformation to the Geometry object.

See coords.Coords.shear() for details.

spherical(*args, **kargs)

Apply ‘spherical’ transformation to the Geometry object.

See coords.Coords.spherical() for details.

superSpherical(*args, **kargs)

Apply ‘superSpherical’ transformation to the Geometry object.

See coords.Coords.superSpherical() for details.

swapAxes(*args, **kargs)

Apply ‘swapAxes’ transformation to the Geometry object.

See coords.Coords.swapAxes() for details.

toCylindrical(*args, **kargs)

Apply ‘toCylindrical’ transformation to the Geometry object.

See coords.Coords.toCylindrical() for details.

toSpherical(*args, **kargs)

Apply ‘toSpherical’ transformation to the Geometry object.

See coords.Coords.toSpherical() for details.

transformCS(*args, **kargs)

Apply ‘transformCS’ transformation to the Geometry object.

See coords.Coords.transformCS() for details.

translate(*args, **kargs)

Apply ‘translate’ transformation to the Geometry object.

See coords.Coords.translate() for details.

trl(*args, **kargs)

Apply ‘translate’ transformation to the Geometry object.

See coords.Coords.translate() for details.

pointsAt(t, normalized=False, return_position=False)

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.

Returns a Coords with the coordinates of the points.

If normalized is True, the parameter values are give in a normalized space where 0 is the start of the curve and 1 is the end.

If return_position is True, also returns the part numbers on which the point are lying and the local parameter values.

directionsAt(t)

Return the directions 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.

subPoints(div=10, extend=[0.0, 0.0])

Return a sequence of points on the Curve.

  • div: int or a list of floats (usually in the range [0.,1.]) If div is an integer, a list of floats is constructed by dividing the range [0.,1.] into div equal parts. The list of floats then specifies a set of parameter values for which points at in each part are returned. The points are returned in a single Coords in order of the parts.

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.

toProp(prop)

Converts the argument into a legal set of properties for the object.

The conversion involves resizing the argument to a 1D array of length self.nelems(), and converting the data type to integer.

getCoords()

Get the coords data.

Returns the full array of coordinates stored in the Geometry object. Note that subclasses may store more points in this array than are used to define the geometry.

split(split=None)

Split a curve into a list of partial curves

split is a list of integer values specifying the node numbers where the curve is to be split. As a convenience, a single int may be given if the curve is to be split at a single node, or None to split all all nodes.

Returns a list of open curves of the same type as the original.

length()

Return the total length of the curve.

This is only available for curves that implement the ‘lengths’ method.

approx(ndiv=None, ntot=None)

Return a PolyLine approximation of the curve

Parameters:

  • ndiv: int: number of straight segments to use over each part of the curve. This is only used if
  • ntot: int: number of straight segments to use over the total length of the curve.

Returns a PolyLine approximation for the curve. C.approx(ndiv=n) returns an approximation with ndiv segments over each part of the curve. This may results in segments with very different lengths. C.approx(ntot=n) returns an approximation with ntot segments over the total length of the curve. This produces more equally sized segments, but the internal end points of the curve parts may not be on the approximating Polyline.

level()

Return the dimensionality of the Geometry, or -1 if unknown

frenet(ndiv=None, ntot=None, upvector=None, avgdir=True, compensate=False)

Return points and Frenet frame along the curve.

A PolyLine approximation for the curve is constructed, using the Curve.approx() method with the arguments ndiv and ntot. Then Frenet frames are constructed with PolyLine.movingFrenet() using the remaining arguments. The resulting PolyLine points and Frenet frames are returned.

Parameters:

  • upvector: (3,) vector: a vector normal to the (tangent,normal) plane at the first point of the curve. It defines the binormal at the first point. If not specified it is set to the shorted distance through the set of 10 first points.

  • avgdir: bool or array. If True (default), the tangential vector is set to the average direction of the two segments ending at a node. If False, the tangent vectors will be those of the line segment starting at the points. The tangential vector can also be set by the user by specifying an array with the matching number of vectors.

  • compensate: bool: If True, adds a compensation algorithm if the curve is closed. For a closed curve the moving Frenet algorithm can be continued back to the first point. If the resulting binormial does not coincide with the starting one, some torsion is added to the end portions of the curve to make the two binormals coincide.

    This feature is off by default because it is currently experimental and is likely to change in future. It may also form the base for setting the starting as well as the ending binormal.

Returns:

  • X: a Coords with npts points on the curve
  • T: normalized tangent vector to the curve at npts points
  • N: normalized normal vector to the curve at npts points
  • B: normalized binormal vector to the curve at npts points
copy()

Return a deep copy of the Geometry object.

The returned object is an exact copy of the input, but has all of its data independent of the former.

splitProp(prop=None)

Partition a Geometry (Formex/Mesh) according to the values in prop.

Parameters:

  • prop: an int array with length self.nelems(), or None. If None, the prop attribute of the Geometry is used.

Returns a list of Geometry objects of the same type as the input. Each object contains all the elements having the same value of prop. The number of objects in the list is equal to the number of unique values in prop. The list is sorted in ascending order of their prop value.

It prop is None and the the object has no prop attribute, an empty list is returned.

resized(size=1.0, tol=1e-05)

Return a copy of the Geometry scaled to the given size.

size can be a single value or a list of three values for the three coordinate directions. If it is a single value, all directions are scaled to the same size. Directions for which the geometry has a size smaller than tol times the maximum size are not rescaled.

setProp(p=None)

Create or destroy the property array for the Formex.

A property array is a rank-1 integer array with dimension equal to the number of elements in the Formex (first dimension of data). You can specify a single value or a list/array of integer values. If the number of passed values is less than the number of elements, they wil be repeated. If you give more, they will be ignored.

If a value None is given, the properties are removed from the Formex.

write(fil, sep=' ', mode='w')

Write a Geometry to a .pgf file.

If fil is a string, a file with that name is opened. Else fil should be an open file. The Geometry is then written to that file in a native format, using sep as separator between the coordinates. If fil is a string, the file is closed prior to returning.

class curve.Line(coords)

A Line is a PolyLine with exactly two points.

Parameters:

  • coords: compatible with (2,3) shaped float array
endPoints()

Return start and end points of the curve.

Returns a Coords with two points, or None if the curve is closed.

sub_directions_2(t, j)

Return the directions at values,parts given by zip(t,j)

t and j can both be arrays, but should have the same length.

localParam(t)

Split global parameter value in part number and local parameter

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.

Returns a tuple of arrays i,t, where i are the (integer) part numbers and t the local parameter values (between 0 and 1).

addNoise(*args, **kargs)

Apply ‘addNoise’ transformation to the Geometry object.

See coords.Coords.addNoise() for details.

affine(*args, **kargs)

Apply ‘affine’ transformation to the Geometry object.

See coords.Coords.affine() for details.

align(*args, **kargs)

Apply ‘align’ transformation to the Geometry object.

See coords.Coords.align() for details.

bump(*args, **kargs)

Apply ‘bump’ transformation to the Geometry object.

See coords.Coords.bump() for details.

bump1(*args, **kargs)

Apply ‘bump1’ transformation to the Geometry object.

See coords.Coords.bump1() for details.

bump2(*args, **kargs)

Apply ‘bump2’ transformation to the Geometry object.

See coords.Coords.bump2() for details.

centered(*args, **kargs)

Apply ‘centered’ transformation to the Geometry object.

See coords.Coords.centered() for details.

cylindrical(*args, **kargs)

Apply ‘cylindrical’ transformation to the Geometry object.

See coords.Coords.cylindrical() for details.

egg(*args, **kargs)

Apply ‘egg’ transformation to the Geometry object.

See coords.Coords.egg() for details.

flare(*args, **kargs)

Apply ‘flare’ transformation to the Geometry object.

See coords.Coords.flare() for details.

hyperCylindrical(*args, **kargs)

Apply ‘hyperCylindrical’ transformation to the Geometry object.

See coords.Coords.hyperCylindrical() for details.

isopar(*args, **kargs)

Apply ‘isopar’ transformation to the Geometry object.

See coords.Coords.isopar() for details.

map(*args, **kargs)

Apply ‘map’ transformation to the Geometry object.

See coords.Coords.map() for details.

map1(*args, **kargs)

Apply ‘map1’ transformation to the Geometry object.

See coords.Coords.map1() for details.

mapd(*args, **kargs)

Apply ‘mapd’ transformation to the Geometry object.

See coords.Coords.mapd() for details.

position(*args, **kargs)

Apply ‘position’ transformation to the Geometry object.

See coords.Coords.position() for details.

projectOnCylinder(*args, **kargs)

Apply ‘projectOnCylinder’ transformation to the Geometry object.

See coords.Coords.projectOnCylinder() for details.

projectOnPlane(*args, **kargs)

Apply ‘projectOnPlane’ transformation to the Geometry object.

See coords.Coords.projectOnPlane() for details.

projectOnSphere(*args, **kargs)

Apply ‘projectOnSphere’ transformation to the Geometry object.

See coords.Coords.projectOnSphere() for details.

reflect(*args, **kargs)

Apply ‘reflect’ transformation to the Geometry object.

See coords.Coords.reflect() for details.

replace(*args, **kargs)

Apply ‘replace’ transformation to the Geometry object.

See coords.Coords.replace() for details.

rollAxes(*args, **kargs)

Apply ‘rollAxes’ transformation to the Geometry object.

See coords.Coords.rollAxes() for details.

rot(*args, **kargs)

Apply ‘rotate’ transformation to the Geometry object.

See coords.Coords.rotate() for details.

rotate(*args, **kargs)

Apply ‘rotate’ transformation to the Geometry object.

See coords.Coords.rotate() for details.

scale(*args, **kargs)

Apply ‘scale’ transformation to the Geometry object.

See coords.Coords.scale() for details.

shear(*args, **kargs)

Apply ‘shear’ transformation to the Geometry object.

See coords.Coords.shear() for details.

spherical(*args, **kargs)

Apply ‘spherical’ transformation to the Geometry object.

See coords.Coords.spherical() for details.

superSpherical(*args, **kargs)

Apply ‘superSpherical’ transformation to the Geometry object.

See coords.Coords.superSpherical() for details.

swapAxes(*args, **kargs)

Apply ‘swapAxes’ transformation to the Geometry object.

See coords.Coords.swapAxes() for details.

toCylindrical(*args, **kargs)

Apply ‘toCylindrical’ transformation to the Geometry object.

See coords.Coords.toCylindrical() for details.

toSpherical(*args, **kargs)

Apply ‘toSpherical’ transformation to the Geometry object.

See coords.Coords.toSpherical() for details.

transformCS(*args, **kargs)

Apply ‘transformCS’ transformation to the Geometry object.

See coords.Coords.transformCS() for details.

translate(*args, **kargs)

Apply ‘translate’ transformation to the Geometry object.

See coords.Coords.translate() for details.

trl(*args, **kargs)

Apply ‘translate’ transformation to the Geometry object.

See coords.Coords.translate() for details.

pointsAt(t, normalized=False, return_position=False)

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.

Returns a Coords with the coordinates of the points.

If normalized is True, the parameter values are give in a normalized space where 0 is the start of the curve and 1 is the end.

If return_position is True, also returns the part numbers on which the point are lying and the local parameter values.

directionsAt(t)

Return the directions 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.

subPoints(div=10, extend=[0.0, 0.0])

Return a sequence of points on the Curve.

  • div: int or a list of floats (usually in the range [0.,1.]) If div is an integer, a list of floats is constructed by dividing the range [0.,1.] into div equal parts. The list of floats then specifies a set of parameter values for which points at in each part are returned. The points are returned in a single Coords in order of the parts.

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.

toProp(prop)

Converts the argument into a legal set of properties for the object.

The conversion involves resizing the argument to a 1D array of length self.nelems(), and converting the data type to integer.

getCoords()

Get the coords data.

Returns the full array of coordinates stored in the Geometry object. Note that subclasses may store more points in this array than are used to define the geometry.

split(split=None)

Split a curve into a list of partial curves

split is a list of integer values specifying the node numbers where the curve is to be split. As a convenience, a single int may be given if the curve is to be split at a single node, or None to split all all nodes.

Returns a list of open curves of the same type as the original.

length()

Return the total length of the curve.

This is only available for curves that implement the ‘lengths’ method.

approx(ndiv=None, ntot=None)

Return a PolyLine approximation of the curve

Parameters:

  • ndiv: int: number of straight segments to use over each part of the curve. This is only used if
  • ntot: int: number of straight segments to use over the total length of the curve.

Returns a PolyLine approximation for the curve. C.approx(ndiv=n) returns an approximation with ndiv segments over each part of the curve. This may results in segments with very different lengths. C.approx(ntot=n) returns an approximation with ntot segments over the total length of the curve. This produces more equally sized segments, but the internal end points of the curve parts may not be on the approximating Polyline.

level()

Return the dimensionality of the Geometry, or -1 if unknown

frenet(ndiv=None, ntot=None, upvector=None, avgdir=True, compensate=False)

Return points and Frenet frame along the curve.

A PolyLine approximation for the curve is constructed, using the Curve.approx() method with the arguments ndiv and ntot. Then Frenet frames are constructed with PolyLine.movingFrenet() using the remaining arguments. The resulting PolyLine points and Frenet frames are returned.

Parameters:

  • upvector: (3,) vector: a vector normal to the (tangent,normal) plane at the first point of the curve. It defines the binormal at the first point. If not specified it is set to the shorted distance through the set of 10 first points.

  • avgdir: bool or array. If True (default), the tangential vector is set to the average direction of the two segments ending at a node. If False, the tangent vectors will be those of the line segment starting at the points. The tangential vector can also be set by the user by specifying an array with the matching number of vectors.

  • compensate: bool: If True, adds a compensation algorithm if the curve is closed. For a closed curve the moving Frenet algorithm can be continued back to the first point. If the resulting binormial does not coincide with the starting one, some torsion is added to the end portions of the curve to make the two binormals coincide.

    This feature is off by default because it is currently experimental and is likely to change in future. It may also form the base for setting the starting as well as the ending binormal.

Returns:

  • X: a Coords with npts points on the curve
  • T: normalized tangent vector to the curve at npts points
  • N: normalized normal vector to the curve at npts points
  • B: normalized binormal vector to the curve at npts points
copy()

Return a deep copy of the Geometry object.

The returned object is an exact copy of the input, but has all of its data independent of the former.

splitProp(prop=None)

Partition a Geometry (Formex/Mesh) according to the values in prop.

Parameters:

  • prop: an int array with length self.nelems(), or None. If None, the prop attribute of the Geometry is used.

Returns a list of Geometry objects of the same type as the input. Each object contains all the elements having the same value of prop. The number of objects in the list is equal to the number of unique values in prop. The list is sorted in ascending order of their prop value.

It prop is None and the the object has no prop attribute, an empty list is returned.

resized(size=1.0, tol=1e-05)

Return a copy of the Geometry scaled to the given size.

size can be a single value or a list of three values for the three coordinate directions. If it is a single value, all directions are scaled to the same size. Directions for which the geometry has a size smaller than tol times the maximum size are not rescaled.

setProp(p=None)

Create or destroy the property array for the Formex.

A property array is a rank-1 integer array with dimension equal to the number of elements in the Formex (first dimension of data). You can specify a single value or a list/array of integer values. If the number of passed values is less than the number of elements, they wil be repeated. If you give more, they will be ignored.

If a value None is given, the properties are removed from the Formex.

close()

Close a PolyLine.

If the PolyLine is already closed, it is returned unchanged. Else it is closed by adding a segment from the last to the first point (even if these are coincident).

Warning

This method changes the PolyLine inplace.

open()

Open a closed PolyLine.

If the PolyLine is closed, it is opened by removing the last segment. Else, it is returned unchanged.

Warning

This method changes the PolyLine inplace.

Use split() if you want to open the PolyLine without losing a segment.

write(fil, sep=' ', mode='w')

Write a Geometry to a .pgf file.

If fil is a string, a file with that name is opened. Else fil should be an open file. The Geometry is then written to that file in a native format, using sep as separator between the coordinates. If fil is a string, the file is closed prior to returning.

toFormex()

Return the polyline as a Formex.

toMesh()

Convert the polyLine to a plex-2 Mesh.

The returned Mesh is equivalent with the PolyLine.

sub_points(t, j)

Return the points at values t in part j

sub_points_2(t, j)

Return the points at value,part pairs (t,j)

sub_directions(t, j)

Return the unit direction vectors at values t in part j.

vectors()

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.

directions(return_doubles=False)

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.

avgDirections(return_doubles=False)

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.

approximate(nseg, equidistant=True, npre=100)

Approximate a PolyLine with a PolyLine of n segments

Parameters:

  • nseg: number of straight segments of the resulting PolyLine
  • equidistant: if True (default) the points are spaced almost equidistantly over the curve. If False, the points are spread equally over the parameter space.
  • npre: only used when equidistant is True: number of segments per part of the curve used in the pre-approximation. This pre- approximation is currently required to compute curve lengths.

Note

This is an alternative for Curve.approx, and may replace it in future.

roll(n)

Roll the points of a closed PolyLine.

lengths()

Return the length of the parts of the curve.

atLength(div)

Returns the parameter values at given relative curve length.

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.

reverse()

Return the same curve with the parameter direction reversed.

parts(j, k)

Return a PolyLine containing only segments j to k (k not included).

The resulting PolyLine is always open.

cutWithPlane(p, n, side='')

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.

append(PL, fuse=True, **kargs)

Append another PolyLine to this one.

Returns the concatenation of two open PolyLines. Closed PolyLines cannot be concatenated.

insertPointsAt(t, normalized=False, return_indices=False)

Insert new 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.

Returns a PolyLine with the new points inserted. Note that the parameter values of the points will have changed. If return_indices is True, also returns the indices of the inserted points in the new PolyLine.

splitAt(t, normalized=False)

Split a PolyLine at parametric 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.

Returns a list of open Polylines.

class curve.BezierSpline(coords=None, deriv=None, curl=0.3333333333333333, control=None, closed=False, degree=3, endzerocurv=False)

A class representing a Bezier spline curve of degree 1, 2 or 3.

A Bezier spline of degree d is a continuous curve consisting of nparts successive parts, where each part is a Bezier curve of the same degree. Currently pyFormex can model linear, quadratic and cubic BezierSplines. A linear BezierSpline is equivalent to a PolyLine, which has more specialized methods than the BezierSpline, so it might be more sensible to use a PolyLine instead of the linear BezierSpline.

A Bezier curve of degree d is determined by d+1 control points, of which the first and the last are on the curve, while the intermediate d-1 points are not. Since the end point of one part is the begin point of the next part, a BezierSpline is described by ncontrol=d*nparts+1 control points if the curve is open, or ncontrol=d*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) The points that are on the curve. For an open curve, npoints=nparts+1, for a closed curve, npoints = nparts. If not specified, the on-curve points should be included in the control argument.

  • deriv : array_like (npoints,3) or (2,3) or a list of 2 values one of which can be None and the other is a shape(3,) arraylike. If specified, it gives the direction of the curve at all points or at the endpoints only for a shape (2,3) array or only at one of the endpoints for a list of shape(3,) arraylike and a None type. 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.

  • curl : float 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. The higher the value, the more the curve becomes curled.

  • control : array(nparts,2,3) or array(ncontrol,3) If coords was specified, this should be a (nparts,2,3) array with the intermediate control points, two for each part.

    If coords was not specified, this should be the full array of ncontrol control points for the curve. The number of points should be a multiple of 3 plus 1. If the curve is closed, the last point is equal to the first and does not need to a multiple of 3 is also allowed, in which case the first point will be appended as last.

    If not specified, the control points are generated automatically from the coords, deriv and curl arguments. If specified, they override these parameters.

  • closed : boolean If True, the curve will be continued from the last point back to the first to create a closed curve.

  • degree: int (1, 2 or 3) Specfies the degree of the curve. Default is 3.

  • endzerocurv : boolean or tuple of two booleans. Specifies the end conditions for an open curve. If True, the end curvature will be forced to zero. The default is to use maximal continuity of the curvature. The value may be set to a tuple of two values to specify different conditions for both ends. This argument is ignored for a closed curve.

pointsOn()

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.

pointsOff()

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.

part(j)

Returns the points defining part j of the curve.

sub_points(t, j)

Return the points at values t in part j.

sub_directions(t, j)

Return the unit direction vectors at values t in part j.

sub_curvature(t, j)

Return the curvature at values t in part j.

length_intgrnd(t, j)

Return the arc length integrand at value t in part j.

lengths()

Return the length of the parts of the curve.

parts(j, k)

Return a curve containing only parts j to k (k not included).

The resulting curve is always open.

toMesh()

Convert the BezierSpline to a Mesh.

For degrees 1 or 2, the returned Mesh is equivalent with the BezierSpline, and will have element type ‘line1’, resp. ‘line2’.

For degree 3, the returned Mesh will currently be a quadratic approximation with element type ‘line2’.

approx_by_subdivision(tol=0.001)

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(extend=[1.0, 1.0])

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.

reverse()

Return the same curve with the parameter direction reversed.

endPoints()

Return start and end points of the curve.

Returns a Coords with two points, or None if the curve is closed.

sub_points_2(t, j)

Return the points at values,parts given by zip(t,j)

t and j can both be arrays, but should have the same length.

sub_directions_2(t, j)

Return the directions at values,parts given by zip(t,j)

t and j can both be arrays, but should have the same length.

localParam(t)

Split global parameter value in part number and local parameter

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.

Returns a tuple of arrays i,t, where i are the (integer) part numbers and t the local parameter values (between 0 and 1).

addNoise(*args, **kargs)

Apply ‘addNoise’ transformation to the Geometry object.

See coords.Coords.addNoise() for details.

affine(*args, **kargs)

Apply ‘affine’ transformation to the Geometry object.

See coords.Coords.affine() for details.

align(*args, **kargs)

Apply ‘align’ transformation to the Geometry object.

See coords.Coords.align() for details.

bump(*args, **kargs)

Apply ‘bump’ transformation to the Geometry object.

See coords.Coords.bump() for details.

bump1(*args, **kargs)

Apply ‘bump1’ transformation to the Geometry object.

See coords.Coords.bump1() for details.

bump2(*args, **kargs)

Apply ‘bump2’ transformation to the Geometry object.

See coords.Coords.bump2() for details.

centered(*args, **kargs)

Apply ‘centered’ transformation to the Geometry object.

See coords.Coords.centered() for details.

cylindrical(*args, **kargs)

Apply ‘cylindrical’ transformation to the Geometry object.

See coords.Coords.cylindrical() for details.

egg(*args, **kargs)

Apply ‘egg’ transformation to the Geometry object.

See coords.Coords.egg() for details.

flare(*args, **kargs)

Apply ‘flare’ transformation to the Geometry object.

See coords.Coords.flare() for details.

hyperCylindrical(*args, **kargs)

Apply ‘hyperCylindrical’ transformation to the Geometry object.

See coords.Coords.hyperCylindrical() for details.

isopar(*args, **kargs)

Apply ‘isopar’ transformation to the Geometry object.

See coords.Coords.isopar() for details.

map(*args, **kargs)

Apply ‘map’ transformation to the Geometry object.

See coords.Coords.map() for details.

map1(*args, **kargs)

Apply ‘map1’ transformation to the Geometry object.

See coords.Coords.map1() for details.

mapd(*args, **kargs)

Apply ‘mapd’ transformation to the Geometry object.

See coords.Coords.mapd() for details.

position(*args, **kargs)

Apply ‘position’ transformation to the Geometry object.

See coords.Coords.position() for details.

projectOnCylinder(*args, **kargs)

Apply ‘projectOnCylinder’ transformation to the Geometry object.

See coords.Coords.projectOnCylinder() for details.

projectOnPlane(*args, **kargs)

Apply ‘projectOnPlane’ transformation to the Geometry object.

See coords.Coords.projectOnPlane() for details.

projectOnSphere(*args, **kargs)

Apply ‘projectOnSphere’ transformation to the Geometry object.

See coords.Coords.projectOnSphere() for details.

reflect(*args, **kargs)

Apply ‘reflect’ transformation to the Geometry object.

See coords.Coords.reflect() for details.

replace(*args, **kargs)

Apply ‘replace’ transformation to the Geometry object.

See coords.Coords.replace() for details.

rollAxes(*args, **kargs)

Apply ‘rollAxes’ transformation to the Geometry object.

See coords.Coords.rollAxes() for details.

rot(*args, **kargs)

Apply ‘rotate’ transformation to the Geometry object.

See coords.Coords.rotate() for details.

rotate(*args, **kargs)

Apply ‘rotate’ transformation to the Geometry object.

See coords.Coords.rotate() for details.

scale(*args, **kargs)

Apply ‘scale’ transformation to the Geometry object.

See coords.Coords.scale() for details.

shear(*args, **kargs)

Apply ‘shear’ transformation to the Geometry object.

See coords.Coords.shear() for details.

spherical(*args, **kargs)

Apply ‘spherical’ transformation to the Geometry object.

See coords.Coords.spherical() for details.

superSpherical(*args, **kargs)

Apply ‘superSpherical’ transformation to the Geometry object.

See coords.Coords.superSpherical() for details.

swapAxes(*args, **kargs)

Apply ‘swapAxes’ transformation to the Geometry object.

See coords.Coords.swapAxes() for details.

toCylindrical(*args, **kargs)

Apply ‘toCylindrical’ transformation to the Geometry object.

See coords.Coords.toCylindrical() for details.

toSpherical(*args, **kargs)

Apply ‘toSpherical’ transformation to the Geometry object.

See coords.Coords.toSpherical() for details.

transformCS(*args, **kargs)

Apply ‘transformCS’ transformation to the Geometry object.

See coords.Coords.transformCS() for details.

translate(*args, **kargs)

Apply ‘translate’ transformation to the Geometry object.

See coords.Coords.translate() for details.

trl(*args, **kargs)

Apply ‘translate’ transformation to the Geometry object.

See coords.Coords.translate() for details.

pointsAt(t, normalized=False, return_position=False)

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.

Returns a Coords with the coordinates of the points.

If normalized is True, the parameter values are give in a normalized space where 0 is the start of the curve and 1 is the end.

If return_position is True, also returns the part numbers on which the point are lying and the local parameter values.

nelems()

Return the number of elements in the Geometry.

This method should be re-implemented by the derived classes. For the (empty) Geometry class it always returns 0.

directionsAt(t)

Return the directions 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.

subPoints(div=10, extend=[0.0, 0.0])

Return a sequence of points on the Curve.

  • div: int or a list of floats (usually in the range [0.,1.]) If div is an integer, a list of floats is constructed by dividing the range [0.,1.] into div equal parts. The list of floats then specifies a set of parameter values for which points at in each part are returned. The points are returned in a single Coords in order of the parts.

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.

toProp(prop)

Converts the argument into a legal set of properties for the object.

The conversion involves resizing the argument to a 1D array of length self.nelems(), and converting the data type to integer.

getCoords()

Get the coords data.

Returns the full array of coordinates stored in the Geometry object. Note that subclasses may store more points in this array than are used to define the geometry.

split(split=None)

Split a curve into a list of partial curves

split is a list of integer values specifying the node numbers where the curve is to be split. As a convenience, a single int may be given if the curve is to be split at a single node, or None to split all all nodes.

Returns a list of open curves of the same type as the original.

length()

Return the total length of the curve.

This is only available for curves that implement the ‘lengths’ method.

approx(ndiv=None, ntot=None)

Return a PolyLine approximation of the curve

Parameters:

  • ndiv: int: number of straight segments to use over each part of the curve. This is only used if
  • ntot: int: number of straight segments to use over the total length of the curve.

Returns a PolyLine approximation for the curve. C.approx(ndiv=n) returns an approximation with ndiv segments over each part of the curve. This may results in segments with very different lengths. C.approx(ntot=n) returns an approximation with ntot segments over the total length of the curve. This produces more equally sized segments, but the internal end points of the curve parts may not be on the approximating Polyline.

level()

Return the dimensionality of the Geometry, or -1 if unknown

frenet(ndiv=None, ntot=None, upvector=None, avgdir=True, compensate=False)

Return points and Frenet frame along the curve.

A PolyLine approximation for the curve is constructed, using the Curve.approx() method with the arguments ndiv and ntot. Then Frenet frames are constructed with PolyLine.movingFrenet() using the remaining arguments. The resulting PolyLine points and Frenet frames are returned.

Parameters:

  • upvector: (3,) vector: a vector normal to the (tangent,normal) plane at the first point of the curve. It defines the binormal at the first point. If not specified it is set to the shorted distance through the set of 10 first points.

  • avgdir: bool or array. If True (default), the tangential vector is set to the average direction of the two segments ending at a node. If False, the tangent vectors will be those of the line segment starting at the points. The tangential vector can also be set by the user by specifying an array with the matching number of vectors.

  • compensate: bool: If True, adds a compensation algorithm if the curve is closed. For a closed curve the moving Frenet algorithm can be continued back to the first point. If the resulting binormial does not coincide with the starting one, some torsion is added to the end portions of the curve to make the two binormals coincide.

    This feature is off by default because it is currently experimental and is likely to change in future. It may also form the base for setting the starting as well as the ending binormal.

Returns:

  • X: a Coords with npts points on the curve
  • T: normalized tangent vector to the curve at npts points
  • N: normalized normal vector to the curve at npts points
  • B: normalized binormal vector to the curve at npts points
copy()

Return a deep copy of the Geometry object.

The returned object is an exact copy of the input, but has all of its data independent of the former.

splitProp(prop=None)

Partition a Geometry (Formex/Mesh) according to the values in prop.

Parameters:

  • prop: an int array with length self.nelems(), or None. If None, the prop attribute of the Geometry is used.

Returns a list of Geometry objects of the same type as the input. Each object contains all the elements having the same value of prop. The number of objects in the list is equal to the number of unique values in prop. The list is sorted in ascending order of their prop value.

It prop is None and the the object has no prop attribute, an empty list is returned.

resized(size=1.0, tol=1e-05)

Return a copy of the Geometry scaled to the given size.

size can be a single value or a list of three values for the three coordinate directions. If it is a single value, all directions are scaled to the same size. Directions for which the geometry has a size smaller than tol times the maximum size are not rescaled.

approximate(nseg, equidistant=True, npre=100)

Approximate a Curve with a PolyLine of n segments

Parameters:

  • nseg: number of straight segments of the resulting PolyLine
  • equidistant: if True (default) the points are spaced almost equidistantly over the curve. If False, the points are spread equally over the parameter space.
  • npre: only used when equidistant is True: number of segments per part of the curve used in the pre-approximation. This pre- approximation is currently required to compute curve lengths.

Note

This is an alternative for Curve.approx, and may replace it in future.

toFormex(*args, **kargs)

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.

setProp(p=None)

Create or destroy the property array for the Formex.

A property array is a rank-1 integer array with dimension equal to the number of elements in the Formex (first dimension of data). You can specify a single value or a list/array of integer values. If the number of passed values is less than the number of elements, they wil be repeated. If you give more, they will be ignored.

If a value None is given, the properties are removed from the Formex.

write(fil, sep=' ', mode='w')

Write a Geometry to a .pgf file.

If fil is a string, a file with that name is opened. Else fil should be an open file. The Geometry is then written to that file in a native format, using sep as separator between the coordinates. If fil is a string, the file is closed prior to returning.

class curve.CardinalSpline(coords, tension=0.0, closed=False, endzerocurv=False)

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).

endPoints()

Return start and end points of the curve.

Returns a Coords with two points, or None if the curve is closed.

sub_points_2(t, j)

Return the points at values,parts given by zip(t,j)

t and j can both be arrays, but should have the same length.

sub_directions_2(t, j)

Return the directions at values,parts given by zip(t,j)

t and j can both be arrays, but should have the same length.

localParam(t)

Split global parameter value in part number and local parameter

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.

Returns a tuple of arrays i,t, where i are the (integer) part numbers and t the local parameter values (between 0 and 1).

addNoise(*args, **kargs)

Apply ‘addNoise’ transformation to the Geometry object.

See coords.Coords.addNoise() for details.

affine(*args, **kargs)

Apply ‘affine’ transformation to the Geometry object.

See coords.Coords.affine() for details.

align(*args, **kargs)

Apply ‘align’ transformation to the Geometry object.

See coords.Coords.align() for details.

bump(*args, **kargs)

Apply ‘bump’ transformation to the Geometry object.

See coords.Coords.bump() for details.

bump1(*args, **kargs)

Apply ‘bump1’ transformation to the Geometry object.

See coords.Coords.bump1() for details.

bump2(*args, **kargs)

Apply ‘bump2’ transformation to the Geometry object.

See coords.Coords.bump2() for details.

centered(*args, **kargs)

Apply ‘centered’ transformation to the Geometry object.

See coords.Coords.centered() for details.

cylindrical(*args, **kargs)

Apply ‘cylindrical’ transformation to the Geometry object.

See coords.Coords.cylindrical() for details.

egg(*args, **kargs)

Apply ‘egg’ transformation to the Geometry object.

See coords.Coords.egg() for details.

flare(*args, **kargs)

Apply ‘flare’ transformation to the Geometry object.

See coords.Coords.flare() for details.

hyperCylindrical(*args, **kargs)

Apply ‘hyperCylindrical’ transformation to the Geometry object.

See coords.Coords.hyperCylindrical() for details.

isopar(*args, **kargs)

Apply ‘isopar’ transformation to the Geometry object.

See coords.Coords.isopar() for details.

map(*args, **kargs)

Apply ‘map’ transformation to the Geometry object.

See coords.Coords.map() for details.

map1(*args, **kargs)

Apply ‘map1’ transformation to the Geometry object.

See coords.Coords.map1() for details.

mapd(*args, **kargs)

Apply ‘mapd’ transformation to the Geometry object.

See coords.Coords.mapd() for details.

position(*args, **kargs)

Apply ‘position’ transformation to the Geometry object.

See coords.Coords.position() for details.

projectOnCylinder(*args, **kargs)

Apply ‘projectOnCylinder’ transformation to the Geometry object.

See coords.Coords.projectOnCylinder() for details.

projectOnPlane(*args, **kargs)

Apply ‘projectOnPlane’ transformation to the Geometry object.

See coords.Coords.projectOnPlane() for details.

projectOnSphere(*args, **kargs)

Apply ‘projectOnSphere’ transformation to the Geometry object.

See coords.Coords.projectOnSphere() for details.

reflect(*args, **kargs)

Apply ‘reflect’ transformation to the Geometry object.

See coords.Coords.reflect() for details.

replace(*args, **kargs)

Apply ‘replace’ transformation to the Geometry object.

See coords.Coords.replace() for details.

rollAxes(*args, **kargs)

Apply ‘rollAxes’ transformation to the Geometry object.

See coords.Coords.rollAxes() for details.

rot(*args, **kargs)

Apply ‘rotate’ transformation to the Geometry object.

See coords.Coords.rotate() for details.

rotate(*args, **kargs)

Apply ‘rotate’ transformation to the Geometry object.

See coords.Coords.rotate() for details.

scale(*args, **kargs)

Apply ‘scale’ transformation to the Geometry object.

See coords.Coords.scale() for details.

shear(*args, **kargs)

Apply ‘shear’ transformation to the Geometry object.

See coords.Coords.shear() for details.

spherical(*args, **kargs)

Apply ‘spherical’ transformation to the Geometry object.

See coords.Coords.spherical() for details.

superSpherical(*args, **kargs)

Apply ‘superSpherical’ transformation to the Geometry object.

See coords.Coords.superSpherical() for details.

swapAxes(*args, **kargs)

Apply ‘swapAxes’ transformation to the Geometry object.

See coords.Coords.swapAxes() for details.

toCylindrical(*args, **kargs)

Apply ‘toCylindrical’ transformation to the Geometry object.

See coords.Coords.toCylindrical() for details.

toSpherical(*args, **kargs)

Apply ‘toSpherical’ transformation to the Geometry object.

See coords.Coords.toSpherical() for details.

transformCS(*args, **kargs)

Apply ‘transformCS’ transformation to the Geometry object.

See coords.Coords.transformCS() for details.

translate(*args, **kargs)

Apply ‘translate’ transformation to the Geometry object.

See coords.Coords.translate() for details.

trl(*args, **kargs)

Apply ‘translate’ transformation to the Geometry object.

See coords.Coords.translate() for details.

pointsAt(t, normalized=False, return_position=False)

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.

Returns a Coords with the coordinates of the points.

If normalized is True, the parameter values are give in a normalized space where 0 is the start of the curve and 1 is the end.

If return_position is True, also returns the part numbers on which the point are lying and the local parameter values.

nelems()

Return the number of elements in the Geometry.

This method should be re-implemented by the derived classes. For the (empty) Geometry class it always returns 0.

directionsAt(t)

Return the directions 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.

subPoints(div=10, extend=[0.0, 0.0])

Return a sequence of points on the Curve.

  • div: int or a list of floats (usually in the range [0.,1.]) If div is an integer, a list of floats is constructed by dividing the range [0.,1.] into div equal parts. The list of floats then specifies a set of parameter values for which points at in each part are returned. The points are returned in a single Coords in order of the parts.

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.

toProp(prop)

Converts the argument into a legal set of properties for the object.

The conversion involves resizing the argument to a 1D array of length self.nelems(), and converting the data type to integer.

getCoords()

Get the coords data.

Returns the full array of coordinates stored in the Geometry object. Note that subclasses may store more points in this array than are used to define the geometry.

split(split=None)

Split a curve into a list of partial curves

split is a list of integer values specifying the node numbers where the curve is to be split. As a convenience, a single int may be given if the curve is to be split at a single node, or None to split all all nodes.

Returns a list of open curves of the same type as the original.

length()

Return the total length of the curve.

This is only available for curves that implement the ‘lengths’ method.

approx(ndiv=None, ntot=None)

Return a PolyLine approximation of the curve

Parameters:

  • ndiv: int: number of straight segments to use over each part of the curve. This is only used if
  • ntot: int: number of straight segments to use over the total length of the curve.

Returns a PolyLine approximation for the curve. C.approx(ndiv=n) returns an approximation with ndiv segments over each part of the curve. This may results in segments with very different lengths. C.approx(ntot=n) returns an approximation with ntot segments over the total length of the curve. This produces more equally sized segments, but the internal end points of the curve parts may not be on the approximating Polyline.

level()

Return the dimensionality of the Geometry, or -1 if unknown

frenet(ndiv=None, ntot=None, upvector=None, avgdir=True, compensate=False)

Return points and Frenet frame along the curve.

A PolyLine approximation for the curve is constructed, using the Curve.approx() method with the arguments ndiv and ntot. Then Frenet frames are constructed with PolyLine.movingFrenet() using the remaining arguments. The resulting PolyLine points and Frenet frames are returned.

Parameters:

  • upvector: (3,) vector: a vector normal to the (tangent,normal) plane at the first point of the curve. It defines the binormal at the first point. If not specified it is set to the shorted distance through the set of 10 first points.

  • avgdir: bool or array. If True (default), the tangential vector is set to the average direction of the two segments ending at a node. If False, the tangent vectors will be those of the line segment starting at the points. The tangential vector can also be set by the user by specifying an array with the matching number of vectors.

  • compensate: bool: If True, adds a compensation algorithm if the curve is closed. For a closed curve the moving Frenet algorithm can be continued back to the first point. If the resulting binormial does not coincide with the starting one, some torsion is added to the end portions of the curve to make the two binormals coincide.

    This feature is off by default because it is currently experimental and is likely to change in future. It may also form the base for setting the starting as well as the ending binormal.

Returns:

  • X: a Coords with npts points on the curve
  • T: normalized tangent vector to the curve at npts points
  • N: normalized normal vector to the curve at npts points
  • B: normalized binormal vector to the curve at npts points
copy()

Return a deep copy of the Geometry object.

The returned object is an exact copy of the input, but has all of its data independent of the former.

splitProp(prop=None)

Partition a Geometry (Formex/Mesh) according to the values in prop.

Parameters:

  • prop: an int array with length self.nelems(), or None. If None, the prop attribute of the Geometry is used.

Returns a list of Geometry objects of the same type as the input. Each object contains all the elements having the same value of prop. The number of objects in the list is equal to the number of unique values in prop. The list is sorted in ascending order of their prop value.

It prop is None and the the object has no prop attribute, an empty list is returned.

resized(size=1.0, tol=1e-05)

Return a copy of the Geometry scaled to the given size.

size can be a single value or a list of three values for the three coordinate directions. If it is a single value, all directions are scaled to the same size. Directions for which the geometry has a size smaller than tol times the maximum size are not rescaled.

approximate(nseg, equidistant=True, npre=100)

Approximate a Curve with a PolyLine of n segments

Parameters:

  • nseg: number of straight segments of the resulting PolyLine
  • equidistant: if True (default) the points are spaced almost equidistantly over the curve. If False, the points are spread equally over the parameter space.
  • npre: only used when equidistant is True: number of segments per part of the curve used in the pre-approximation. This pre- approximation is currently required to compute curve lengths.

Note

This is an alternative for Curve.approx, and may replace it in future.

toFormex(*args, **kargs)

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.

setProp(p=None)

Create or destroy the property array for the Formex.

A property array is a rank-1 integer array with dimension equal to the number of elements in the Formex (first dimension of data). You can specify a single value or a list/array of integer values. If the number of passed values is less than the number of elements, they wil be repeated. If you give more, they will be ignored.

If a value None is given, the properties are removed from the Formex.

write(fil, sep=' ', mode='w')

Write a Geometry to a .pgf file.

If fil is a string, a file with that name is opened. Else fil should be an open file. The Geometry is then written to that file in a native format, using sep as separator between the coordinates. If fil is a string, the file is closed prior to returning.

pointsOn()

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.

pointsOff()

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.

part(j)

Returns the points defining part j of the curve.

sub_points(t, j)

Return the points at values t in part j.

sub_directions(t, j)

Return the unit direction vectors at values t in part j.

sub_curvature(t, j)

Return the curvature at values t in part j.

length_intgrnd(t, j)

Return the arc length integrand at value t in part j.

lengths()

Return the length of the parts of the curve.

parts(j, k)

Return a curve containing only parts j to k (k not included).

The resulting curve is always open.

toMesh()

Convert the BezierSpline to a Mesh.

For degrees 1 or 2, the returned Mesh is equivalent with the BezierSpline, and will have element type ‘line1’, resp. ‘line2’.

For degree 3, the returned Mesh will currently be a quadratic approximation with element type ‘line2’.

approx_by_subdivision(tol=0.001)

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(extend=[1.0, 1.0])

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.

reverse()

Return the same curve with the parameter direction reversed.

class curve.CardinalSpline2(coords, tension=0.0, closed=False)

A class representing a cardinal spline.

endPoints()

Return start and end points of the curve.

Returns a Coords with two points, or None if the curve is closed.

sub_points_2(t, j)

Return the points at values,parts given by zip(t,j)

t and j can both be arrays, but should have the same length.

sub_directions(t, j)

Return the directions at values t in part j

t can be an array of parameter values, j is a single segment number.

sub_directions_2(t, j)

Return the directions at values,parts given by zip(t,j)

t and j can both be arrays, but should have the same length.

localParam(t)

Split global parameter value in part number and local parameter

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.

Returns a tuple of arrays i,t, where i are the (integer) part numbers and t the local parameter values (between 0 and 1).

addNoise(*args, **kargs)

Apply ‘addNoise’ transformation to the Geometry object.

See coords.Coords.addNoise() for details.

affine(*args, **kargs)

Apply ‘affine’ transformation to the Geometry object.

See coords.Coords.affine() for details.

align(*args, **kargs)

Apply ‘align’ transformation to the Geometry object.

See coords.Coords.align() for details.

bump(*args, **kargs)

Apply ‘bump’ transformation to the Geometry object.

See coords.Coords.bump() for details.

bump1(*args, **kargs)

Apply ‘bump1’ transformation to the Geometry object.

See coords.Coords.bump1() for details.

bump2(*args, **kargs)

Apply ‘bump2’ transformation to the Geometry object.

See coords.Coords.bump2() for details.

centered(*args, **kargs)

Apply ‘centered’ transformation to the Geometry object.

See coords.Coords.centered() for details.

cylindrical(*args, **kargs)

Apply ‘cylindrical’ transformation to the Geometry object.

See coords.Coords.cylindrical() for details.

egg(*args, **kargs)

Apply ‘egg’ transformation to the Geometry object.

See coords.Coords.egg() for details.

flare(*args, **kargs)

Apply ‘flare’ transformation to the Geometry object.

See coords.Coords.flare() for details.

hyperCylindrical(*args, **kargs)

Apply ‘hyperCylindrical’ transformation to the Geometry object.

See coords.Coords.hyperCylindrical() for details.

isopar(*args, **kargs)

Apply ‘isopar’ transformation to the Geometry object.

See coords.Coords.isopar() for details.

map(*args, **kargs)

Apply ‘map’ transformation to the Geometry object.

See coords.Coords.map() for details.

map1(*args, **kargs)

Apply ‘map1’ transformation to the Geometry object.

See coords.Coords.map1() for details.

mapd(*args, **kargs)

Apply ‘mapd’ transformation to the Geometry object.

See coords.Coords.mapd() for details.

position(*args, **kargs)

Apply ‘position’ transformation to the Geometry object.

See coords.Coords.position() for details.

projectOnCylinder(*args, **kargs)

Apply ‘projectOnCylinder’ transformation to the Geometry object.

See coords.Coords.projectOnCylinder() for details.

projectOnPlane(*args, **kargs)

Apply ‘projectOnPlane’ transformation to the Geometry object.

See coords.Coords.projectOnPlane() for details.

projectOnSphere(*args, **kargs)

Apply ‘projectOnSphere’ transformation to the Geometry object.

See coords.Coords.projectOnSphere() for details.

reflect(*args, **kargs)

Apply ‘reflect’ transformation to the Geometry object.

See coords.Coords.reflect() for details.

replace(*args, **kargs)

Apply ‘replace’ transformation to the Geometry object.

See coords.Coords.replace() for details.

rollAxes(*args, **kargs)

Apply ‘rollAxes’ transformation to the Geometry object.

See coords.Coords.rollAxes() for details.

rot(*args, **kargs)

Apply ‘rotate’ transformation to the Geometry object.

See coords.Coords.rotate() for details.

rotate(*args, **kargs)

Apply ‘rotate’ transformation to the Geometry object.

See coords.Coords.rotate() for details.

scale(*args, **kargs)

Apply ‘scale’ transformation to the Geometry object.

See coords.Coords.scale() for details.

shear(*args, **kargs)

Apply ‘shear’ transformation to the Geometry object.

See coords.Coords.shear() for details.

spherical(*args, **kargs)

Apply ‘spherical’ transformation to the Geometry object.

See coords.Coords.spherical() for details.

superSpherical(*args, **kargs)

Apply ‘superSpherical’ transformation to the Geometry object.

See coords.Coords.superSpherical() for details.

swapAxes(*args, **kargs)

Apply ‘swapAxes’ transformation to the Geometry object.

See coords.Coords.swapAxes() for details.

toCylindrical(*args, **kargs)

Apply ‘toCylindrical’ transformation to the Geometry object.

See coords.Coords.toCylindrical() for details.

toSpherical(*args, **kargs)

Apply ‘toSpherical’ transformation to the Geometry object.

See coords.Coords.toSpherical() for details.

transformCS(*args, **kargs)

Apply ‘transformCS’ transformation to the Geometry object.

See coords.Coords.transformCS() for details.

translate(*args, **kargs)

Apply ‘translate’ transformation to the Geometry object.

See coords.Coords.translate() for details.

trl(*args, **kargs)

Apply ‘translate’ transformation to the Geometry object.

See coords.Coords.translate() for details.

pointsAt(t, normalized=False, return_position=False)

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.

Returns a Coords with the coordinates of the points.

If normalized is True, the parameter values are give in a normalized space where 0 is the start of the curve and 1 is the end.

If return_position is True, also returns the part numbers on which the point are lying and the local parameter values.

nelems()

Return the number of elements in the Geometry.

This method should be re-implemented by the derived classes. For the (empty) Geometry class it always returns 0.

directionsAt(t)

Return the directions 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.

subPoints(div=10, extend=[0.0, 0.0])

Return a sequence of points on the Curve.

  • div: int or a list of floats (usually in the range [0.,1.]) If div is an integer, a list of floats is constructed by dividing the range [0.,1.] into div equal parts. The list of floats then specifies a set of parameter values for which points at in each part are returned. The points are returned in a single Coords in order of the parts.

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.

toProp(prop)

Converts the argument into a legal set of properties for the object.

The conversion involves resizing the argument to a 1D array of length self.nelems(), and converting the data type to integer.

getCoords()

Get the coords data.

Returns the full array of coordinates stored in the Geometry object. Note that subclasses may store more points in this array than are used to define the geometry.

split(split=None)

Split a curve into a list of partial curves

split is a list of integer values specifying the node numbers where the curve is to be split. As a convenience, a single int may be given if the curve is to be split at a single node, or None to split all all nodes.

Returns a list of open curves of the same type as the original.

length()

Return the total length of the curve.

This is only available for curves that implement the ‘lengths’ method.

approx(ndiv=None, ntot=None)

Return a PolyLine approximation of the curve

Parameters:

  • ndiv: int: number of straight segments to use over each part of the curve. This is only used if
  • ntot: int: number of straight segments to use over the total length of the curve.

Returns a PolyLine approximation for the curve. C.approx(ndiv=n) returns an approximation with ndiv segments over each part of the curve. This may results in segments with very different lengths. C.approx(ntot=n) returns an approximation with ntot segments over the total length of the curve. This produces more equally sized segments, but the internal end points of the curve parts may not be on the approximating Polyline.

level()

Return the dimensionality of the Geometry, or -1 if unknown

frenet(ndiv=None, ntot=None, upvector=None, avgdir=True, compensate=False)

Return points and Frenet frame along the curve.

A PolyLine approximation for the curve is constructed, using the Curve.approx() method with the arguments ndiv and ntot. Then Frenet frames are constructed with PolyLine.movingFrenet() using the remaining arguments. The resulting PolyLine points and Frenet frames are returned.

Parameters:

  • upvector: (3,) vector: a vector normal to the (tangent,normal) plane at the first point of the curve. It defines the binormal at the first point. If not specified it is set to the shorted distance through the set of 10 first points.

  • avgdir: bool or array. If True (default), the tangential vector is set to the average direction of the two segments ending at a node. If False, the tangent vectors will be those of the line segment starting at the points. The tangential vector can also be set by the user by specifying an array with the matching number of vectors.

  • compensate: bool: If True, adds a compensation algorithm if the curve is closed. For a closed curve the moving Frenet algorithm can be continued back to the first point. If the resulting binormial does not coincide with the starting one, some torsion is added to the end portions of the curve to make the two binormals coincide.

    This feature is off by default because it is currently experimental and is likely to change in future. It may also form the base for setting the starting as well as the ending binormal.

Returns:

  • X: a Coords with npts points on the curve
  • T: normalized tangent vector to the curve at npts points
  • N: normalized normal vector to the curve at npts points
  • B: normalized binormal vector to the curve at npts points
copy()

Return a deep copy of the Geometry object.

The returned object is an exact copy of the input, but has all of its data independent of the former.

splitProp(prop=None)

Partition a Geometry (Formex/Mesh) according to the values in prop.

Parameters:

  • prop: an int array with length self.nelems(), or None. If None, the prop attribute of the Geometry is used.

Returns a list of Geometry objects of the same type as the input. Each object contains all the elements having the same value of prop. The number of objects in the list is equal to the number of unique values in prop. The list is sorted in ascending order of their prop value.

It prop is None and the the object has no prop attribute, an empty list is returned.

resized(size=1.0, tol=1e-05)

Return a copy of the Geometry scaled to the given size.

size can be a single value or a list of three values for the three coordinate directions. If it is a single value, all directions are scaled to the same size. Directions for which the geometry has a size smaller than tol times the maximum size are not rescaled.

approximate(nseg, equidistant=True, npre=100)

Approximate a Curve with a PolyLine of n segments

Parameters:

  • nseg: number of straight segments of the resulting PolyLine
  • equidistant: if True (default) the points are spaced almost equidistantly over the curve. If False, the points are spread equally over the parameter space.
  • npre: only used when equidistant is True: number of segments per part of the curve used in the pre-approximation. This pre- approximation is currently required to compute curve lengths.

Note

This is an alternative for Curve.approx, and may replace it in future.

toFormex(*args, **kargs)

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.

setProp(p=None)

Create or destroy the property array for the Formex.

A property array is a rank-1 integer array with dimension equal to the number of elements in the Formex (first dimension of data). You can specify a single value or a list/array of integer values. If the number of passed values is less than the number of elements, they wil be repeated. If you give more, they will be ignored.

If a value None is given, the properties are removed from the Formex.

write(fil, sep=' ', mode='w')

Write a Geometry to a .pgf file.

If fil is a string, a file with that name is opened. Else fil should be an open file. The Geometry is then written to that file in a native format, using sep as separator between the coordinates. If fil is a string, the file is closed prior to returning.

class curve.NaturalSpline(coords, closed=False, endzerocurv=False)

A class representing a natural spline.

endPoints()

Return start and end points of the curve.

Returns a Coords with two points, or None if the curve is closed.

sub_points_2(t, j)

Return the points at values,parts given by zip(t,j)

t and j can both be arrays, but should have the same length.

sub_directions(t, j)

Return the directions at values t in part j

t can be an array of parameter values, j is a single segment number.

sub_directions_2(t, j)

Return the directions at values,parts given by zip(t,j)

t and j can both be arrays, but should have the same length.

localParam(t)

Split global parameter value in part number and local parameter

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.

Returns a tuple of arrays i,t, where i are the (integer) part numbers and t the local parameter values (between 0 and 1).

addNoise(*args, **kargs)

Apply ‘addNoise’ transformation to the Geometry object.

See coords.Coords.addNoise() for details.

affine(*args, **kargs)

Apply ‘affine’ transformation to the Geometry object.

See coords.Coords.affine() for details.

align(*args, **kargs)

Apply ‘align’ transformation to the Geometry object.

See coords.Coords.align() for details.

bump(*args, **kargs)

Apply ‘bump’ transformation to the Geometry object.

See coords.Coords.bump() for details.

bump1(*args, **kargs)

Apply ‘bump1’ transformation to the Geometry object.

See coords.Coords.bump1() for details.

bump2(*args, **kargs)

Apply ‘bump2’ transformation to the Geometry object.

See coords.Coords.bump2() for details.

centered(*args, **kargs)

Apply ‘centered’ transformation to the Geometry object.

See coords.Coords.centered() for details.

cylindrical(*args, **kargs)

Apply ‘cylindrical’ transformation to the Geometry object.

See coords.Coords.cylindrical() for details.

egg(*args, **kargs)

Apply ‘egg’ transformation to the Geometry object.

See coords.Coords.egg() for details.

flare(*args, **kargs)

Apply ‘flare’ transformation to the Geometry object.

See coords.Coords.flare() for details.

hyperCylindrical(*args, **kargs)

Apply ‘hyperCylindrical’ transformation to the Geometry object.

See coords.Coords.hyperCylindrical() for details.

isopar(*args, **kargs)

Apply ‘isopar’ transformation to the Geometry object.

See coords.Coords.isopar() for details.

map(*args, **kargs)

Apply ‘map’ transformation to the Geometry object.

See coords.Coords.map() for details.

map1(*args, **kargs)

Apply ‘map1’ transformation to the Geometry object.

See coords.Coords.map1() for details.

mapd(*args, **kargs)

Apply ‘mapd’ transformation to the Geometry object.

See coords.Coords.mapd() for details.

position(*args, **kargs)

Apply ‘position’ transformation to the Geometry object.

See coords.Coords.position() for details.

projectOnCylinder(*args, **kargs)

Apply ‘projectOnCylinder’ transformation to the Geometry object.

See coords.Coords.projectOnCylinder() for details.

projectOnPlane(*args, **kargs)

Apply ‘projectOnPlane’ transformation to the Geometry object.

See coords.Coords.projectOnPlane() for details.

projectOnSphere(*args, **kargs)

Apply ‘projectOnSphere’ transformation to the Geometry object.

See coords.Coords.projectOnSphere() for details.

reflect(*args, **kargs)

Apply ‘reflect’ transformation to the Geometry object.

See coords.Coords.reflect() for details.

replace(*args, **kargs)

Apply ‘replace’ transformation to the Geometry object.

See coords.Coords.replace() for details.

rollAxes(*args, **kargs)

Apply ‘rollAxes’ transformation to the Geometry object.

See coords.Coords.rollAxes() for details.

rot(*args, **kargs)

Apply ‘rotate’ transformation to the Geometry object.

See coords.Coords.rotate() for details.

rotate(*args, **kargs)

Apply ‘rotate’ transformation to the Geometry object.

See coords.Coords.rotate() for details.

scale(*args, **kargs)

Apply ‘scale’ transformation to the Geometry object.

See coords.Coords.scale() for details.

shear(*args, **kargs)

Apply ‘shear’ transformation to the Geometry object.

See coords.Coords.shear() for details.

spherical(*args, **kargs)

Apply ‘spherical’ transformation to the Geometry object.

See coords.Coords.spherical() for details.

superSpherical(*args, **kargs)

Apply ‘superSpherical’ transformation to the Geometry object.

See coords.Coords.superSpherical() for details.

swapAxes(*args, **kargs)

Apply ‘swapAxes’ transformation to the Geometry object.

See coords.Coords.swapAxes() for details.

toCylindrical(*args, **kargs)

Apply ‘toCylindrical’ transformation to the Geometry object.

See coords.Coords.toCylindrical() for details.

toSpherical(*args, **kargs)

Apply ‘toSpherical’ transformation to the Geometry object.

See coords.Coords.toSpherical() for details.

transformCS(*args, **kargs)

Apply ‘transformCS’ transformation to the Geometry object.

See coords.Coords.transformCS() for details.

translate(*args, **kargs)

Apply ‘translate’ transformation to the Geometry object.

See coords.Coords.translate() for details.

trl(*args, **kargs)

Apply ‘translate’ transformation to the Geometry object.

See coords.Coords.translate() for details.

pointsAt(t, normalized=False, return_position=False)

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.

Returns a Coords with the coordinates of the points.

If normalized is True, the parameter values are give in a normalized space where 0 is the start of the curve and 1 is the end.

If return_position is True, also returns the part numbers on which the point are lying and the local parameter values.

nelems()

Return the number of elements in the Geometry.

This method should be re-implemented by the derived classes. For the (empty) Geometry class it always returns 0.

directionsAt(t)

Return the directions 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.

subPoints(div=10, extend=[0.0, 0.0])

Return a sequence of points on the Curve.

  • div: int or a list of floats (usually in the range [0.,1.]) If div is an integer, a list of floats is constructed by dividing the range [0.,1.] into div equal parts. The list of floats then specifies a set of parameter values for which points at in each part are returned. The points are returned in a single Coords in order of the parts.

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.

toProp(prop)

Converts the argument into a legal set of properties for the object.

The conversion involves resizing the argument to a 1D array of length self.nelems(), and converting the data type to integer.

getCoords()

Get the coords data.

Returns the full array of coordinates stored in the Geometry object. Note that subclasses may store more points in this array than are used to define the geometry.

split(split=None)

Split a curve into a list of partial curves

split is a list of integer values specifying the node numbers where the curve is to be split. As a convenience, a single int may be given if the curve is to be split at a single node, or None to split all all nodes.

Returns a list of open curves of the same type as the original.

length()

Return the total length of the curve.

This is only available for curves that implement the ‘lengths’ method.

approx(ndiv=None, ntot=None)

Return a PolyLine approximation of the curve

Parameters:

  • ndiv: int: number of straight segments to use over each part of the curve. This is only used if
  • ntot: int: number of straight segments to use over the total length of the curve.

Returns a PolyLine approximation for the curve. C.approx(ndiv=n) returns an approximation with ndiv segments over each part of the curve. This may results in segments with very different lengths. C.approx(ntot=n) returns an approximation with ntot segments over the total length of the curve. This produces more equally sized segments, but the internal end points of the curve parts may not be on the approximating Polyline.

level()

Return the dimensionality of the Geometry, or -1 if unknown

frenet(ndiv=None, ntot=None, upvector=None, avgdir=True, compensate=False)

Return points and Frenet frame along the curve.

A PolyLine approximation for the curve is constructed, using the Curve.approx() method with the arguments ndiv and ntot. Then Frenet frames are constructed with PolyLine.movingFrenet() using the remaining arguments. The resulting PolyLine points and Frenet frames are returned.

Parameters:

  • upvector: (3,) vector: a vector normal to the (tangent,normal) plane at the first point of the curve. It defines the binormal at the first point. If not specified it is set to the shorted distance through the set of 10 first points.

  • avgdir: bool or array. If True (default), the tangential vector is set to the average direction of the two segments ending at a node. If False, the tangent vectors will be those of the line segment starting at the points. The tangential vector can also be set by the user by specifying an array with the matching number of vectors.

  • compensate: bool: If True, adds a compensation algorithm if the curve is closed. For a closed curve the moving Frenet algorithm can be continued back to the first point. If the resulting binormial does not coincide with the starting one, some torsion is added to the end portions of the curve to make the two binormals coincide.

    This feature is off by default because it is currently experimental and is likely to change in future. It may also form the base for setting the starting as well as the ending binormal.

Returns:

  • X: a Coords with npts points on the curve
  • T: normalized tangent vector to the curve at npts points
  • N: normalized normal vector to the curve at npts points
  • B: normalized binormal vector to the curve at npts points
copy()

Return a deep copy of the Geometry object.

The returned object is an exact copy of the input, but has all of its data independent of the former.

splitProp(prop=None)

Partition a Geometry (Formex/Mesh) according to the values in prop.

Parameters:

  • prop: an int array with length self.nelems(), or None. If None, the prop attribute of the Geometry is used.

Returns a list of Geometry objects of the same type as the input. Each object contains all the elements having the same value of prop. The number of objects in the list is equal to the number of unique values in prop. The list is sorted in ascending order of their prop value.

It prop is None and the the object has no prop attribute, an empty list is returned.

resized(size=1.0, tol=1e-05)

Return a copy of the Geometry scaled to the given size.

size can be a single value or a list of three values for the three coordinate directions. If it is a single value, all directions are scaled to the same size. Directions for which the geometry has a size smaller than tol times the maximum size are not rescaled.

approximate(nseg, equidistant=True, npre=100)

Approximate a Curve with a PolyLine of n segments

Parameters:

  • nseg: number of straight segments of the resulting PolyLine
  • equidistant: if True (default) the points are spaced almost equidistantly over the curve. If False, the points are spread equally over the parameter space.
  • npre: only used when equidistant is True: number of segments per part of the curve used in the pre-approximation. This pre- approximation is currently required to compute curve lengths.

Note

This is an alternative for Curve.approx, and may replace it in future.

toFormex(*args, **kargs)

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.

setProp(p=None)

Create or destroy the property array for the Formex.

A property array is a rank-1 integer array with dimension equal to the number of elements in the Formex (first dimension of data). You can specify a single value or a list/array of integer values. If the number of passed values is less than the number of elements, they wil be repeated. If you give more, they will be ignored.

If a value None is given, the properties are removed from the Formex.

write(fil, sep=' ', mode='w')

Write a Geometry to a .pgf file.

If fil is a string, a file with that name is opened. Else fil should be an open file. The Geometry is then written to that file in a native format, using sep as separator between the coordinates. If fil is a string, the file is closed prior to returning.

class curve.Arc3(coords)

A class representing a circular arc.

endPoints()

Return start and end points of the curve.

Returns a Coords with two points, or None if the curve is closed.

sub_points_2(t, j)

Return the points at values,parts given by zip(t,j)

t and j can both be arrays, but should have the same length.

sub_directions(t, j)

Return the directions at values t in part j

t can be an array of parameter values, j is a single segment number.

sub_directions_2(t, j)

Return the directions at values,parts given by zip(t,j)

t and j can both be arrays, but should have the same length.

localParam(t)

Split global parameter value in part number and local parameter

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.

Returns a tuple of arrays i,t, where i are the (integer) part numbers and t the local parameter values (between 0 and 1).

addNoise(*args, **kargs)

Apply ‘addNoise’ transformation to the Geometry object.

See coords.Coords.addNoise() for details.

affine(*args, **kargs)

Apply ‘affine’ transformation to the Geometry object.

See coords.Coords.affine() for details.

align(*args, **kargs)

Apply ‘align’ transformation to the Geometry object.

See coords.Coords.align() for details.

bump(*args, **kargs)

Apply ‘bump’ transformation to the Geometry object.

See coords.Coords.bump() for details.

bump1(*args, **kargs)

Apply ‘bump1’ transformation to the Geometry object.

See coords.Coords.bump1() for details.

bump2(*args, **kargs)

Apply ‘bump2’ transformation to the Geometry object.

See coords.Coords.bump2() for details.

centered(*args, **kargs)

Apply ‘centered’ transformation to the Geometry object.

See coords.Coords.centered() for details.

cylindrical(*args, **kargs)

Apply ‘cylindrical’ transformation to the Geometry object.

See coords.Coords.cylindrical() for details.

egg(*args, **kargs)

Apply ‘egg’ transformation to the Geometry object.

See coords.Coords.egg() for details.

flare(*args, **kargs)

Apply ‘flare’ transformation to the Geometry object.

See coords.Coords.flare() for details.

hyperCylindrical(*args, **kargs)

Apply ‘hyperCylindrical’ transformation to the Geometry object.

See coords.Coords.hyperCylindrical() for details.

isopar(*args, **kargs)

Apply ‘isopar’ transformation to the Geometry object.

See coords.Coords.isopar() for details.

map(*args, **kargs)

Apply ‘map’ transformation to the Geometry object.

See coords.Coords.map() for details.

map1(*args, **kargs)

Apply ‘map1’ transformation to the Geometry object.

See coords.Coords.map1() for details.

mapd(*args, **kargs)

Apply ‘mapd’ transformation to the Geometry object.

See coords.Coords.mapd() for details.

position(*args, **kargs)

Apply ‘position’ transformation to the Geometry object.

See coords.Coords.position() for details.

projectOnCylinder(*args, **kargs)

Apply ‘projectOnCylinder’ transformation to the Geometry object.

See coords.Coords.projectOnCylinder() for details.

projectOnPlane(*args, **kargs)

Apply ‘projectOnPlane’ transformation to the Geometry object.

See coords.Coords.projectOnPlane() for details.

projectOnSphere(*args, **kargs)

Apply ‘projectOnSphere’ transformation to the Geometry object.

See coords.Coords.projectOnSphere() for details.

reflect(*args, **kargs)

Apply ‘reflect’ transformation to the Geometry object.

See coords.Coords.reflect() for details.

replace(*args, **kargs)

Apply ‘replace’ transformation to the Geometry object.

See coords.Coords.replace() for details.

rollAxes(*args, **kargs)

Apply ‘rollAxes’ transformation to the Geometry object.

See coords.Coords.rollAxes() for details.

rot(*args, **kargs)

Apply ‘rotate’ transformation to the Geometry object.

See coords.Coords.rotate() for details.

rotate(*args, **kargs)

Apply ‘rotate’ transformation to the Geometry object.

See coords.Coords.rotate() for details.

scale(*args, **kargs)

Apply ‘scale’ transformation to the Geometry object.

See coords.Coords.scale() for details.

shear(*args, **kargs)

Apply ‘shear’ transformation to the Geometry object.

See coords.Coords.shear() for details.

spherical(*args, **kargs)

Apply ‘spherical’ transformation to the Geometry object.

See coords.Coords.spherical() for details.

superSpherical(*args, **kargs)

Apply ‘superSpherical’ transformation to the Geometry object.

See coords.Coords.superSpherical() for details.

swapAxes(*args, **kargs)

Apply ‘swapAxes’ transformation to the Geometry object.

See coords.Coords.swapAxes() for details.

toCylindrical(*args, **kargs)

Apply ‘toCylindrical’ transformation to the Geometry object.

See coords.Coords.toCylindrical() for details.

toSpherical(*args, **kargs)

Apply ‘toSpherical’ transformation to the Geometry object.

See coords.Coords.toSpherical() for details.

transformCS(*args, **kargs)

Apply ‘transformCS’ transformation to the Geometry object.

See coords.Coords.transformCS() for details.

translate(*args, **kargs)

Apply ‘translate’ transformation to the Geometry object.

See coords.Coords.translate() for details.

trl(*args, **kargs)

Apply ‘translate’ transformation to the Geometry object.

See coords.Coords.translate() for details.

pointsAt(t, normalized=False, return_position=False)

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.

Returns a Coords with the coordinates of the points.

If normalized is True, the parameter values are give in a normalized space where 0 is the start of the curve and 1 is the end.

If return_position is True, also returns the part numbers on which the point are lying and the local parameter values.

nelems()

Return the number of elements in the Geometry.

This method should be re-implemented by the derived classes. For the (empty) Geometry class it always returns 0.

directionsAt(t)

Return the directions 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.

subPoints(div=10, extend=[0.0, 0.0])

Return a sequence of points on the Curve.

  • div: int or a list of floats (usually in the range [0.,1.]) If div is an integer, a list of floats is constructed by dividing the range [0.,1.] into div equal parts. The list of floats then specifies a set of parameter values for which points at in each part are returned. The points are returned in a single Coords in order of the parts.

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.

toProp(prop)

Converts the argument into a legal set of properties for the object.

The conversion involves resizing the argument to a 1D array of length self.nelems(), and converting the data type to integer.

getCoords()

Get the coords data.

Returns the full array of coordinates stored in the Geometry object. Note that subclasses may store more points in this array than are used to define the geometry.

split(split=None)

Split a curve into a list of partial curves

split is a list of integer values specifying the node numbers where the curve is to be split. As a convenience, a single int may be given if the curve is to be split at a single node, or None to split all all nodes.

Returns a list of open curves of the same type as the original.

length()

Return the total length of the curve.

This is only available for curves that implement the ‘lengths’ method.

approx(ndiv=None, ntot=None)

Return a PolyLine approximation of the curve

Parameters:

  • ndiv: int: number of straight segments to use over each part of the curve. This is only used if
  • ntot: int: number of straight segments to use over the total length of the curve.

Returns a PolyLine approximation for the curve. C.approx(ndiv=n) returns an approximation with ndiv segments over each part of the curve. This may results in segments with very different lengths. C.approx(ntot=n) returns an approximation with ntot segments over the total length of the curve. This produces more equally sized segments, but the internal end points of the curve parts may not be on the approximating Polyline.

level()

Return the dimensionality of the Geometry, or -1 if unknown

frenet(ndiv=None, ntot=None, upvector=None, avgdir=True, compensate=False)

Return points and Frenet frame along the curve.

A PolyLine approximation for the curve is constructed, using the Curve.approx() method with the arguments ndiv and ntot. Then Frenet frames are constructed with PolyLine.movingFrenet() using the remaining arguments. The resulting PolyLine points and Frenet frames are returned.

Parameters:

  • upvector: (3,) vector: a vector normal to the (tangent,normal) plane at the first point of the curve. It defines the binormal at the first point. If not specified it is set to the shorted distance through the set of 10 first points.

  • avgdir: bool or array. If True (default), the tangential vector is set to the average direction of the two segments ending at a node. If False, the tangent vectors will be those of the line segment starting at the points. The tangential vector can also be set by the user by specifying an array with the matching number of vectors.

  • compensate: bool: If True, adds a compensation algorithm if the curve is closed. For a closed curve the moving Frenet algorithm can be continued back to the first point. If the resulting binormial does not coincide with the starting one, some torsion is added to the end portions of the curve to make the two binormals coincide.

    This feature is off by default because it is currently experimental and is likely to change in future. It may also form the base for setting the starting as well as the ending binormal.

Returns:

  • X: a Coords with npts points on the curve
  • T: normalized tangent vector to the curve at npts points
  • N: normalized normal vector to the curve at npts points
  • B: normalized binormal vector to the curve at npts points
copy()

Return a deep copy of the Geometry object.

The returned object is an exact copy of the input, but has all of its data independent of the former.

splitProp(prop=None)

Partition a Geometry (Formex/Mesh) according to the values in prop.

Parameters:

  • prop: an int array with length self.nelems(), or None. If None, the prop attribute of the Geometry is used.

Returns a list of Geometry objects of the same type as the input. Each object contains all the elements having the same value of prop. The number of objects in the list is equal to the number of unique values in prop. The list is sorted in ascending order of their prop value.

It prop is None and the the object has no prop attribute, an empty list is returned.

resized(size=1.0, tol=1e-05)

Return a copy of the Geometry scaled to the given size.

size can be a single value or a list of three values for the three coordinate directions. If it is a single value, all directions are scaled to the same size. Directions for which the geometry has a size smaller than tol times the maximum size are not rescaled.

approximate(nseg, equidistant=True, npre=100)

Approximate a Curve with a PolyLine of n segments

Parameters:

  • nseg: number of straight segments of the resulting PolyLine
  • equidistant: if True (default) the points are spaced almost equidistantly over the curve. If False, the points are spread equally over the parameter space.
  • npre: only used when equidistant is True: number of segments per part of the curve used in the pre-approximation. This pre- approximation is currently required to compute curve lengths.

Note

This is an alternative for Curve.approx, and may replace it in future.

toFormex(*args, **kargs)

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.

setProp(p=None)

Create or destroy the property array for the Formex.

A property array is a rank-1 integer array with dimension equal to the number of elements in the Formex (first dimension of data). You can specify a single value or a list/array of integer values. If the number of passed values is less than the number of elements, they wil be repeated. If you give more, they will be ignored.

If a value None is given, the properties are removed from the Formex.

write(fil, sep=' ', mode='w')

Write a Geometry to a .pgf file.

If fil is a string, a file with that name is opened. Else fil should be an open file. The Geometry is then written to that file in a native format, using sep as separator between the coordinates. If fil is a string, the file is closed prior to returning.

class curve.Arc(coords=None, center=None, radius=None, angles=None, angle_spec=0.017453292519943295)

A class representing a circular arc.

The arc can be specified by 3 points (begin, center, end) or by center, radius and two angles. In the latter case, the arc lies in a plane parallel to the x,y plane. If specified by 3 colinear points, the plane of the circle will be parallel to the x,y plane if the points are in such plane, else the plane will be parallel to the z-axis.

endPoints()

Return start and end points of the curve.

Returns a Coords with two points, or None if the curve is closed.

sub_points_2(t, j)

Return the points at values,parts given by zip(t,j)

t and j can both be arrays, but should have the same length.

sub_directions_2(t, j)

Return the directions at values,parts given by zip(t,j)

t and j can both be arrays, but should have the same length.

localParam(t)

Split global parameter value in part number and local parameter

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.

Returns a tuple of arrays i,t, where i are the (integer) part numbers and t the local parameter values (between 0 and 1).

addNoise(*args, **kargs)

Apply ‘addNoise’ transformation to the Geometry object.

See coords.Coords.addNoise() for details.

affine(*args, **kargs)

Apply ‘affine’ transformation to the Geometry object.

See coords.Coords.affine() for details.

align(*args, **kargs)

Apply ‘align’ transformation to the Geometry object.

See coords.Coords.align() for details.

bump(*args, **kargs)

Apply ‘bump’ transformation to the Geometry object.

See coords.Coords.bump() for details.

bump1(*args, **kargs)

Apply ‘bump1’ transformation to the Geometry object.

See coords.Coords.bump1() for details.

bump2(*args, **kargs)

Apply ‘bump2’ transformation to the Geometry object.

See coords.Coords.bump2() for details.

centered(*args, **kargs)

Apply ‘centered’ transformation to the Geometry object.

See coords.Coords.centered() for details.

cylindrical(*args, **kargs)

Apply ‘cylindrical’ transformation to the Geometry object.

See coords.Coords.cylindrical() for details.

egg(*args, **kargs)

Apply ‘egg’ transformation to the Geometry object.

See coords.Coords.egg() for details.

flare(*args, **kargs)

Apply ‘flare’ transformation to the Geometry object.

See coords.Coords.flare() for details.

hyperCylindrical(*args, **kargs)

Apply ‘hyperCylindrical’ transformation to the Geometry object.

See coords.Coords.hyperCylindrical() for details.

isopar(*args, **kargs)

Apply ‘isopar’ transformation to the Geometry object.

See coords.Coords.isopar() for details.

map(*args, **kargs)

Apply ‘map’ transformation to the Geometry object.

See coords.Coords.map() for details.

map1(*args, **kargs)

Apply ‘map1’ transformation to the Geometry object.

See coords.Coords.map1() for details.

mapd(*args, **kargs)

Apply ‘mapd’ transformation to the Geometry object.

See coords.Coords.mapd() for details.

position(*args, **kargs)

Apply ‘position’ transformation to the Geometry object.

See coords.Coords.position() for details.

projectOnCylinder(*args, **kargs)

Apply ‘projectOnCylinder’ transformation to the Geometry object.

See coords.Coords.projectOnCylinder() for details.

projectOnPlane(*args, **kargs)

Apply ‘projectOnPlane’ transformation to the Geometry object.

See coords.Coords.projectOnPlane() for details.

projectOnSphere(*args, **kargs)

Apply ‘projectOnSphere’ transformation to the Geometry object.

See coords.Coords.projectOnSphere() for details.

reflect(*args, **kargs)

Apply ‘reflect’ transformation to the Geometry object.

See coords.Coords.reflect() for details.

replace(*args, **kargs)

Apply ‘replace’ transformation to the Geometry object.

See coords.Coords.replace() for details.

rollAxes(*args, **kargs)

Apply ‘rollAxes’ transformation to the Geometry object.

See coords.Coords.rollAxes() for details.

rot(*args, **kargs)

Apply ‘rotate’ transformation to the Geometry object.

See coords.Coords.rotate() for details.

rotate(*args, **kargs)

Apply ‘rotate’ transformation to the Geometry object.

See coords.Coords.rotate() for details.

scale(*args, **kargs)

Apply ‘scale’ transformation to the Geometry object.

See coords.Coords.scale() for details.

shear(*args, **kargs)

Apply ‘shear’ transformation to the Geometry object.

See coords.Coords.shear() for details.

spherical(*args, **kargs)

Apply ‘spherical’ transformation to the Geometry object.

See coords.Coords.spherical() for details.

superSpherical(*args, **kargs)

Apply ‘superSpherical’ transformation to the Geometry object.

See coords.Coords.superSpherical() for details.

swapAxes(*args, **kargs)

Apply ‘swapAxes’ transformation to the Geometry object.

See coords.Coords.swapAxes() for details.

toCylindrical(*args, **kargs)

Apply ‘toCylindrical’ transformation to the Geometry object.

See coords.Coords.toCylindrical() for details.

toSpherical(*args, **kargs)

Apply ‘toSpherical’ transformation to the Geometry object.

See coords.Coords.toSpherical() for details.

transformCS(*args, **kargs)

Apply ‘transformCS’ transformation to the Geometry object.

See coords.Coords.transformCS() for details.

translate(*args, **kargs)

Apply ‘translate’ transformation to the Geometry object.

See coords.Coords.translate() for details.

trl(*args, **kargs)

Apply ‘translate’ transformation to the Geometry object.

See coords.Coords.translate() for details.

pointsAt(t, normalized=False, return_position=False)

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.

Returns a Coords with the coordinates of the points.

If normalized is True, the parameter values are give in a normalized space where 0 is the start of the curve and 1 is the end.

If return_position is True, also returns the part numbers on which the point are lying and the local parameter values.

nelems()

Return the number of elements in the Geometry.

This method should be re-implemented by the derived classes. For the (empty) Geometry class it always returns 0.

directionsAt(t)

Return the directions 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.

subPoints(div=10, extend=[0.0, 0.0])

Return a sequence of points on the Curve.

  • div: int or a list of floats (usually in the range [0.,1.]) If div is an integer, a list of floats is constructed by dividing the range [0.,1.] into div equal parts. The list of floats then specifies a set of parameter values for which points at in each part are returned. The points are returned in a single Coords in order of the parts.

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.

toProp(prop)

Converts the argument into a legal set of properties for the object.

The conversion involves resizing the argument to a 1D array of length self.nelems(), and converting the data type to integer.

getCoords()

Get the coords data.

Returns the full array of coordinates stored in the Geometry object. Note that subclasses may store more points in this array than are used to define the geometry.

split(split=None)

Split a curve into a list of partial curves

split is a list of integer values specifying the node numbers where the curve is to be split. As a convenience, a single int may be given if the curve is to be split at a single node, or None to split all all nodes.

Returns a list of open curves of the same type as the original.

length()

Return the total length of the curve.

This is only available for curves that implement the ‘lengths’ method.

level()

Return the dimensionality of the Geometry, or -1 if unknown

frenet(ndiv=None, ntot=None, upvector=None, avgdir=True, compensate=False)

Return points and Frenet frame along the curve.

A PolyLine approximation for the curve is constructed, using the Curve.approx() method with the arguments ndiv and ntot. Then Frenet frames are constructed with PolyLine.movingFrenet() using the remaining arguments. The resulting PolyLine points and Frenet frames are returned.

Parameters:

  • upvector: (3,) vector: a vector normal to the (tangent,normal) plane at the first point of the curve. It defines the binormal at the first point. If not specified it is set to the shorted distance through the set of 10 first points.

  • avgdir: bool or array. If True (default), the tangential vector is set to the average direction of the two segments ending at a node. If False, the tangent vectors will be those of the line segment starting at the points. The tangential vector can also be set by the user by specifying an array with the matching number of vectors.

  • compensate: bool: If True, adds a compensation algorithm if the curve is closed. For a closed curve the moving Frenet algorithm can be continued back to the first point. If the resulting binormial does not coincide with the starting one, some torsion is added to the end portions of the curve to make the two binormals coincide.

    This feature is off by default because it is currently experimental and is likely to change in future. It may also form the base for setting the starting as well as the ending binormal.

Returns:

  • X: a Coords with npts points on the curve
  • T: normalized tangent vector to the curve at npts points
  • N: normalized normal vector to the curve at npts points
  • B: normalized binormal vector to the curve at npts points
copy()

Return a deep copy of the Geometry object.

The returned object is an exact copy of the input, but has all of its data independent of the former.

splitProp(prop=None)

Partition a Geometry (Formex/Mesh) according to the values in prop.

Parameters:

  • prop: an int array with length self.nelems(), or None. If None, the prop attribute of the Geometry is used.

Returns a list of Geometry objects of the same type as the input. Each object contains all the elements having the same value of prop. The number of objects in the list is equal to the number of unique values in prop. The list is sorted in ascending order of their prop value.

It prop is None and the the object has no prop attribute, an empty list is returned.

resized(size=1.0, tol=1e-05)

Return a copy of the Geometry scaled to the given size.

size can be a single value or a list of three values for the three coordinate directions. If it is a single value, all directions are scaled to the same size. Directions for which the geometry has a size smaller than tol times the maximum size are not rescaled.

approximate(nseg, equidistant=True, npre=100)

Approximate a Curve with a PolyLine of n segments

Parameters:

  • nseg: number of straight segments of the resulting PolyLine
  • equidistant: if True (default) the points are spaced almost equidistantly over the curve. If False, the points are spread equally over the parameter space.
  • npre: only used when equidistant is True: number of segments per part of the curve used in the pre-approximation. This pre- approximation is currently required to compute curve lengths.

Note

This is an alternative for Curve.approx, and may replace it in future.

toFormex(*args, **kargs)

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.

setProp(p=None)

Create or destroy the property array for the Formex.

A property array is a rank-1 integer array with dimension equal to the number of elements in the Formex (first dimension of data). You can specify a single value or a list/array of integer values. If the number of passed values is less than the number of elements, they wil be repeated. If you give more, they will be ignored.

If a value None is given, the properties are removed from the Formex.

write(fil, sep=' ', mode='w')

Write a Geometry to a .pgf file.

If fil is a string, a file with that name is opened. Else fil should be an open file. The Geometry is then written to that file in a native format, using sep as separator between the coordinates. If fil is a string, the file is closed prior to returning.

approx(ndiv=None, chordal=0.001)

Return a PolyLine approximation of the Arc.

Approximates the Arc by a sequence of inscribed straight line segments.

If ndiv is specified, the arc is divided in pecisely ndiv segments.

If ndiv is not given, the number of segments is determined from the chordal distance tolerance. It will guarantee that the distance of any point of the arc to the chordal approximation is less or equal than chordal times the radius of the arc.

class curve.Spiral(turns=2.0, nparts=100, rfunc=None)

A class representing a spiral curve.

endPoints()

Return start and end points of the curve.

Returns a Coords with two points, or None if the curve is closed.

sub_points(t, j)

Return the points at values t in part j

t can be an array of parameter values, j is a single segment number.

sub_points_2(t, j)

Return the points at values,parts given by zip(t,j)

t and j can both be arrays, but should have the same length.

sub_directions(t, j)

Return the directions at values t in part j

t can be an array of parameter values, j is a single segment number.

sub_directions_2(t, j)

Return the directions at values,parts given by zip(t,j)

t and j can both be arrays, but should have the same length.

localParam(t)

Split global parameter value in part number and local parameter

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.

Returns a tuple of arrays i,t, where i are the (integer) part numbers and t the local parameter values (between 0 and 1).

addNoise(*args, **kargs)

Apply ‘addNoise’ transformation to the Geometry object.

See coords.Coords.addNoise() for details.

affine(*args, **kargs)

Apply ‘affine’ transformation to the Geometry object.

See coords.Coords.affine() for details.

align(*args, **kargs)

Apply ‘align’ transformation to the Geometry object.

See coords.Coords.align() for details.

bump(*args, **kargs)

Apply ‘bump’ transformation to the Geometry object.

See coords.Coords.bump() for details.

bump1(*args, **kargs)

Apply ‘bump1’ transformation to the Geometry object.

See coords.Coords.bump1() for details.

bump2(*args, **kargs)

Apply ‘bump2’ transformation to the Geometry object.

See coords.Coords.bump2() for details.

centered(*args, **kargs)

Apply ‘centered’ transformation to the Geometry object.

See coords.Coords.centered() for details.

cylindrical(*args, **kargs)

Apply ‘cylindrical’ transformation to the Geometry object.

See coords.Coords.cylindrical() for details.

egg(*args, **kargs)

Apply ‘egg’ transformation to the Geometry object.

See coords.Coords.egg() for details.

flare(*args, **kargs)

Apply ‘flare’ transformation to the Geometry object.

See coords.Coords.flare() for details.

hyperCylindrical(*args, **kargs)

Apply ‘hyperCylindrical’ transformation to the Geometry object.

See coords.Coords.hyperCylindrical() for details.

isopar(*args, **kargs)

Apply ‘isopar’ transformation to the Geometry object.

See coords.Coords.isopar() for details.

map(*args, **kargs)

Apply ‘map’ transformation to the Geometry object.

See coords.Coords.map() for details.

map1(*args, **kargs)

Apply ‘map1’ transformation to the Geometry object.

See coords.Coords.map1() for details.

mapd(*args, **kargs)

Apply ‘mapd’ transformation to the Geometry object.

See coords.Coords.mapd() for details.

position(*args, **kargs)

Apply ‘position’ transformation to the Geometry object.

See coords.Coords.position() for details.

projectOnCylinder(*args, **kargs)

Apply ‘projectOnCylinder’ transformation to the Geometry object.

See coords.Coords.projectOnCylinder() for details.

projectOnPlane(*args, **kargs)

Apply ‘projectOnPlane’ transformation to the Geometry object.

See coords.Coords.projectOnPlane() for details.

projectOnSphere(*args, **kargs)

Apply ‘projectOnSphere’ transformation to the Geometry object.

See coords.Coords.projectOnSphere() for details.

reflect(*args, **kargs)

Apply ‘reflect’ transformation to the Geometry object.

See coords.Coords.reflect() for details.

replace(*args, **kargs)

Apply ‘replace’ transformation to the Geometry object.

See coords.Coords.replace() for details.

rollAxes(*args, **kargs)

Apply ‘rollAxes’ transformation to the Geometry object.

See coords.Coords.rollAxes() for details.

rot(*args, **kargs)

Apply ‘rotate’ transformation to the Geometry object.

See coords.Coords.rotate() for details.

rotate(*args, **kargs)

Apply ‘rotate’ transformation to the Geometry object.

See coords.Coords.rotate() for details.

scale(*args, **kargs)

Apply ‘scale’ transformation to the Geometry object.

See coords.Coords.scale() for details.

shear(*args, **kargs)

Apply ‘shear’ transformation to the Geometry object.

See coords.Coords.shear() for details.

spherical(*args, **kargs)

Apply ‘spherical’ transformation to the Geometry object.

See coords.Coords.spherical() for details.

superSpherical(*args, **kargs)

Apply ‘superSpherical’ transformation to the Geometry object.

See coords.Coords.superSpherical() for details.

swapAxes(*args, **kargs)

Apply ‘swapAxes’ transformation to the Geometry object.

See coords.Coords.swapAxes() for details.

toCylindrical(*args, **kargs)

Apply ‘toCylindrical’ transformation to the Geometry object.

See coords.Coords.toCylindrical() for details.

toSpherical(*args, **kargs)

Apply ‘toSpherical’ transformation to the Geometry object.

See coords.Coords.toSpherical() for details.

transformCS(*args, **kargs)

Apply ‘transformCS’ transformation to the Geometry object.

See coords.Coords.transformCS() for details.

translate(*args, **kargs)

Apply ‘translate’ transformation to the Geometry object.

See coords.Coords.translate() for details.

trl(*args, **kargs)

Apply ‘translate’ transformation to the Geometry object.

See coords.Coords.translate() for details.

pointsAt(t, normalized=False, return_position=False)

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.

Returns a Coords with the coordinates of the points.

If normalized is True, the parameter values are give in a normalized space where 0 is the start of the curve and 1 is the end.

If return_position is True, also returns the part numbers on which the point are lying and the local parameter values.

nelems()

Return the number of elements in the Geometry.

This method should be re-implemented by the derived classes. For the (empty) Geometry class it always returns 0.

directionsAt(t)

Return the directions 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.

subPoints(div=10, extend=[0.0, 0.0])

Return a sequence of points on the Curve.

  • div: int or a list of floats (usually in the range [0.,1.]) If div is an integer, a list of floats is constructed by dividing the range [0.,1.] into div equal parts. The list of floats then specifies a set of parameter values for which points at in each part are returned. The points are returned in a single Coords in order of the parts.

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.

toProp(prop)

Converts the argument into a legal set of properties for the object.

The conversion involves resizing the argument to a 1D array of length self.nelems(), and converting the data type to integer.

getCoords()

Get the coords data.

Returns the full array of coordinates stored in the Geometry object. Note that subclasses may store more points in this array than are used to define the geometry.

split(split=None)

Split a curve into a list of partial curves

split is a list of integer values specifying the node numbers where the curve is to be split. As a convenience, a single int may be given if the curve is to be split at a single node, or None to split all all nodes.

Returns a list of open curves of the same type as the original.

length()

Return the total length of the curve.

This is only available for curves that implement the ‘lengths’ method.

approx(ndiv=None, ntot=None)

Return a PolyLine approximation of the curve

Parameters:

  • ndiv: int: number of straight segments to use over each part of the curve. This is only used if
  • ntot: int: number of straight segments to use over the total length of the curve.

Returns a PolyLine approximation for the curve. C.approx(ndiv=n) returns an approximation with ndiv segments over each part of the curve. This may results in segments with very different lengths. C.approx(ntot=n) returns an approximation with ntot segments over the total length of the curve. This produces more equally sized segments, but the internal end points of the curve parts may not be on the approximating Polyline.

level()

Return the dimensionality of the Geometry, or -1 if unknown

frenet(ndiv=None, ntot=None, upvector=None, avgdir=True, compensate=False)

Return points and Frenet frame along the curve.

A PolyLine approximation for the curve is constructed, using the Curve.approx() method with the arguments ndiv and ntot. Then Frenet frames are constructed with PolyLine.movingFrenet() using the remaining arguments. The resulting PolyLine points and Frenet frames are returned.

Parameters:

  • upvector: (3,) vector: a vector normal to the (tangent,normal) plane at the first point of the curve. It defines the binormal at the first point. If not specified it is set to the shorted distance through the set of 10 first points.

  • avgdir: bool or array. If True (default), the tangential vector is set to the average direction of the two segments ending at a node. If False, the tangent vectors will be those of the line segment starting at the points. The tangential vector can also be set by the user by specifying an array with the matching number of vectors.

  • compensate: bool: If True, adds a compensation algorithm if the curve is closed. For a closed curve the moving Frenet algorithm can be continued back to the first point. If the resulting binormial does not coincide with the starting one, some torsion is added to the end portions of the curve to make the two binormals coincide.

    This feature is off by default because it is currently experimental and is likely to change in future. It may also form the base for setting the starting as well as the ending binormal.

Returns:

  • X: a Coords with npts points on the curve
  • T: normalized tangent vector to the curve at npts points
  • N: normalized normal vector to the curve at npts points
  • B: normalized binormal vector to the curve at npts points
copy()

Return a deep copy of the Geometry object.

The returned object is an exact copy of the input, but has all of its data independent of the former.

splitProp(prop=None)

Partition a Geometry (Formex/Mesh) according to the values in prop.

Parameters:

  • prop: an int array with length self.nelems(), or None. If None, the prop attribute of the Geometry is used.

Returns a list of Geometry objects of the same type as the input. Each object contains all the elements having the same value of prop. The number of objects in the list is equal to the number of unique values in prop. The list is sorted in ascending order of their prop value.

It prop is None and the the object has no prop attribute, an empty list is returned.

resized(size=1.0, tol=1e-05)

Return a copy of the Geometry scaled to the given size.

size can be a single value or a list of three values for the three coordinate directions. If it is a single value, all directions are scaled to the same size. Directions for which the geometry has a size smaller than tol times the maximum size are not rescaled.

approximate(nseg, equidistant=True, npre=100)

Approximate a Curve with a PolyLine of n segments

Parameters:

  • nseg: number of straight segments of the resulting PolyLine
  • equidistant: if True (default) the points are spaced almost equidistantly over the curve. If False, the points are spread equally over the parameter space.
  • npre: only used when equidistant is True: number of segments per part of the curve used in the pre-approximation. This pre- approximation is currently required to compute curve lengths.

Note

This is an alternative for Curve.approx, and may replace it in future.

toFormex(*args, **kargs)

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.

setProp(p=None)

Create or destroy the property array for the Formex.

A property array is a rank-1 integer array with dimension equal to the number of elements in the Formex (first dimension of data). You can specify a single value or a list/array of integer values. If the number of passed values is less than the number of elements, they wil be repeated. If you give more, they will be ignored.

If a value None is given, the properties are removed from the Formex.

write(fil, sep=' ', mode='w')

Write a Geometry to a .pgf file.

If fil is a string, a file with that name is opened. Else fil should be an open file. The Geometry is then written to that file in a native format, using sep as separator between the coordinates. If fil is a string, the file is closed prior to returning.

Functions defined in module curve

curve.circle()

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.

curve.arc2points(x0, x1, R, pos='-')

Create an arc between two points

Given two points x0 and x1, this constructs an arc with radius R through these points. The two points should have the same z-value. The arc will be in a plane parallel with the x-y plane and wind positively around the z-axis when moving along the arc from x0 to x1.

If pos == ‘-‘, the center of the arc will be at the left when going along the chord from x0 to x1, creating an arc smaller than a half-circle. If pos == ‘+’, the center of the arc will be at the right when going along the chord from x0 to x1, creating an arc larger than a half-circle.

If R is too small, an exception is raised.

curve.convertFormexToCurve(self, closed=False)

Convert a Formex to a Curve.

The following Formices can be converted to a Curve: - plex 2 : to PolyLine - plex 3 : to BezierSpline with degree=2 - plex 4 : to BezierSpline