Bending a pipe by 'x' degrees?

Blitz3D Forums/Blitz3D Programming/Bending a pipe by 'x' degrees?

Chaos(Posted 2007) [#1]
Does anyone have any ideas on how to take a cylinder (in fact a modified version of the MyCylinder function from the archives) and bend it at a location along its length by 'x' degrees - im building a small application to assist in the construction of a tubular space frame for an off road buggy and the app needs to bend the tube meshes, I have modified the 'MyClinder' function to allow for tube length wall thickness diameter etc and added the option to display inner wall of tube and endcapping from inner wall to outer wall.

I now want to take this mesh and bend it by moving the verts along its length correctly to form the bend but im at a loss as to how to achieve this - any help would be greatly appreciated (A bit of code to point me on the correct path would be a blessing!!!!!)

Chaos


Stevie G(Posted 2007) [#2]
You could use a 4 pt Bezier curve where you specify the start position and then end position and set the 2 middle points to influence the curves start and end directions. This will give you the center of the bend.

Then get the direction of the curve at a specific timestep by positioning a pivot at the currect timestep and point it to the next timestep. Then extrude the vertices on the x and y axis relative to this pivot.

Not sure if that made sense? At least I know what I mean ;)

Stevie


big10p(Posted 2007) [#3]
There's a function in the code arcs to create a torus - may help point you in the right direction?


Chaos(Posted 2007) [#4]
Stevie G - Thanks for that I think I get what your talking about, im trying something similar at the moment myself using a pivot and taking the ring of verts created from the pipe function and rotating it the required amount then capturing the vert locations - might work, and gives me flexability on the angle of the curve

big10p - Wow I thought i'd checked all through the archives but I missed that one thanks for the heads up, a very neat little function - thanks again

Cheers guys

Chaos


bytecode77(Posted 2007) [#5]
this is a job for a good 3d modeller i guess


big10p(Posted 2007) [#6]
DC: he needs his app to bend the bars in realtime. ;)

TBH, I'd approach this problem in 2D, then extrapolate the calcs to create a 3D bar. I *might* have a crack at this during the week. I'm pretty rusty, coding-wise, though. :)


Chaos(Posted 2007) [#7]
DC: as big10p said i need to be able to bend and re-bend the tubes in realtime - the idea is to feed in the size of the tube then bend it on screen to fit the chassis, I thought of doing it 2D first myself but I realised I would need to be able to 'tweak' tubes to fit on screen in 3d anyway - so I thought id try and do it in 3d first as that would probably be the tough bit!!

big10p: thanks man if you do get chance to have a play any assistance or just pointers would be very much appreciated, I will be plugging away at it during the evenings after work myself during the week and will post the progress I make if your interested....

Cheers

Chaos


bytecode77(Posted 2007) [#8]
maybee you have to make a 'bend animation' in a 3d modeller and save it as an animated mesh. then load it in blitz3d and play it!


Chaos(Posted 2007) [#9]
DC: Yeah could do but I need to be able to allow the user to select the correct size of tooling for the bend and to how many degrees, so unless I scale it which might mess up I would need to animate all size bending die's


Chaos(Posted 2007) [#10]
But thanks DC if all else fails thats the way it will have to be done I suppose

Cheers

Chaos


Stevie G(Posted 2007) [#11]
Did you get this sorted? If not I could code an example which may help.


big10p(Posted 2007) [#12]
I was gonna have a go, but haven't got around to it yet. Probably better if you do it, Stevie. ;)


sswift(Posted 2007) [#13]
This is the easiest way to do what you want.

Assuming your cylinder is vertical:

Place a pivot in the center of the first segment of the cylinder. Ie, the middle of the circle of vertices that forms the bottom.

Place a pivot in the center of the next segment. Make it a child of the first pivot.

Place a pivot in the center of the next segment. Make it a child of the second pivot.

Repeat until all segments have a pivot that is parented to the previous pivot.

Now, create one pivot for each vertex in the second segment. (The vertices in the first segment will not move so we do not need to do that one.) Make each of these a child of the second segments pivot. Repeat this for the rest of the vertices, attaching them to their segment's pivot.

You're almost done!

Divide desired curvature by number of segments in the cylinder-1. Ie, if there are six segments in your cylinder, counting the top and bottom, and you want a 90 degree curve, divide 90 by 5. This gives us 18. So ROTATION = 18.

So, assuming a 9 degree bend, starting at the second segment, rotate each segment's pivot by 18 degrees on either the Z axis if you want a bend to the right, or the X axis if you want a bend from front to back.

Once you have done this, simply copy the new global position of each vertex's pivot to the vertex. You now have a curved cylinder.

This works because each child will rotate around the parent, and you've created a chain of children starting from the bottom of the cylinder, and the vertex pivots are parented to each section of this chain, so they rotate with it as expected as well.

It's possible to do this without one pivot per vertex, or even using just a single pivot, but it's just way easier for you to do it this way and should be plenty fast enough for your needs.


Chaos(Posted 2007) [#14]
Wow thanks everyone! - i managed to produce a test example similar in principle to sswift's idea in the end,

First create a ring of verts at the correct diameter

parent that ring to a pivot a set distance away (the distance is important as it the bending tool diameter)

rotate the whole ring of verts via the pivot using the same maths as sswift to get the degree of movement per segment

at each movement/rotation capture the global locations of each vert and create a new vert at that global position connected to a bend mesh object

finally skin the new mesh object and I have a bent tube mesh!!!!

Got it working last night - then fiddled with it and broke it!!! - but should have it working tonight again

Thanks very much for the help everyone :)