Primitive Instancing
Primitive Instancing
The concept of primitive instancing is to construct more complex
objects from simpler primitive shapes. This concept is utilized
in many commercial CAD solid modeling systems. Blocks, cylinders,
spheres, and cones are some of the typical primitive solids that
these systems offer. For fairly simple objects, it can be easy
to model their shapes using combinations of these primitives.
However, for the components with complex shapes, it can be difficult
or very tedious to describe their shapes starting with primitive
solids.
To implement the primitive instancing concept, it is first necessary
to identify the primitives of interest. For this example, I will
use cubes, cones, and squares. Then, it is necessary to be able
to scale the primitives to generate shapes of the appropriate
sizes and proportions. It is also necessary to position and orient
the scaled shapes.
Let's investigate the cube first. For our purposes, we will be
using MATLAB to model our objects, and MATLAB's graphics capabilities
are limited to wireframes (at present). So, it is only necessary
to model end-points of line segments that will be displayed.
For a cube, I will assume that one face is centered in the XZ
plane, a unit cube is most convenient, and the cube extends along
the Y axis. This is shown in the figure below. In MATLAB code,
the cube vertices are:
Cube = [-0.5, -0.5, -0.5, -0.5, -0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
0.5, -0.5, -0.5, 0.5, 0.5, -0.5;
BR>
0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1;
-0.5, 0.5, 0.5, -0.5, -0.5, -0.5, 0.5, 0.5, -0.5, -0.5,
0.5, 0.5, 0.5, 0.5, -0.5, -0.5;
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];

To position, orient, and scale the cube using relative transformations,
the following equation is used. Note that I am using the Roll-Pitch-Yaw
convention for rotations.
InstantiatedCube = Translate(tx,ty,tz) * Rotate(theta,phi,psi) * Scale(sx,sy,sz)
* Cube
For a cone, I assume that the base of the cone (circle) lies in
the XY plane, with a radius of 1 unit, and four line segments
connect the circle to the cone's apex, 1 unit along the Z axis.
For a square, I center a unit square in the XY plane as follows:
square = [-0.5, -0.5, 0.5, 0.5, -0.5;
-0.5, 0.5, 0.5, -0.5, -0.5;
0, 0, 0, 0, 0;
1, 1, 1, 1, 1];