Sign in to follow this  
coolhelix

How to get normal vector at the edges of Bezier surface

Recommended Posts

Hi, guys, I want to generate a Bezier surface with shading effect. So, I have to compute the normal vector for every vertex (sampling point). I don't want to use the matrix, because the order of the surface would be very large. So I Use polynomial equation would be fine. I want to get the normal value of P(u,w), at position u,w, where u = 0, and w = 0. What frustrating me was that after computation, the tangent value in u and v direction are the same. Pu(0,0) == Pv(0,0) So, the cross product of these two vector was invalid. How can I resolve this issue? P.S. My code to generate the first derivative of Bernstein function. The code add some special handling to the extreme condition where t is 0.

    //Get first derivative of Bernstein function
    float DBasis(int n,int i,float t)
    {
        if ( t == 0)
        {
            if( i == 0)
            {
                // n * Ni( n, i ) * pow( 1 - t, n - 1) * (-1)
                return (-n) * Ni(n,i)* pow( 1 - t, n - 1);
            }
            else
                return 0;
        }
        else if ( t == 1 )
        {
            if( i == n)
            {
                // i * Ni(n, i) * pow( t, i - 1)
                return i * Ni(n,i)* pow( t, i - 1);
            }
            else
                return 0;
        }
        else
        {
            //   i - n * t
            // --------------  * Basis( n, i , t);
            //  t * ( 1 - t)
            return ( i - n * t) * Basis( n, i , t) / ( t * ( 1 - t) );
        }
    }
Thanks, Ed.

Share this post


Link to post
Share on other sites
If the direction of the tangent vectors of the parameters have the same direction then you have a 1 dimensional curve at that location, not a surface(so the normal isn't very well defined).

I don't entirely understand your issue, but it seems like you might be taking the derivative with regard to an axis (rather than a parameter)and getting a scalar representing a single component of the tangent vector(as opposed to a full 3 component vector). If that were the case and you were finding the derivative of something like a height map with respect to the x and y axis then you could put a 1 into the component that you were finding the derivative over and a 0 into the other component to extend those derivatives to 3 component vectors. So if you have dz/dx and dz/dy then your tangent vectors would be something like (1,0,dz/dx) and (0,1,dz/dy) which will never be in the same direction.

If that's not the problem then you may just be trying to find a value that isn't unique(the normal of a line). If your doing it for graphics then you could check the normal at a location on the surface very close to the point in question. It'd basically be equivalent to taking the limit of the normal as it approaches from a specific direction. If you're getting this result at more than a finite number of feature points then something else is seriously wrong.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this