# Pipe mesh generation from Lines

This topic is 4988 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I have generatad a crystal using lines. Now this looks boring and i would like to replace those lines with pipes or bars. So i would need a function that would look like: void GeneratePipeVerticesFromLine(Vector linestart,Vector lineend,float verts[somenumber][3]) { ... } Now i have tried to do it by trans nad Normilize the line and then create a pipe. But i have failed. The glut Mesh generation stuff wont help me becuase they dont return and vertices, they just paint them. Any tips or suggestions??

##### Share on other sites
If you just want a straight pipe (i.e. a cylinder), it's pretty easy. I don't have time to hammer out the psuedocode right now, but the general idea is:

1. Create an orthonormal basis with the line as the z axis.

2. Iterate from 0 to 2pi by some step.

3. At each step find a point as a combination of the line start point, the local basis x axis * sin(angle) * radius, and the local basis y axis * cos(angle) * radius. This gives you the points for the 'circle' at one end of the cylinder.

4. Add the line direction vector to each of those points to get the points for the circle at the other end of the cylinder.

5. Triangulate.

If that's not clear or you have questions, just ask.

##### Share on other sites
Quote:
 Original post by jyk1. Create an orthonormal basis with the line as the z axis.If that's not clear or you have questions, just ask.

I dont get how to do this. There is no problem for me to create a pipe (cylinder) around any of the axis. But my problem is how i should rotate and transform so it can replace my line.

##### Share on other sites
You want two vectors ('up' and 'right') which are orthogonal to your initial line ('forwards').

The easiest way to do it is to cross the forwards vector with some other vector guaranteed not to be parallel to the forward vector to get the right vector, and then cross the right vector with the forwards vector to get the up vector. (Normalise them all at the end, of course).

'Up' and 'Right' then become 'local x axis' and 'local y axis' in step 3 of jyk's solution.

It may be worth keeping in mind that you could draw the open cylinder as a triangle strip. You'll be generating points at angle=0 twice (both at the beginning and at the end), unless you use an index buffer.

1. 1
2. 2
3. 3
Rutin
22
4. 4
JoeJ
16
5. 5

• 14
• 29
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631774
• Total Posts
3002288
×