Search code examples
c++algorithm3dindicesvertices

Algorithm for generating a 3d cylinder along a path


How would one go ahead and generate a cylinder that follows a path? The path is connected using nodes, and smoothing is not needed, just a hard edged long cylinder. The cylinder should be stored using a triangle list, so both vertices and indices is required.


Solution

  • If you "unwrap" the cylinder mesh, you get a regular rectangular grid with rectangles split in two triangles.

    Every vertex can be indexed by a pair of integers, from 0 to M-1 and from 0 to N-1 (with vertexes (I,0) and (I,N) being identical). Then turn every pair (I, J) to the single number I+J.M.

    The triangles join the vertexes (I, J), (I+1, J), (I+1, J+1), or the vertexes (I, J), (I, J+1), (I+1, J+1).