M. Kemper
M. Kemper

Reputation: 75

JaveFX TriangleMesh Pyramid - it works, but why?

Making a 4-sided pyramid is explained 'lightly' in a few texts, as follows:

pyramid.getPoints().addAll(0,0,0); //0 = top
pyramid.getPoints().addAll(0, height, -hypotenuse/2); //1 = closest
pyramid.getPoints().addAll(-hypotenuse/2, height, 0); //2 = leftest
pyramid.getPoints().addAll(hypotenuse/2, height, 0); //3 = furthest
pyramid.getPoints().addAll(0, height, hypotenuse/2); //4 = rightest

pyramid.getTexCoords().addAll(0, 0);

pyramid.getFaces().addAll(0,0,2,0,1,0); //Left front side
pyramid.getFaces().addAll(0,0,1,0,3,0); //???
pyramid.getFaces().addAll(0,0,3,0,4,0); //Right back side
pyramid.getFaces().addAll(0,0,4,0,2,0); //???
pyramid.getFaces().addAll(4,0,1,0,2,0); //Bottom triangle at front???
pyramid.getFaces().addAll(4,0,3,0,1,0); //Bottom triangle right???

It works, but I don't understand it.

enter image description here

The 2nd face added has vertices 0, 1, 3, so (reference figure) ... it slices the pyramid in half. It is not an external face as far as I can tell. Same with the 4th face, only now the slice is orthogonal to the 2nd face. And then the last 2 faces, which should be the triangles making up the square base of the pyramid. The first one goes from vertex 4 to vertex 1 to vertex 2, so ... that is the front triangle of the pyramid base (is what I think). So I expect vertices 2,3,4 to form the back triangle of the pyramid base, but in the last line of code we see vertices 4,3,1, which (according to my logic) make up the right triangle of the pyramid base, i.e. does not complement the front triangle of the pyramid base. Can someone please explain this on-the-face-of-it simple geometric puzzle? And is there a proper indepth resource out there I can study?

Much obliged - Michael

Upvotes: 1

Views: 253

Answers (1)

James_D
James_D

Reputation: 209684

The correct numbering of the vertices is (apologies for the crudely-drawn image):

enter image description here

which you can see fairly clearly by plotting vertices 1-4 in the x-z plane:

1: (0, -h/2)
2: (-h/2, 0)
3: (h/2,  0)
4: (0,  h/2)

enter image description here

Thus the faces

(0,2,1)
(0,1,3)
(0,3,4)
(0,4,2)
(4,1,2)
(4,3,1)

describe exactly the triangles you want.

Upvotes: 1

Related Questions