pointsandfaces – some internals

Let’s get back to our fist example and take a look behind the scenes. To see what we have actually got, press <Ctrl>+1 to make the edges of the triangles that shape the objects surface, visible, decrease the value for fn down to 6, set a height of 10, make a thicker wall, prefix the polyhydron()-statement with a “%”, insert an echo()-statement to output the arrays, insert a call to PnfDebugPoints() (found in littlehelpers.scad), to show and label the positions of the points, and press <F5> to view.

use <inc/pnf/pnf_cylinder.scad>
use <inc/pnf/pnf_littlehelpers.scad>
fn = 6;
outer_radius = 30;
wall_thickness = 8;
height = 10;

v = pnf_tube_pnf_v(r = outer_radius, h = height, wt = wall_thickness, nz = 1, fn = fn);
%polyhedron(v[0], v[1], 4);
PnfDebugPoints(v[0],true)
echo(v);

I have given the output of the echo-statement some formatting and rounded some values to make it easier to read:

Points:

lower outer ring:
[30, 0, 0], [15, 26, 0], [-15, 26, 0], [-30, 0, 0], [-15, -26, 0], [15, -26, 0]
upper outer ring:
[30, 0, 10], [15, 26, 10], [-15, 26, 10], [-30, 0, 10], [-15, -26, 10], [15, -26, 10]
upper inner ring:
[26, 0, 10], [13, 22.5, 10], [-13, 22.5, 10], [-26, 0, 10], [-13, -22.5, 10], [13, -22.5, 10]
lower inner ring:
[26, 0, 0], [13, 22.5, 0], [-13, 22.5, 0], [-26, 0, 0], [-13, -22.5, 0], [13, -22.5, 0]

Faces:

[ 0,  6,  7], [ 1,  7,  8], [ 2,  8,  9], [ 3,  9, 10], [ 4, 10, 11], [ 5, 11,  6],
[ 0,  7,  1], [ 1,  8,  2], [ 2,  9,  3], [ 3, 10,  4], [ 4, 11,  5], [ 5,  6,  0],
[ 6, 12, 13], [ 7, 13, 14], [ 8, 14, 15], [ 9, 15, 16], [10, 16, 17], [11, 17, 12],
[ 6, 13,  7], [ 7, 14,  8], [ 8, 15,  9], [ 9, 16, 10], [10, 17, 11], [11, 12,  6],
[12, 18, 19], [13, 19, 20], [14, 20, 21], [15, 21, 22], [16, 22, 23], [17, 23, 18],
[12, 19, 13], [13, 20, 14], [14, 21, 15], [15, 22, 16], [16, 23, 17], [17, 18, 12],
[18,  0,  1], [19,  1,  2], [20,  2,  3], [21,  3,  4], [22,  4,  5], [23,  5,  0],
[18,  1, 19], [19,  2, 20], [20,  3, 21], [21,  4, 22], [22,  5, 23], [23,  0, 18]

And this is what we see. Take a look at the order of the points. They are indexed in the faces-array. The first triangle is (0,6,7), and if you look up the points in the image below, you will see, that they describe a triangle on the surface of the object. Note, the order of the points of this triangle. I’s clockwise, seen from the outside of the object. This order defines where the outside is. So take care of it. The second triangle is (1,7,8). Find it, and see, that it is not (0,7,1), which would be the neighbor and would complete this side of the wall. The order, in which the faces appear in the faces-array is not relevant, so in every row the upper-left triangles come first, then the lower right triangles. The scheme of the numbering looks simple. Every circle of points has 6 elements, and this is the difference in index between the first and second point of each upper left triangle. The difference in index between the second and third point is usually 1, except for the last face in the row, because it closes here and connects to its beginning. The rule for this is also simple. If a row of triangles closes to itself, the index of the rightmost point must be the the index of the first point. The scheme for the lower-right triangles follows the same principles.

Each row follows this scheme. Now it makes sense, that the outer points go from bottom to top and the inner points go from top to bottom. Instead of handling the outside wall, the inside wall and the two rims separately, we can use one scheme for all the faces of our tube. The only exception is the bottom rim, which connects the last row of points with the first row of points, but handling this exception is as easy as closing rows. Regarding this aspect, constructing a tube is simpler than constructing a cylinder!

You should take a look a the function pnf_row_of_faces_v() in pnf.scad, which is the core routine to connect two rows of points with faces.

Almost as easy to understand, at least regarding the complexity of building the faces-array is the next example