Jump to content

  • Log In with Google      Sign In   
  • Create Account


B-Spline Surface Normal


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 mrhyperpenguin   Members   -  Reputation: 301

Like
0Likes
Like

Posted 01 May 2014 - 06:38 PM

I'm trying to compute the analytic normals for a B-Spline surface. I know the normal is the cross product of the partial derivatives of the surface but I'm not sure if I'm taking the partial derivatives correctly.

 

atzr9Ca.png

 

Since a B-Spline surface is just the sum of the basis functions in each direction multiplied by the control points (2), I should just be able to take the derivative of each term and add them up (3), correct?

 

I'm getting the derivative of the basis function from [0].

 

What about the control points? Are they constant with respect to u and v? How do I take their derivative?

 

Thanks,

Victor

 

[0] - http://members.gamedev.net/skyork/pdfs/Bspline_Construction_Summary2005.pdf



Sponsor:

#2 Lichtso   Members   -  Reputation: 118

Like
0Likes
Like

Posted 02 May 2014 - 05:08 AM

Mathematically you are correct, but the terminology is wrong.

There is a difference between Bézier curves and B-splines (both 2D).

And their higher dimensional counterparts Bézier surfaces and NURBS (both 3D).

A B-spline is made of multiple weighted bezier curves, broadly speaking.

 

But the equations you have there seem like they belong to a Bézier surface not a B-Spline surface (or NURBS).

Their derivatives can be calculated with different approaches. I think using De Casteljau's algorithm is a easy one.

For example, exactly calculating the derivative in the direction of u:

float s = 1.0-u, t = 1.0-v;
Vector3 points[4];

for(unsigned int i = 0; i < 4; i ++) {
    unsigned int i4 = i+4, i8 = i+8;
    Vector3   a = controlPoints[i ]*t+controlPoints[i4]*v,
              b = controlPoints[i4]*t+controlPoints[i8]*v,
              c = controlPoints[i8]*t+controlPoints[i+12]*v,
              d = a*v+b*t,
              e = b*v+c*t;
    points[i] = d*v+e*t;
}

points[0] = points[0]*s+points[1]*u;
points[1] = points[1]*s+points[2]*u;
points[2] = points[2]*s+points[3]*u;
points[0] = points[0]*s+points[1]*u;
points[1] = points[1]*s+points[2]*u;

return (points[1]-points[0])*3;

for the other derivative you would have to swap u and v and flip the order of the control points.

 

I'm preoccupied in this topic for a while now because I'm trying to write a Bézier surface raytracing algorithm.

What are you planing to use them for?



#3 cadjunkie   Members   -  Reputation: 1273

Like
0Likes
Like

Posted 02 May 2014 - 09:34 AM

I'm trying to compute the analytic normals for a B-Spline surface. I know the normal is the cross product of the partial derivatives of the surface but I'm not sure if I'm taking the partial derivatives correctly.

 

atzr9Ca.png

 

Since a B-Spline surface is just the sum of the basis functions in each direction multiplied by the control points (2), I should just be able to take the derivative of each term and add them up (3), correct?

 

I'm getting the derivative of the basis function from [0].

 

What about the control points? Are they constant with respect to u and v? How do I take their derivative?

 

Thanks,

Victor

 

[0] - http://members.gamedev.net/skyork/pdfs/Bspline_Construction_Summary2005.pdf

 

The control points aren't functions of u or v, so  you don't have to take derivatives of them. They're really just constants. You should be fine computing the derivative like you want. The tricky part is taking the derivatives of the B-spline basis functions. The functions themselves are built recursively, so the derivatives of a B-spline basis function of degree n can be formulated in terms of B-spline basis functions of degree n-1. This website should clarify:

 

http://www.cs.mtu.edu/~shene/COURSES/cs3621/NOTES/spline/B-spline/bspline-derv.html

 

If you're interested in getting code snippets for B-splines, "The NURBS Book" by Piegl and Tiller is a great resource. I would also like to know what you're using B-splines for. I work with CAD surfaces a lot and it's good to see someone else interested in them too.

 

 

Mathematically you are correct, but the terminology is wrong.

There is a difference between Bézier curves and B-splines (both 2D).

And their higher dimensional counterparts Bézier surfaces and NURBS (both 3D).

A B-spline is made of multiple weighted bezier curves, broadly speaking.

 

But the equations you have there seem like they belong to a Bézier surface not a B-Spline surface (or NURBS).

Their derivatives can be calculated with different approaches. I think using De Casteljau's algorithm is a easy one.

The equations that OP posted are the equations for a B-spline surface as well as a Bezier surface. The only difference is which basis functions appear as the \(N_{i,p}(u)\) terms. If it's the Bernstein basis functions, the surface is Bezier; if it's B-spline basis functions, then it's a B-spline surface. Strictly speaking, the B-spline basis is a generalization of the Bernstein basis.

 

Bezier and B-spline curves can be 3D spatial curves, and thus could also be described as 4D rational curves as well. B-splines can be decomposed into Bezier curves via generalizations of the de Casteljau method, like the Cox-de Boor or Boehm algorithm, or also known as knot refinement.

 

You're right that the equations posted don't describe a rational surface. Those equations would look like this:

\[ S(u,v) = \frac{\sum_{i=0}^n \sum_{j=0}^m w_{ij} P_{ij} N_{i,p}(u) N_{j,q}(v)}{\sum_{i=0}^n \sum_{j=0}^m w_{ij} N_{i,p}(u) N_{j,q}(v)} \]


Edited by cadjunkie, 02 May 2014 - 09:39 AM.


#4 mrhyperpenguin   Members   -  Reputation: 301

Like
0Likes
Like

Posted 02 May 2014 - 11:57 PM

Thanks guys. With your help I have been able to compute what appears to be the correct normals (when compared to the central differences method.)

 

Mathematically you are correct, but the terminology is wrong.

 

I don't have too much background in these topics so it's completely possible I'm using the terminology wrong. But yes, I am dealing with B-spline surfaces. I'm just assuming that all the weights are one (for now).

 

The control points aren't functions of u or v, so  you don't have to take derivatives of them. They're really just constants. You should be fine computing the derivative like you want. The tricky part is taking the derivatives of the B-spline basis functions. The functions themselves are built recursively, so the derivatives of a B-spline basis function of degree n can be formulated in terms of B-spline basis functions of degree n-1. This website should clarify:

 

http://www.cs.mtu.edu/~shene/COURSES/cs3621/NOTES/spline/B-spline/bspline-derv.html

 

Thanks for the clarification. It was actually the website you posted that initially confused me. Their definition for \(Q_i\) involves a difference in control points but I see now that that is from a simplification and not from the derivative.

 

I actually found the computation of the basis functions and their derivatives to be pretty simple. I just took a dynamic programming approach and computed the values from their definition directly. As long as you compute them from the "bottom up" and store the values as you go, the code is relatively simple and straight forward. Though, I haven't looked at the algorithms you guys posted, so maybe there are gains to be made somewhere.

 

I don't have a particular use case for B-spline surfaces in mind at the moment. I'm more experimenting with GPU tessellation and decided to use B-splines. Now I'm going to come up with an intelligent level of detail scheme and see how many I can render at once.

 

I would be interested in hearing what you guys are doing with them though.

 

Thanks again,

Victor

 

 



#5 cadjunkie   Members   -  Reputation: 1273

Like
0Likes
Like

Posted 05 May 2014 - 09:51 AM

That's good that you were able to figure it out. Doing the recursive algorithm to evaluate the B-spline basis functions isn't a bad way to go about it, but there are gains to take advantage of. For example, you can take advantage of the local support property to only calculate the nonzero B-spline basis functions and save yourself a bit of computation. Also, there are ways to do away with recursion when computing the B-spline basis functions.

 

I'm actually trying to write a complete trimmed B-spline visualization program so I'm actually very interested in your approach and your results. Post them if you get a chance.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS