Class Definition: geom.Polyline

drafting: geom.Polyline

A polyline of straight segments and circular arcs, lying in a plane.

A geom.Polyline is the package’s one representation of an outline that may carry arcs, the polyline of a DXF file. Its vertices are rows [x, y, bulge] in its own plane, and it is open or closed. It may cross itself: it is a line in a drawing. An area to make a solid from is a geom.Region, built from closed polylines.

The bulge of a vertex turns the segment leaving it into a circular arc. It is the tangent of a quarter of the arc’s included angle: zero is a straight segment, 1 a semicircle and 0.4142 a quarter circle. The height of the arc above the middle of its chord is the bulge times half the chord. A positive bulge is an arc running anticlockwise from the vertex to the next, which puts it to the right of the direction of travel; a negative one runs clockwise, to the left. So a polyline from [0, 0] to [20, 0] with a bulge of 1 dips below the chord, to y = -10. Two vertices with a bulge of 1 each make a whole circle.

The vertices are coordinates in the polyline’s geom.UCS, so the same outline can be laid on any plane, as a CAD program’s user coordinate system lays a sketch on a face. By default it is the world xy plane, and assigning another UCS moves the polyline onto it.

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

See also: geom.Region, geom.UCS, draw.Drawing.polyline

Source Code: geom.Polyline

The geom.Polyline class contains the following properties:

The vertices as an N-by-3 matrix [x, y, bulge], in millimetres in the polyline’s plane.

true when the last vertex is joined back to the first.

The geom.UCS the vertices are coordinates in, the world xy plane by default. Assigning another moves the polyline onto it, its shape unchanged in its own coordinates.

The geom.Polyline class offers the following public methods:

geom.Polyline: PL = geom.Polyline (P)

geom.Polyline: PL = geom.Polyline (P, Name, Value, …)

PL = geom.Polyline (P) makes an open polyline in the world xy plane through the vertices given as rows of P, in millimetres. P is an N-by-3 matrix [x, y, bulge], or an N-by-2 matrix of vertices joined by straight segments, with at least two rows.

Name/Value pairs:

'Closed'
true to join the last vertex back to the first, false by default. A closed polyline must not repeat its first vertex at the end; a repeat is accepted and dropped. An open polyline has no segment leaving its last vertex, so the bulge there must be zero.
'UCS'
The geom.UCS the vertices are coordinates in, the world xy plane by default.
 
 ## A slot 40 between centres and 12 wide, as one closed polyline
 PL = geom.Polyline ([0, -6, 0; 40, -6, 1; 40, 6, 0; 0, 6, 1], ...
                     'Closed', true);

geom.Polyline: PL = fillet (PL, RADIUS)

geom.Polyline: PL = fillet (PL, RADIUS, IDX)

PL = fillet (PL, RADIUS) rounds every corner where two straight segments meet with an arc of radius RADIUS millimetres, tangent to both: the corner vertex becomes the two points where the arc meets the segments, joined by the arc. Corners where an arc meets a segment are left as they are, and so are the two ends of an open polyline.

PL = fillet (PL, RADIUS, IDX) rounds only the corners at the vertices indexed by IDX, each of which must be a corner between two straight segments.

A radius too large for a corner, whose arc would run past the end of a segment or into the round of the next corner, is refused.

 
 ## A plate 60 by 40 with corners of radius 5
 PL = fillet (geom.Polyline ([0, 0; 60, 0; 60, 40; 0, 40], ...
                             'Closed', true), 5);

See also: geom.Region.fillet

geom.Polyline: PL = chamfer (PL, D)

geom.Polyline: PL = chamfer (PL, [D1, D2])

geom.Polyline: PL = chamfer (…, IDX)

geom.Polyline: PL = chamfer (…, 'Angle', A)

PL = chamfer (PL, D) cuts every corner where two straight segments meet with a straight segment from D millimetres back along the segment before the corner to D along the segment after it. Corners where an arc meets a segment are left as they are, and so are the two ends of an open polyline.

PL = chamfer (PL, [D1, D2]) cuts back D1 along the segment before each corner and D2 along the segment after it, before and after in the order of the vertices.

PL = chamfer (PL, D, 'Angle', A) cuts back D along the segment before each corner, with the cut at A degrees to that segment, so a square corner is cut D x A, reaching D * tand (A) along the segment after it.

PL = chamfer (…, IDX) cuts only the corners at the vertices indexed by IDX, each of which must be a corner between two straight segments.

A cut that would run past the end of a segment, or into the cut or round of the next corner, or an angle at which the cut misses the segment after the corner, is refused.

 
 ## A plate 60 by 40 with its corners cut 5 by 45 degrees
 PL = geom.Polyline ([0, 0; 60, 0; 60, 40; 0, 40], 'Closed', true);
 PL = chamfer (PL, 5);

See also: geom.Polyline.fillet, geom.Region.chamfer

geom.Polyline: write (PL, FILE)

geom.Polyline: write (PL, FILE, Name, Value, …)

write (PL, FILE) writes the polyline PL to FILE, which must end in .dxf, as one LWPOLYLINE of an ASCII DXF drawing. The entity holds the polyline’s plane as its normal and elevation, and the polyline’s geom.UCS goes with it as extended data under the application 'DRAFTING', so geom.read gives back the polyline that was written, frame and all.

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 lines and arcs, which is what a polyline is made of.
'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