# Rotation to form a pyramid

• 10-24-2010, 10:39 PM
Phinehas
Rotation to form a pyramid
Hi,

I have an idea and want to implement it in WebGL. Normally, we have to create many vertex to form a pyramid (at least four triangle and three vertex for each triangle).

However, I want to use only one triangle to form a pyramid. The method is that I rotate the screen 90 degree after drawing one triangle. Then, I can rotate it again and drawing the second triangle and so on. Therefore, if I change the size of the triangle, I only change one time without extra effort.

But, I fail to implement it with the following coding:
Code :

```for (var j = 0; j < n; j++) { mvPushMatrix(); mvRotate(1, [0, 1, 0]); setMatrixUniforms(); gl.drawElements(gl.TRIANGLES, pyramidVertexIndexBuffer.numItems, gl.UNSIGNED_SHORT, 0); mvPopMatrix(); }```

It only show me one triangle. Is there any mistakes I made?
• 10-30-2010, 09:13 AM
wglb
Re: Rotation to form a pyramid
Yes, you use the same rotation for every triangle.
Rotation angle should depend on j value.
Try something like:
Code :

```var deltaAngle = Math.PI * 2 / n; for (var j = 0; j < n; j++) { mvPushMatrix(); mvRotate(j * deltaAngle, [0, 1, 0]); setMatrixUniforms(); gl.drawElements(gl.TRIANGLES, pyramidVertexIndexBuffer.numItems, gl.UNSIGNED_SHORT, 0); mvPopMatrix(); }```

(not tested!)
• 06-02-2011, 12:42 AM
henbietha
Re: Rotation to form a pyramid
How do you figure out the volume of a segmented pyramid? Let's say there's a pyramid, and you're given the base length (16) and height (10). If we were to cut off the top 4 inches of the pyramid, how can you calculate the volume of just that segment of the pyramid?