I'm trying to turn a 3D curved line into a tube, by drawing circles along it and joining them up. I'm having difficulty drawing the circles with the correct rotation. I'm currently drawing circles in a for loop by getting the 2D circle points on the xy plane and applying a rotation to them:
for ( int j = 0; j <= NumSides; ++j )
{
// ensure polygon meets up
if( j == NumSides )
angle = StartAngle;
CVector3D point( sin(angle)*radius, cos(angle)*radius, 0 );
CMatrix4 rotation;
rotation = Matrix4RotationYAngle( vangle );
rotation *= Matrix4RotationXAngle( hangle );
rotation.Translate( points_[i] );
rotation.Transform(point);
surface_.AddPoint( point );
angle -= AngleInc; // Ensure polygon goes clockwise
}
angle = StartAngle;
where hangle and vangle are the number of radians to rotate on the x and y axis respectively. I'm getting these be averaging the angle of the direction vectors for the line segments before and after the centre of the circle (points_[i]
).
I will also want to squash the tube later, by turning the circles into ovals, and I want to be able to twist the squashed tube, by altering the angle the circle is being squashed in.
Any help is greatly appreciated.