2

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

Community
  • 1
  • 1
  • to clarify I am looking for a way to determine the NURBS parameter based on the x-location of a point that lies on the NURBS curve so that I can then evaluate the curve at this parameter and find the corresponding y value of that point – Michael Martin Jun 25 '15 at 16:43

1 Answers1

0

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.

fang
  • 3,473
  • 1
  • 13
  • 19
  • Thanks for your answer. I have a few follow up questions though. What do you mean by extracting the Bezier curve for the given knot interval? Also, Xmin2 and Xmax2 are not being used in your example code. Are they not needed? – Michael Martin Jul 01 '15 at 08:41
  • A NURBS curve is composed of multiple curve segments defined within each non-null knot interval. Each of these curve segments is in fact a Bezier curve (or rational Bezier curve if your NURBS curve is indeed rational). So, extracting a Bezier curve for the knot interval simply means creating a Bezier curve representation for knot interval [a, b]. The algorithm to do this should be available online or in any geometric modeling textbook. – fang Jul 01 '15 at 19:41
  • Xmin2 and Xmax2 is not really used. If X0 is within [Xmin, Xmax] but not within [Xmin1, Xmax1], then X0 has to be within [Xmin2, Xmax2]. You can use this to check whether the computation is correct. – fang Jul 01 '15 at 19:43