# NURBS problem

This topic is 4171 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I wonder if anyone who's grappled with NURBS before can give me a hand. I've coded a simple 2D NURBS curve evaluator, it doesn't use weights, and the knot vector is generated at runtime with values from 0.0 to 1.0 to give a uniform distribution. I've added 10 control points to the NURBS, the first 8 are the control points you see drawn below, and the last 2 are the 1st and 2nd control points added again, in an attempt to make the NURBS loop and create a closed 'blob'. The problem seems to be at the beginning and end of the curve, with some sort of overlapping, as well as some NaN values that cause those off shooting polys. After staring at the code for 2 days straight, I still can't spot the problem. Probably just need a fresh set of eyes, so any help would be much appreciated. Thanks.
class NURBS
{
// Private variables
private Vector2[] p;	// NURBS control points
private float[] t;	// NURBS knot vectors
private int k;		// NURBS degree

// Properties
public Vector2[] Points
{
get { return p; }
set { p = value; }
}

// Create the NURBS curve
public void Create(int degree)
{
// Store the degree
k = degree;

// Create the knot vector
t = new float[p.Length + k + 1];

// Loop through all the knots
for(int i = 0; i < t.Length; i++)
// Set the knot value
t = (float)i / ((float)t.Length - 1.0f);
}

// Normalized B-Spline basis function
private float N(int i, int k, float u)
{
// If the degree is zero
if(k == 0)
// Cap to the i'th knot
if((t <= u) && (u < t[i+1]))
return 1.0f;
else
return 0.0f;
// Otherwise
else
// Do the calculation
return ((u - t) / (t[i+k] - t)) * N(i, k-1, u) +
((t[i+k+1] - u) / (t[i+k+1] - t[i+1])) * N(i+1, k-1, u);
}

// Evaluate the NURBS curve
public Vector2 Evaluate(float u)
{
// Calculate the numerator
Vector2 a = new Vector2();
float b = 0;
for(int i = 0; i < p.Length; i++)
{
// Add the influences to the accumulators
float result = N(i, k, u);
a += (p * result);
b += result;
}

// Calculate and return the evaluated point
return (a / b);
}
}



1. 1
Rutin
26
2. 2
3. 3
4. 4
5. 5

• 11
• 10
• 13
• 20
• 14
• ### Forum Statistics

• Total Topics
632950
• Total Posts
3009383
• ### Who's Online (See full list)

There are no registered users currently online

×