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.

How the namespaces of drafting turn into one another The geom namespace sits in the middle. Solids are made from geom regions and cut back into them; meshes are cut into regions; solids and meshes turn into each other; assemblies hold solids and meshes; drawings are made of geom objects. +model model.Assembly model.Viewer +polymesh polymesh.Mesh +solid solid.Shape +geom Polyline Spline Path Region each one lying in a geom.UCS +draw draw.Drawing add add solid.polyhedron tessellate section extrude, revolve, loft, sweep, helix section, projection polyline, spline, path, region, hatch

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.

NamespaceWhat it holdsWhat 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.Viewer is 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 +geom that work on point sets carrying no arcs, such as geom.offset or geom.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, projection and geom.text can give several separate pieces, so they return a row cell array of geom.Region objects, largest first, and cell (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 the write method 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.

ClassWhat it isMade 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 appearsWhat it does there
The UCS property of a polyline, spline, path or regionThe 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 fileEvery 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:

FromToHow
Matrixgeom.Polyline, geom.Spline, geom.Path, geom.RegionThe constructor.
geom.Polyline, geom.Spline geom.Pathgeom.Path (PL), geom.Path (SP); a polyline's bulges become exact arcs.
Closed polyline, spline or pathgeom.Region geom.Region (OUTLINE, HOLES).
Loose pieces or loopsgeom.Path, geom.Regiongeom.Path.chain joins pieces end to end; geom.Region.nest sorts loops into outlines and holes.
Textgeom.Regiongeom.text (STR), the outlines of the letters.
geom.Regionsolid.Shape solid.extrude, solid.revolve, solid.helix; several regions with solid.loft; a region and a path with solid.sweep.
solid.Shapegeom.Region section (S, U), a cut; projection (S, U), the outline seen along a direction.
polymesh.Meshgeom.Region section (M, U), then fit to turn the facets back into lines, arcs and splines.
polymesh.Meshsolid.Shape solid.polyhedron (M), from a closed mesh.
A grid of points, as meshgrid makes it solid.Shapesolid.surface (X, Y, Z, H), an exact surface through it, thickened.
solid.Shapepolymesh.Mesh tessellate (S, TOL), each triangle in the colour of its solid.
Vertices and faces, or a patch struct polymesh.Meshpolymesh.Mesh (V, F), polymesh.Mesh (S).
solid.Shape, polymesh.Mesh model.Assemblyadd (A, NAME, X, U), a part defined once however often it is placed.
model.Assemblysolid.Shape, polymesh.Meshshape (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, regiondraw.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.Assemblymodel.Viewer show, which returns the viewer.
model.Viewergeom.UCS, edges, faces, pointsgeom.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

ObjectReadWrite
solid.Shapesolid.read: STEPwrite (S, FILE): STEP; STL, OBJ, PLY and 3MF through tessellate
polymesh.Meshpolymesh.read: STL, OBJ, PLY, 3MFwrite (M, FILE)
model.Assemblymodel.read: STEP, 3MFwrite (A, FILE): STEP, 3MF
Polyline, spline, path, regiongeom.read: DXFwrite (G, FILE): DXF; geom.write (C, FILE) for several
draw.Drawingdraw.read: DXFwrite (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.