Anders Thorup: Input for 3D splines

The following pages contain examples of the use of a very simple Pascal program, 3dspline.pas. The program is designed for generation of input data for curve drawings in TEX, and it requires (knowledge of) the TEX-package spline.sty. The routines in the Pascal program are centered around one procedure:

                               cproj.

To describe it, assume that the coordinates of a center in 3-space is given. Associate with it the central projection from the center onto the plane through the origin perpendicular to the center. Then the call cproj(x), for a point x in 3-space, computes the image of x under the projection, and writes the two coordinates of the image point to an output file. The purpose is to use the procedure to generate coordinates that may serve as input for various spline commands and other curve drawing commands from the spline package. The output coordinates depend on the choice of center, and the following pages show how the output varies under changes of the center. The source code of the Pascal program contains several routines for manipulating with vectors in 3-space. The body part of the program produces several examples.

As mentioned above, the macros of the Pascal program are designed for the generation of input data for curve drawings in TEX; however, the body part of the program as it is generates a complete TEX file. In fact, all the pages you see are in the source code of the program, and this whole document may be reproduced as follows:

(1) Compile the Pascal program 3dspline.pas

(2) Run the resulting executable; it will produce a tex file, cproj.tex, containing a lot of spline drawing commands.

(3) Tex the file cproj.tex (with Plain TeX or AmSTeX); the file spline.sty is required.

(4) View the result on your favourite device; as always when the spline package is used it is required that the interpretation accepts imbedded PostScript code as described in DVIPS.

Anders Thorup 3 January 2005

2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

Setup. To obtain coordinates of the vertices of the regular polyhedra, consider a trapezoid inscribed in a unit circle, say with vertices of coordinates (±r, l) and (±r′, l′). If c is the common length of the two non-horizontal sides then

r^{2} + l^{2} = 1, r^{′2} + l^{′2} = 1, (r′ − r)^{2} + (l′ − l)^{2} = c^{2}.

Assume that l′ > l and l′ > 0. Then, in terms of the two ratios μ = r/c and μ′ = r′/c, the coordinates are given by the formulas (where L := 1 − (μ − μ′)^{2} and N := 1 + 4μμ′):

(1’) c^{2} = \frac{4L}{N}, r^{2} = \frac{4μ^{2}L}{N}, r^{′ 2} = \frac{4μ^{′ 2}L}{N},

(1”) l′ − l = \frac{2L}{\sqrt{N}} , l = \frac{−1 + 2μ(μ − μ′)}{\sqrt{N}}, l′ = \frac{1 + 2μ′(μ − μ′)}{\sqrt{N}} .

Note the degenerate case of a triangle: r′ := 0, l′ = 1. Then, μ′ = 0, and

(2) c^{2} = 4(1 − μ^{2}), r^{2} = 4μ^{2}(1 − μ^{2}), l = −1 + 2μ^{2}.

If r and r′ are the radii of the circles circumscribing the base and the top of a regular truncated pyramid, based on a regular n-gon, and inscribed in a unit sphere, then the side lengths are b = 2r sin π/n and b′ = 2r′ sin π/n. Therefore,

(3) μ = \frac{b/c}{2 sin π/n}, μ′ = \frac{b′/c}{2 sin π/n}.

(r, 0, l) (r′, 0, l′) c bb′  (r, 0, l)

The side lengths of the regular polyhedra. For example, by using (2) it is easy to determine the side length c of the regular polyhedra inscribed in a unit sphere, with a vertex at the North Pole:

For the tetrahedron, n = 3 and b = c. Hence μ^{2} = 1/(2 sin π/3) = 1/3 and c^{2} = 8/3.

For the hexahedron, n = 3 and b = \sqrt{2}c. Hence μ^{2} = 2/(2 sin π/3)^{2} = 2/3, and c^{2} = 4/3.

For the octahedron, n = 4 and b = c. Hence μ^{2} = 1/(2 sin π/4)^{2} = 1/2, and c^{2} = 2.

For the icosahedron, n = 5 and b = c. Hence μ^{2} = 1/(2 sin π/5)^{2}. As 2 sin^{2} π/5 = 1 − cos 2π/5 = (5 − \sqrt{5})/4, it follows that μ^{2} = 2/(5 − \sqrt{5}) = (5 + \sqrt{5})/10, and c^{2} = 2(5 − \sqrt{5})/5.

For the dodecahedron, n = 3, and b/c is the ratio between the diagonal and the side of regular pentagon, and hence equal to (2 sin 2π/5)/(2 sin π/5) = 2 cos π/5.

So μ = cos(π/5)/ sin(π/3) and c^{2} = 4(3−4 cos^{2}(π/5))/3 = 4(3−2(cos(2π/5))/3 = (4 cos 2π/5)^{2}/3.

Coordinates. For the icosahedron (one vertex on the North Pole), use (2) to determine the coordinates of the vertices: One vertex is (r, 0, l), where r, l are given by (2): r = 2/\sqrt{5}, l = 1/\sqrt{5}.

For the dodecahedron (top face horizontal), use (1): b/c = sin(2π/5)/ sin(π/5) = 2 cos π/5 and b′/c = 1. Hence μ = cot π/5 and μ′ = 1/(2 sin π/5). It is fastest to use c determined above: r = μc = (4/\sqrt{3})(cos 2π/5)(cot π/5), and r′ = μ′c = (2/\sqrt{3})(cos 2π/5)/(sin π/5).

          x= (r, 0, l) x1= (r′, 0, l′)  (r cos 2π/10, r sin 2π/10, −l) =x2 r1:=1/sqrt(3)*(sqrt(5)-1)/(2*sin(2*pi/10)) l1:=sqrt(1-r1*r1) r:=1/sqrt(3)/sin(2*pi/10) l:=sqrt(1-r*r)

The path marked above on the dodecahedron begins at the point x2 and ends at the point obtained by rotating x1 one fifth around the z-axis. So the path may be drawn by a PSline, produced by the following block of code:

  beginps('PSline');
    cproj(x2);
    cproj(x);
    cproj(x1);
    rotateonefifth(x1);cproj(x1);
  endps;
  rotateonefifth(x2);rotateonfifth(x);

After the first ‘rotateonefifth’, the point x1 becomes the end point of the path. The next two ‘rotateonefifth’s do not contribute to the PSline, but when the code has been completed, all three points x2, x, x1 have been rotated. So, the top part of the dodecahedron may be drawn by repeating the code 5 times. The bottom part may be drawn by reflecting the top part in the origin.