Package layout
Five namespaces, ten classes and one middle layer: how the parts of drafting are arranged, and how an object made in one part becomes an object of another.
Five namespaces around one middle layer
Every public name in the package lives in one of five namespaces.
+geom sits in the middle and the other four build on it: a solid
is made from regions and cut back into regions, a mesh is cut into regions,
and a drawing is made of geom objects. +geom depends on none of
them, so a solid never depends on the drawing model, and the drawing model
never depends on Open CASCADE.
Below them, in src, five compiled files do the heavy work.
None of them is called directly; each is reached through the classes and
functions above.
| Namespace | What it holds | What it needs |
|---|---|---|
+geom |
The classes geom.Polyline, geom.Spline,
geom.Path, geom.Region and
geom.UCS; planar geometry on point sets (area, offset,
curvature, intersections, fillets, hatch lines); geom.text;
geom.read and geom.write for DXF. |
Octave alone, except region booleans, offset, the
copies and arrays of regions, and geom.text, which use Open
CASCADE. |
+draw |
draw.Drawing, the drawing model; sheet parts
(draw.titleblock, draw.coordtable,
draw.symbol); line types and colours
(draw.linetype, draw.colour);
draw.read. |
Octave alone. |
+polymesh |
polymesh.Mesh, a triangle mesh with colours;
polymesh.read for STL, OBJ, PLY and 3MF. |
Octave alone. |
+solid |
solid.Shape; the primitives solid.box,
solid.wedge, solid.cylinder,
solid.cone, solid.sphere,
solid.ellipsoid, solid.torus; solids from
regions (solid.extrude, solid.revolve,
solid.loft, solid.sweep,
solid.helix), from meshes (solid.polyhedron)
and from grids of points (solid.surface);
solid.read for STEP. |
Open CASCADE. |
+model |
model.Assembly, named parts placed together;
model.Viewer, the window that shows solids and meshes;
model.read for STEP and 3MF. |
Open CASCADE; the viewer needs a display as well. |
Open CASCADE 7.8 or later, its visualization libraries and X11 are
needed to build the package; pkg install stops and names what is
missing.
Rules that hold everywhere
- Objects are values. Every class except
model.Vieweris a value class: a method returns a new object and leaves the one it was given unchanged, so a result is always assigned,S = fillet (S, E, 2). A viewer is a handle, because it stands for a window. - Functions take objects. Only constructors take plain matrices.
The planar geometry functions of
+geomthat work on point sets carrying no arcs, such asgeom.offsetorgeom.curvature, take N-by-2 matrices, as before. - Lengths are millimetres and angles are degrees, everywhere and in every file the package writes.
- Pieces come back as a row cell of regions. Region booleans,
offset,section,projectionandgeom.textcan give several separate pieces, so they return a row cell array ofgeom.Regionobjects, largest first, andcell (1, 0)when nothing is left. - Reading is a function, writing is a method. A file is read by a
function in the namespace of what it returns (
solid.read,polymesh.read,model.read,geom.read,draw.read) and written by thewritemethod of the object written, which picks the format from the file's extension.
The geometry classes
Four value classes are the package's one representation of outlines and
curves, used by drawings and solids alike. Each lies in a
geom.UCS, the world xy plane unless told otherwise.
| Class | What it is | Made from |
|---|---|---|
geom.Polyline |
The DXF polyline: vertices [x, y, bulge] in its plane,
open or closed, straight segments and arcs. |
An N-by-2 or N-by-3 matrix. |
geom.Spline |
A NURBS curve in its plane, open or closed; an exact ellipse among them. | Points to pass through, geom.Spline.nurbs for control
points, knots and weights, geom.Spline.ellipse. |
geom.Path |
A route in 3-D of straight segments, arcs and splines, open or closed; what a region is swept along. | An M-by-3 matrix, a polyline, a spline, join of paths
and splines, geom.Path.arc, geom.Path.chain of
loose pieces. |
geom.Region |
A closed area: one outline and any number of holes, each a closed path of segments, arcs and splines, checked to be valid. | A closed polyline, path or spline, or a matrix, for the outline and
each hole; geom.Region.nest of loose loops. |
A region is the hub of the package. It is what a solid is made from, what
a section of a solid or a mesh is, what geom.text gives and what
a hatch fills. It combines with union, subtract and
intersect, grows and shrinks with offset, rounds and
bevels with fillet and chamfer, and is wrapped by
hull, resized, mirrored and copied in rows, columns or round a
point.
The UCS, the frame they share
A geom.UCS is a user coordinate system: an origin, an
x axis and a normal, so a plane with coordinates of its own. It is how
the namespaces agree on where things are. Assigning a geom object another UCS
moves it there, keeping its shape in its own coordinates, so a profile drawn
in the xy plane is laid on any face of a part by giving it that
face's UCS.
| Where a UCS appears | What it does there |
|---|---|
The UCS property of a polyline, spline, path or
region | The plane the object lies in. A solid is made where its
region's plane puts it: extrude rises along the normal,
revolve and helix turn about the plane's own
y axis. |
The last argument of a primitive, solid.box (80, 40, 12,
U) | Places the primitive: a box by its corner, or by the
point 'Anchor' names. |
section (S, U), section (M, U) |
The plane of the cut. The regions come back lying in
U. |
projection (S, U) | The direction the outline is seen along. |
add (A, NAME, X, U) | Where a part is placed in an assembly. |
geom.UCS (V), pickucs (V) | A UCS picked with the mouse on a face or three points in a viewer; the pick prints the line that makes it again from coordinates. |
| A DXF file | Every geom object's UCS is kept in the file, so
geom.read gives back the frame that was written. |
A UCS is made from a normal and an origin, geom.UCS (NORMAL,
ORIGIN), with a point the x axis points to as a third argument,
or from three points with geom.UCS.threepoint.
geom.UCS () is the world xy plane.
toworld and tolocal carry points between a UCS and
the world.
From one class to another
Every way an object of one class becomes an object of another:
| From | To | How |
|---|---|---|
| Matrix | geom.Polyline, geom.Spline,
geom.Path, geom.Region | The constructor. |
geom.Polyline, geom.Spline |
geom.Path | geom.Path (PL),
geom.Path (SP); a polyline's bulges become exact
arcs. |
| Closed polyline, spline or path | geom.Region |
geom.Region (OUTLINE, HOLES). |
| Loose pieces or loops | geom.Path,
geom.Region | geom.Path.chain joins pieces
end to end; geom.Region.nest sorts loops into outlines and
holes. |
| Text | geom.Region | geom.text
(STR), the outlines of the letters. |
geom.Region | solid.Shape |
solid.extrude, solid.revolve,
solid.helix; several regions with
solid.loft; a region and a path with
solid.sweep. |
solid.Shape | geom.Region |
section (S, U), a cut; projection (S, U),
the outline seen along a direction. |
polymesh.Mesh | geom.Region |
section (M, U), then fit to turn the facets
back into lines, arcs and splines. |
polymesh.Mesh | solid.Shape |
solid.polyhedron (M), from a closed mesh. |
A grid of points, as meshgrid makes it |
solid.Shape | solid.surface (X, Y, Z, H),
an exact surface through it, thickened. |
solid.Shape | polymesh.Mesh |
tessellate (S, TOL), each triangle in the colour of its
solid. |
Vertices and faces, or a patch struct |
polymesh.Mesh | polymesh.Mesh (V, F),
polymesh.Mesh (S). |
solid.Shape, polymesh.Mesh |
model.Assembly | add (A, NAME, X, U),
a part defined once however often it is placed. |
model.Assembly | solid.Shape,
polymesh.Mesh | shape (A), every placed
solid in one shape, kept apart rather than united, an error when a part
is a mesh; tessellate (A), every part as one mesh. |
| Polyline, spline, path, region | draw.Drawing |
The methods polyline, spline,
path, region and hatch. A drawing
is flat, so the object must lie in its xy plane. |
solid.Shape, polymesh.Mesh,
model.Assembly | model.Viewer |
show, which returns the viewer. |
model.Viewer | geom.UCS, edges,
faces, points | geom.UCS (V) or pickucs
(V); pick (V) returns the edges and faces clicked on
a solid, or the points clicked on a mesh. |
One object through every layer
A plate with a bore, made once as a region and carried through the package:
## A plate 60 by 40 with a bore of diameter 20, in the xy plane
R = geom.Region ([0, 0; 60, 0; 60, 40; 0, 40], {[20, 20, 1; 40, 20, 1]});
## A solid from the region, and a mesh from the solid
S = solid.extrude (R, 10);
M = tessellate (S);
## A cut through the middle of the bore gives two pieces, each a region
## lying in the plane of the cut
C = section (S, geom.UCS ([0, -1, 0], [0, 20, 0]));
## A drawing is flat, so lay a piece in the xy plane before hatching it
Q = C{1};
Q.UCS = geom.UCS ();
D = draw.Drawing ('section');
D = D.hatch (Q);
## The plate twice in an assembly, the second stacked on the first
A = model.Assembly ('stack');
A = add (A, 'plate', S, geom.UCS ());
A = add (A, 'plate', [], geom.UCS ([0, 0, 1], [0, 0, 10]));
The second add passes [] for the part: the
part named 'plate' is already defined, so the assembly places
it again rather than storing it twice.
Files
| Object | Read | Write |
|---|---|---|
solid.Shape | solid.read:
STEP | write (S, FILE): STEP; STL, OBJ, PLY and 3MF
through tessellate |
polymesh.Mesh | polymesh.read: STL,
OBJ, PLY, 3MF | write (M, FILE) |
model.Assembly | model.read: STEP,
3MF | write (A, FILE): STEP, 3MF |
| Polyline, spline, path, region | geom.read:
DXF | write (G, FILE): DXF; geom.write (C,
FILE) for several |
draw.Drawing | draw.read:
DXF | write (D, FILE): DXF; print onto
paper at a stated scale, as PDF, EPS, SVG, PNG, JPEG or TIFF;
tikz for LaTeX |
How each geom class and each drawing entity is written to DXF and read back is set out in DXF and the classes.