How to extrude a flat two-dimensional grid, giving its depth

I have a set of coplanar connected triangles, i.e. 2D mesh. Now I need to extrude several units along the z axis. A mesh is defined by the set of vertices that the visualization tool has, matching them with an array of triangles.

Mesh example:

Vertices: (0,0,0), (10,0,0), (10,10,0), (0,10,0) <- (x, y, z) Triangles: (1, 2, 3 ) and (3, 4, 1) <- the numbers here refer to the position of the vertex above.

So here we have a 2D square. Now I need to add more vertices and triangles to this list to make an extruded shape. Triangles should be in a clockwise direction, otherwise they will push back.

Is there a simple algorithm for this? Thank.

+5
source share
1 answer

Assuming you want to extrude at a distance of z, you need to follow these steps:

0) let n be the initial number of vertices (4 in your example)

1) For each vertex in your vertex array, add (0,0, z) to it and add the result to your vertex array, for a total of 2 * n vertices. So, for your example, you add the vertices (0,0, z), (10,0, z), (10,10, z), (0,10, z) to your vertex array, for all of 2 * 4 = 8 vertices.

2) ( ) . (3 ). , ( ). 6 4 (3,1) (1,3).

3) (a, b, c) , (a + n, b + n, c + n).

4) , . (a, b) , 2, (a, b, b + n) (b + n, a + n, a)

. , .

+10

All Articles