Curve

class pyspline.pyCurve.Curve(**kwargs)[source]

Create an instance of a b-spline curve. There are two ways to initialize the class

  • Creation: Create an instance of the spline class directly by supplying the required information. kwargs MUST contain the following information: k, t, coef.

  • LMS/Interpolation: Create an instance of the spline class by using an interpolating spline to given data points or a LMS spline. The following keyword argument information is required:

    1. k Spline Order

    2. X real array size (N, nDim) of data to fit. OR
      1. x (1D) and s for 1D

      2. x (1D) and y (1D) for 2D spatial curve

      3. x (1D) and y` (1D) and z 1D for 3D spatial curve

    3. s real array of size (N). Optional for nDim >= 2

Parameters:
k{2, 3, 4}

Order for spline. A spline with order \(n\) has at most \(C^{n-2}\) continuity. The \(n-1\) derivative will be piecewise constant.

nCtlint

Number of control points. If this is specified then LMS will be used instead of interpolation.

tarray, list

Knot vector. Used only for creation. Must be size nCtl + k

coefarray, size (nCtl, nDim)

Coefficients to use. Only used for creation. The second dimension determine the spatial order of the spline

Xarary, size (N, ndim)

Full array of data to interpolate/fit

xarray, size (N)

Just x coordinates of data to fit

yarray, size (N)

Just y coordinates of data to fit

zarray, size (N)

Just z coordinates of data to fit

sarray, size(N)

Optional parameter to use. Not required for nDim >=2

nIterint

The number of Hoscheks parameter correction iterations to run. Only used for LMS fitting.

weightarray, size(N)

A array of weighting factors for each fitting point. A value of -1 can be used to exactly constrain a point. By default, all weights are 1.0

derivarray, size (len(derivPtr), nDim)

Array containing derivative information the user wants to use at a particular point. EXPERIMENTAL

derivPtrint, array, size (nDerivPtr)

Array of indices pointing to the index of points in X (or x,y,z), for which the user has supplied a derivative for in deriv. EXPERIMENTAL

derivWeightsarray size(nDerivPtr)

Optional array of the weighting to use for derivatives. A value of -1 can be used to exactly constrain a derivative. EXPERIMENTAL

Examples

>>> x = [0, 0.5, 1.0]
>>> y = [0, 0.25, 1.0]
>>> s = [0., 0.5, 1.0]
>>> # Spatial interpolated seg (k=2 makes this a straight line)
>>> line_seg = Curve(x=x, y=y, k=2)
>>> # With explicit parameter values
>>> line_seg = Curve(x=x, y=y, k=2, s=s)
>>> #Interpolate parabolic curve
>>> parabola = Curve(x=x, y=y, k=3)
>>> #Interpolate parabolic curve with parameter values
>>> parabola = Curve(x=x, y=y, k=3, s=s)
calcGrevillePoints()[source]

Calculate the Greville points

calcInterpolatedGrevillePoints()[source]

Compute greville points, but with additional interpolated knots

computeData(recompute=False)[source]

Compute discrete data that is used for the Tecplot Visualization as well as the data for doing the brute-force checks

Parameters:
recomputebool

If True, recompute the data even if it has already been computed.

getDerivative(s)[source]

Evaluate the derivative of the spline at parametric position, s

Parameters:
sfloat

Parametric location for derivative

Returns:
dsarray

The first derivative. This is an array of size nDim

getLength()[source]

Compute the length of the curve using the Euclidean Norm

Returns:
lengthfloat

Physical length of curve

getSecondDerivative(s)[source]

Evaluate the second derivative of the spline at parametric position, s

Parameters:
sfloat

Parametric location for derivative

Returns:
d2sarray

The second derivative. This is an array of size nDim

getValue(s)[source]

Evaluate the spline at parametric position, s

Parameters:
sfloat or array

Parametric position(s) at which to evaluate the curve.

Returns:
valuesarray of size nDim or an array of size (N, 3)

The evaluated points. If a single scalar s was given, the result with be an array of length nDim (or a scalar if nDim=1). If a vector of s values were given it will be an array of size (N, 3) (or size (N) if ndim=1)

insertKnot(u, r)[source]

Insert at knot in the curve at parametric position u

Parameters:
ufloat

Parametric position to split at

rint

Number of time to insert. Should be > 0.

Returns:
actualRint

The number of times the knot was actually inserted

breakPtint

Index in the knot vector of the new knot(s)

projectCurve(inCurve, nIter=25, eps=1e-10, **kwargs)[source]

Find the minimum distance between this curve (self) and a second curve passed in (inCurve)

Parameters:
inCurvepySpline.curve object

Other curve to use

nIterint

Maximum number of Newton iterations to perform.

epsfloat

Desired parameter tolerance.

sfloat

Initial guess for curve1 (this curve class)

tfloat

Initial guess for inCurve (curve passed in )

Returns:
sfloat

Parametric position on curve1 (this class)

tfloat

Parametric position on curve2 (inCurve)

Dfloat

Minimum distance between this curve and inCurve. It is equivalent to ||self(s) - inCurve(t)||_2.

projectCurveMultiSol(inCurve, nIter=25, eps=1e-10, **kwargs)[source]

Find the minimum distance between this curve (self) and a second curve passed in (inCurve). Try to find as many local solutions as possible

Parameters:
inCurvepySpline.curve object

Other curve to use

nIterint

Maximum number of Newton iterations to perform.

epsfloat

Desired parameter tolerance.

sfloat

Initial guess for curve1 (this curve class)

tfloat

Initial guess for inCurve (curve passed in )

Returns:
sarray

Parametric position(s) on curve1 (this class)

tfloat

Parametric position)s_ on curve2 (inCurve)

Dfloat

Minimum distance(s) between this curve and inCurve. It is equivalent to ||self(s) - inCurve(t)||_2.

projectPoint(x0, nIter=25, eps=1e-10, **kwargs)[source]

Perform a point inversion algorithm. Attempt to find the closest parameter values to the given points x0.

Parameters:
x0array

A point or list of points in nDim space for which the minimum distance to the curve is sought.

nIterint

Maximum number of Newton iterations to perform.

epsfloat

Desired parameter tolerance.

Returns:
sfloat or array

Solution to the point inversion. s are the parametric locations yielding the minimum distance to points x0

Dfloat or array

Physical distances between the points and the curve. This is simply ||curve(s) - X0||_2.

recompute(nIter, computeKnots=True)[source]

Run iterations of Hoscheks Parameter Correction on the current curve

Parameters:
nIterint

The number of parameter correction iterations to run

computeKnotsbool

Flag whether or not the knots should be recomputed

reverse()[source]

Reverse the direction of this curve

splitCurve(u)[source]

Split the curve at parametric position u. This uses the insertKnot() routine

Parameters:
ufloat

Parametric position to insert knot.

Returns:
curve1pySpline curve object

Curve from s=[0, u]

curve2pySpline curve object

Curve from s=[u, 1]

Notes

curve1 and curve2 may be None if the parameter u is outside the range of (0, 1)

windowCurve(uLow, uHigh)[source]

Compute the segment of the curve between the two parameter values

Parameters:
uLowfloat

Lower bound for the clip

uHighfloat

Upper bound for the clip

writeIGES_directory(handle, Dcount, Pcount, twoD=False)[source]

Write the IGES file header information (Directory Entry Section) for this curve.

DO NOT MODIFY ANYTHING HERE UNLESS YOU KNOW EXACTLY WHAT YOU ARE DOING!

writeIGES_parameters(handle, Pcount, counter)[source]

Write the IGES parameter information for this curve.

DO NOT MODIFY ANYTHING HERE UNLESS YOU KNOW EXACTLY WHAT YOU ARE DOING!

writeTecplot(fileName, curve=True, coef=True, orig=True)[source]

Write the curve to a tecplot .dat file

Parameters:
fileNamestr

File name for tecplot file. Should have .dat extension

curvebool

Flag to write discrete approximation of the actual curve

coefbool

Flag to write b-spline coefficients

origbool

Flag to write original data (used for fitting) if it exists