Class Definition: geom.Spline

drafting: geom.Spline

A smooth curve: a NURBS, drawn through points or given by its control points.

A geom.Spline holds a non-uniform rational B-spline: control points that pull the curve towards them, a weight for each, a degree and a knot vector. This form carries exactly the curves a solid is made of and a cut through it gives, a circle, an ellipse or any other conic as a rational spline and Open CASCADE’s own B-splines as they are, and it is what a DXF SPLINE holds. The curve is open, or closed and joined back to its start.

A spline is usually drawn through points: a cubic that passes through each in turn, smooth all along, its direction and curvature changing without a jump. It is parametrised by the distance from point to point. Either end of an open spline may be given a direction; an end left free is shaped as Octave’s spline shapes it, the first and last two pieces each one cubic. A closed spline is smooth all round. The points and the directions are kept as the spline’s fit data, as DXF keeps them, and when the spline is joined into a path its free ends take the direction of what they meet. geom.Spline.nurbs makes a spline from control points, knots and weights instead, with no fit data.

A spline is the curve of a grip, a curved rib or a channel that follows a surface: solid.sweep carries a section along it as one segment of a geom.Path, and a closed spline is a smooth outline or hole of a geom.Region.

Its points are coordinates in the spline’s geom.UCS, the world coordinate system by default, and assigning another UCS moves the spline, its shape unchanged in its own coordinates. A spline whose points all have z = 0 lies in the plane of its UCS.

A geom.Spline is a value: every change makes a new one.

See also: geom.Path, geom.Region, geom.Polyline, solid.sweep, spline

Source Code: geom.Spline

The geom.Spline class contains the following properties:

The degree of the polynomial pieces the curve is made of, 3 for a spline drawn through points.

The control points as an N-by-3 matrix in millimetres in the spline’s UCS. The curve starts at the first and ends at the last.

An N-by-1 vector of positive weights, all 1 for a curve that is not rational.

The full knot vector, a row of N + Degree + 1 nondecreasing parameters, its first and its last value each repeated Degree + 1 times. For a spline drawn through points the inner knots are the distances along the points.

true when the curve ends where it starts.

For a spline drawn through points, the points as an M-by-3 matrix in its UCS, in the order the spline passes through them; empty for a spline made from control points.

For a spline drawn through points, a 2-by-3 matrix whose rows are the unit directions given at its first and its last point, or NaN for an end left free, as both are for a closed spline; empty for a spline made from control points.

The geom.UCS the points are coordinates in, the world coordinate system by default. Assigning another moves the spline onto it, its shape unchanged in its own coordinates.

The geom.Spline class offers the following public methods:

geom.Spline: SP = geom.Spline (V)

geom.Spline: SP = geom.Spline (V, Name, Value, …)

SP = geom.Spline (V) makes the cubic spline through the points given as rows of V, an M-by-3 matrix in millimetres, or an M-by-2 matrix of points in the plane of the UCS, with at least two rows. Through two points with both ends free, the spline is the straight line between them.

Name/Value pairs:

'Closed'
true for a spline that runs on from the last point back to the first, smooth there as everywhere, false by default. A closed spline needs at least three points and has no ends to give directions to. It must not repeat its first point at the end; a repeat is accepted and dropped.
'Tangents'
A 2-by-3 matrix [T1; T2] of the directions at the first and the last point, of any nonzero length; a row of NaN leaves that end free. Both ends are free by default.
'UCS'
The geom.UCS the points are coordinates in, the world coordinate system by default.
 
 ## The centre line of a grip, leaving straight up and arriving level
 SP = geom.Spline ([0, 0, 0; 10, 0, 30; 40, 0, 50; 80, 0, 50], ...
                   'Tangents', [0, 0, 1; 1, 0, 0]);

 ## A smooth closed outline through five points
 SP = geom.Spline ([0, 0; 30, -5; 45, 15; 25, 30; 5, 20], ...
                   'Closed', true);

See also: geom.Spline.nurbs

geom.Spline: L = length (SP)

L = length (SP) returns the length of the spline SP along the curve, in millimetres.

geom.Spline: P = points (SP, N)

P = points (SP, N) returns N points along the spline SP, from its start to its end, or round a closed spline back to its start, as an N-by-3 matrix of coordinates in its UCS. They are spaced evenly in the spline’s parameter, for a spline drawn through points the distance from point to point, so they include every point it passes through only when N falls on them. Convert them to world coordinates with geom.UCS.toworld.

geom.Spline: P = join (SP, P2, …)

geom.Spline: P = join (…, 'Tangent', TF)

P = join (SP, P2, …) returns the geom.Path that runs along the spline SP, then along P2, and so on, as geom.Path.join puts paths and splines end to end.

See also: geom.Path.join

geom.Spline: write (SP, FILE)

geom.Spline: write (SP, FILE, Name, Value, …)

write (SP, FILE) writes the spline SP to FILE, which must end in .dxf, as one SPLINE of an ASCII DXF drawing, in world coordinates: its control points, knots and weights, and its fit points and end directions where it was drawn through points. The spline’s geom.UCS goes with it as extended data under the application 'DRAFTING', so geom.read gives back the spline that was written, frame and fit data included.

Name/Value pairs:

'Layer'
The layer, '0' by default.
'Linetype'
One of the line types of draw.linetype, or any name the receiving program holds; 'CONTINUOUS' by default.
'Colour'
An AutoCAD colour index from 1 to 256, 256 meaning the layer’s colour, which is the default. True colour came only with R2004.
'Version'
'R2000' (AC1015), the default, or 'R12' (AC1009) for a program that reads nothing later. R12 holds only lines and arcs, so a spline is an error there.
'LTScale'
The drawing’s line-type scale, 1 by default, written in the header so the dashes look the same wherever the file is opened.

The drawing units are millimetres. Several geom objects go in one file through geom.write.

See also: geom.read, geom.write, draw.Drawing.write

geom.Spline: SP = geom.Spline.nurbs (P, KNOTS)

geom.Spline: SP = geom.Spline.nurbs (P, KNOTS, W)

geom.Spline: SP = geom.Spline.nurbs (…, 'UCS', U)

SP = geom.Spline.nurbs (P, KNOTS) makes the B-spline with the control points given as rows of P, an N-by-3 matrix in millimetres, or an N-by-2 matrix of points in the plane of the UCS, with at least two rows, and the knot vector KNOTS. KNOTS has N + D + 1 nondecreasing values, which sets the degree D: its first and its last value are each repeated D + 1 times, so the curve starts at the first control point and ends at the last, and no inner knot is repeated more than D times. The degree is at most 25.

SP = geom.Spline.nurbs (P, KNOTS, W) gives each control point a positive weight, which makes the curve rational, a NURBS, as a circle or another conic must be.

The option 'UCS' gives the geom.UCS the control points are coordinates in, the world coordinate system by default. The spline is closed when its first and last control points coincide. It has no fit data.

 
 ## A quarter of a circle of radius 10, exactly
 SP = geom.Spline.nurbs ([10, 0; 10, 10; 0, 10], [0, 0, 0, 1, 1, 1], ...
                         [1; sqrt(2) / 2; 1]);
 length (SP)
 ⇒ 15.708

See also: geom.Spline

geom.Spline: SP = geom.Spline.ellipse (A, B)

geom.Spline: SP = geom.Spline.ellipse (A, B, 'UCS', U)

SP = geom.Spline.ellipse (A, B) returns the closed ellipse centred on the origin with the semi-axis A millimetres along the x axis and B along the y axis, a circle when they are equal. It is a rational spline of degree 2, four quarters joined, which follows the ellipse exactly, so its area and length are those of the ellipse and a solid made from it has a true elliptic face. As a closed spline it is the outline or a hole of a geom.Region, or a path to sweep along.

The option 'UCS' lays it in the geom.UCS U, centred on its origin, A along its x axis; the world xy plane by default. Turning the UCS turns the ellipse.

 
 ## An elliptic boss 40 by 20, 5 high, with a bore of 8
 R = geom.Region (geom.Spline.ellipse (20, 10), {[-4, 0, 1; 4, 0, 1]});
 S = solid.extrude (R, 5);

See also: geom.Spline.nurbs, geom.Region, solid.ellipsoid