This topic is now archived and is closed to further replies.


body by nurbs

Recommended Posts

themule    122
is it possible to make a nurbs surface that wraps around to connect to itself from behind? like a distorted cylinder... or the outline surface of a human figure? making these nurbs surfaces by specifying all the control points/points on the surface is very tedious, so i just wanted to confirm if the above is possible before attempting to make another nurbs surface. thanks.

Share this post

Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Pretty much any of these parametric curve/surface formats that can represent conic sections can represent surfaces of revolution (2D curve revolved around an axis to get a surface). NURBS curves give good circles, so yes, it is very possible to make a distorted cylinder using NURBS. Not sure if it is such a good idea to skin an entire human model using just one surface; you''d probably want many different patches for this. If you''re interested in the subject, look up The NURBS Book by Piegl and Tiller; it''s pretty much the definitive reference for NURBS.

Share this post

Link to post
Share on other sites
snisarenko    526
Try to do a body by Vicotria''s Secret ..... cause all u see is curves ..... lol

My Website: [link][/link]
or directly at
"I''ve read about...doom being used to manage unix programs(you "kill" the processes)" dede

Share this post

Link to post
Share on other sites
themule    122
ok i have a slightly different question now:
what if i have the actual points on a curve, and i want to know the control points for a nurbs that could render the curve in opengl? since opengl nurbs capability is just limited to having control points as input, it is of no use to me if i dont have the control points for my curve. how to get the control points for my curve(s)?

Share this post

Link to post
Share on other sites
UnIcron    122
A couple of months ago I was wondering much the same thing. Since then I''ve done some research. Although my knowledge is not yet complete, I''ll try to answer your question as best I can.

I believe you''re right about the OpenGL API not being much help in curve-fitting. Consequently, you must first understand the mathematical definition of NURBS because you will have to right your own routine for evaluating them.

(I ask for forgiveness in advance for the no doubt ugly formatting)
A NURBS curve is given by

/__ Ni, p(u)wiPi
i = 0
/__ Ni, p(u)wi
i = 0

The parameter u typically ranges from 0 to 1.
The Pi are the control points.
The wi are weights associated with each control point.

The Ni, p in this definition are given by a function known as the B-spline basis function. This is

Ni,0(u) = 1 if ui<=u<ui+1
0 otherwise

Ni,p(u) =

u - ui*Ni,p-1(u) +

ui+p+1 - u * Ni+1,p-1(u)

The p in this definition represents the degree of the curve. The subscripted u''s come from a nondecreasing dequence of numbers called the knot vector. This knot vector is denoted as U={u0,...,um}.

The knot size of the knot vector, the number of control points, and the degree of the curve are all related by

m = n + p + 1,
where p is the degree, n+1 is the number of control points, and m+1 is the number of knots.

If all the weights are the same (ignoring the case where they are 0), the weights cancel each other out in the definition, the denominator becomes 1 (because B-spline basis functions must give you an affinie combination of points -- don''t worry if you don''t understand this), and you are left with a special type of NURBS curve call a B-spline curve:

/__ Ni, p(u)Pi
i = 0

So, when you specify a NURBS curve through OpenGL, you must give the control points, the knot vector, and the set of weights. I haven''t used the gluNURBS interface that much, but I''m pretty sure it gives you the option of specifying either 3 or 4 values per control point. The fourth one is probably the weight, and if you don''t use it you''ll probably get a B-spline curve.

Now, on to the problem at hand. I''m assuming you want to do curve fitting using a B-spline curve. I found one algorithm to do this called global interpolation in The NURBS Book by Piegl and Tiller.

The method begins with a set of points Qk,k=0,...,n. You want to fit a p degree B-spline curve to this data. To do so, you must associate a certain parameter value with each point that you have. You then use these values to obtain the knot vector. After this, you make a system of linear equations using the parameter values and points you have and solve this system to obtain the control points you need.

Let zk denote the parameter values that you want to get. They calculate these as follows:

d =
/__ |Qk - Qk-1|
i = 0

z0=0 zn=1

uk=uk-1 + |Qk-Qk-1|
for k = 1,...,n - 1.

Once the parameters are calculated, the knot vector is determined by averaging them together:

um-p=...=um = 1

1 __
- \
p /__ zi
i = 0

for j = 1,...,n - p.

Remember, once you have the degree of the curve and the number of control points you want, you can discover the number of elements you must have in the knot vector by means of
m = n + p + 1.
The number of control points you want is necessarily equal to the number of points that you have in this algorithm.

Once you have obtained the parameter sampling, you can set up a system of linear equations in order to find what control points would give you the points you have at the parameter sampling you obtained.

For example, assume you start out with 5 points and want a cubic curve (degree 3). Let the control points you want be given by
Si =(p0,p1,p2,p3,

This is basically one row of a matrix that contains all of the B-spline basis functions evaluated at the appropriate intervals:
Ti = ( N0,3(zi),
N4,3(zi) )

Then you have that

Ti dot Si = Qi

for i ranging from 0 to 4.

This is clearly a system of linear equations. Actually, it is more than one system, since the points most likely have at least two components; you have to solve each one. In case you do not know how to solve linear equations, I will give a brief example.

Start out with the following system of equations:

x - 3z = -2
3x + y - 2z = 5
2x + 2y + z = 4

The coefficient matrix is given by taking the coefficients in front of every variable

1 0 -3
3 1 -2
2 2 1

The augmented matrix is the same except that the constants on the righthand sides of the equations are included as an extra column

1 0 -3 -2
3 1 -2 5
2 2 1 4

In situations like this, elementary row operations consist of multiplying a row by a nonzero constant, adding a multiple of one row to another, and interchanging two rows. Your goal is to take the matrix you start out with, perform these elementary row operations on it, and then arrive at a matrix in something called reduced row-echelon form. Row-echelon form means that all rows that are completely zeros are at the bottom, each row not entirely zeros begins with a one, and for two rows not entirely zeros, the 1 in the ''higher'' row has to be further to the ''left''.

If you were to perform these operations on the example above, you should eventually end up with

1 0 0 4
0 1 0 -3
0 0 1 2

What this tells you is that z = 2, y = -3, x = 4 is the solution to this system of equations. This is exactly the same thing you would do at the last step of B-spline curve fitting, only you have to evaluate the basis functions at the specified parameters first in order to get the coefficients.

Despite the relatively lengthy mathematical theory, implementing a simple curve fitting algorithm really is not that bad, but you must first possess routines to evaluate B-spline basis functions and evaluate systems of linear equations. Although several optimizations are possible, writing simple code to accomplish these tasks shouldn''t be that terrible, either. You might want to look into what happens when a system has no solution or an infinite number of solutions, however.

I hope I have been of assistance, but I''m not really an expert in this stuff either, and I probably can''t explain it as well as I like. Please let me know if you have any questions or think I made a mistake somewhere. My best general advice is to make sure you understand the mathematical theory behind NURBS before you try to use them in OpenGL.

Share this post

Link to post
Share on other sites