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.