point evaluation of NURBS curve given an axial coordinate

766 views Asked by At

my question is how to get the second coordinate (in 2D) of a point that lies on a curve defined as a NURBS curve given the axial coordinate. I have the knot vector, control points, their weights and basis functions.

I looked through similar questions (How to find out Y coordinate of specific point in bezier curve in canvas?) but did not find a good answer so far. Thanks, M

1

There are 1 answers

3
fang On

This is not an easy task if you need to implement everything from scratch. Nevertheless, the codes will look like this:

for each non-null knot interval in the knot vector of the NURBS
{
    extract Bezier curve B(t) from the NURBS for this knot interval [a, b];
    compute the minimum and maximum X values of the Bezier curve's control points. 
    if ( X0 is within [Xmin, Xmax] )
    {
        t0 = a;
        t1 = b;
        epsilon = 1.0e-06; // a small value;

       while ( (t1-t0) > epsilon )
       {
          Subdivide B(t) at t=0.5 to generate two Bezier curves: B1(t) and B2(t);
          compute the [Xmin1, Xmax1] for B1(t) and [Xmin2, Xmax2] for B2(t);
          if ( X0 is within [Xmin1, Xmax1] )
          {
              B(t) = B1(t);
              t0 = a;
              t1 = (a+b)/2;
          }  
          else
          {
              B(t) = B2(t);
              t0 = (a+b)/2;
              t1 = b;
          } 
       } // end while loop

       return ((t0+t1)/2);  // This is the parameter value you are looking for
   } // end if()

} // end for loop

The (t0+t1)/2 is the parameter value you are looking for. Please note that you might find multiple solutions given the same X0 value.