0

My current task: To extrude a shape along a MOVING bspline. Each control point on the bspline consists of a position, and an "up" vector

Initially, people using my code will establish their bsplines like this (green dots/lines are the position and upvector, the purple are just interpolations).

enter image description here

The programmers will then expect to be able to move control point's POSITION (but not upvector) and have things render correctly. So here's the same stuff except with the bottom position now moved to distort the spline:

enter image description here

As you can see, the upvector, when it tries to work with this, doesn't stay sane at all. It actually behaves correctly, but then suddenly makes a huge jump, in this case 180 degrees. But if one of the points is offset a little bit perpendicularly, it won't be 180 degrees... illustrated below:

enter image description here

In my BSpline class, the upvector is grabbed like so:

    utype GetUpVector(float thePos)
    {
        vtype aTan=GetTangent(thePos);

        float aPos=thePos-floorf(thePos);
        int aIPos=(int)floorf(thePos);

        utype aUp;
        LerpN(aUp,mPoints[_clamp(0,aIPos,mPoints.Size()-1)].mUp,mPoints[_clamp(0,aIPos+1,mPoints.Size()-1)].mUp,aPos);
        vtype aLeft=aTan.Cross(aUp);
        vtype aResult=aLeft.Cross(aTan);
        return aResult.Normal();
    }

(Where mPoints is the list of points in the spline, and GetTangent gets basically the direction of the spline at the location).

Can anyone help me figure out what's happening here? How do I get the spline to return an upvector that keeps to the curve of the spline?

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
KiraHoneybee
  • 495
  • 3
  • 12
  • technical nit, but an important one: you're not showing B-splines, you're showing entire (textured, even) meshes. If the question is on B-spline/Beziers, at the very least tailor those graphics to the question. – Mike 'Pomax' Kamermans Jul 28 '22 at 00:41
  • @Mike'Pomax'Kamermans Well, I see the mesh as incidental and just illustrative... my spline is flipping its normals/updirection, and the mesh generation is downstream from that. If I can stop the spline doing that flip, the meshes will render correctly. – KiraHoneybee Jul 28 '22 at 00:54
  • Pretty sure you're running into [a variant of this](https://math.stackexchange.com/questions/2843307/getting-consistent-normals-along-a-3d-bezier-curve) – Mike 'Pomax' Kamermans Jul 28 '22 at 01:03
  • 1
    @Mike'Pomax'Kamermans Ah, thank you... "Rotational Minimizing Frames" was the secret word I needed. – KiraHoneybee Jul 28 '22 at 01:20

0 Answers0