0

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.

Tim Orton
  • 329
  • 3
  • 14
  • The current problem is that some circles are at the wrong angle, and some are flipped in the opposite direction, so the previous circle doesn't join up correctly. – Tim Orton Apr 20 '15 at 09:41
  • This [Smoothly connecting circle centers](http://stackoverflow.com/a/25182327/2521214) might help look there for `glCircle3D` it draws circle for given position and direction – Spektre Apr 21 '15 at 16:21
  • 1
    What you are trying to do is to sweep a 2d section along a 3d curve. In order to do that, you need to generate orthonormal basis vectors along each point of the curve -- a moving coordinate frame along the curve. If your curve is C3 you can use the [Frenet–Serret frame](http://en.wikipedia.org/wiki/Frenet%E2%80%93Serret_formulas); another option is Bishop's [Parallel Transport Frame](http://arxiv.org/abs/1311.5857). – dbc Apr 21 '15 at 18:03
  • 1
    @dbc yep the link in comment of mine does the basis vector stuff + cubic curve interpolation between 4 control points – Spektre Apr 22 '15 at 06:46

0 Answers0