Results 1 to 2 of 2
Thread: problem for draw a b-spline
- 02-21-2010, 09:39 PM #1
Member
- Join Date
- Feb 2010
- Posts
- 2
- Rep Power
- 0
problem for draw a b-spline
Hi,
I am new to computer graphic calculations. When I tried to write a program to draw a b-spline according to the points given, but the result makes me confused.
According to the formula
Ni,p(t) = Ni,p(t) (t - ti)/(ti+p - ti) + Ni+1,p(t) (ti+p - t)/(ti+p - ti+1) ,
Ni,0 = {1 if ti <= t <= ti+1 , 0 otherwise }
so I had my methods to compute the b-spline basis and set the path like below:
the variables used:Java Code:private double bsplineBasis(double u, int i, int p) { if(p==0){ if(U[i]<=u&& u<U[i+1]){ return 1; } else{ return 0; } } else{ double t1 = (u-U[i])/(U[i+p]-U[i]); double t2 = (U[i+p+1]-u)/(U[i+p+1]-U[i+1]); double n1 =bsplineBasis(u,i,p-1); double n2 =bsplineBasis(u,i+1,p-1); double c1 =0; if (n1!=0) { c1 =t1*n1; } double c2 =0; if (n2!=0) { c2 =t2*n2; } return c1 + c2; } } private void setPath() { path.reset(); int n = points.length; int w = getWidth(); for(int j = 0; j <= w; j++) { double t = (double)j/w; // [0 <= t <= 1.0] double x = 0; double y = 0; for(int k = 0; k < n; k++) { x += bsplineBasis(t,k,p)*points[k].x; y += bsplineBasis(t,k,p)*points[k].y; } if(j > 0) path.lineTo(x,y); else path.moveTo(x,y); } }
Point[] points;
double U[] = {0,0,0,0,0.5,1,1,1,1};
int p = 3;
And the result is like that:

It looks like the point[0,0] is automatically added as the last control point. since I have enforced the path end at the last control point, so the path turns sharply at the last part.
Anyone can tell me what is wrong with the methods, thanks very much..Last edited by teken2004; 02-22-2010 at 04:35 AM. Reason: something new
- 02-22-2010, 12:38 PM #2
Member
- Join Date
- Feb 2010
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Finding where to draw
By flok in forum AWT / SwingReplies: 4Last Post: 11-24-2009, 05:55 PM -
how to draw an arc
By Baker in forum New To JavaReplies: 1Last Post: 04-16-2009, 09:05 PM -
How to draw images in SWT
By Java Tip in forum SWTReplies: 0Last Post: 07-02-2008, 08:02 PM -
How to Draw Arc in Java
By Java Tip in forum java.awtReplies: 0Last Post: 06-23-2008, 11:12 PM -
help me draw... please...
By kureikougaiji in forum New To JavaReplies: 1Last Post: 01-28-2008, 12:22 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks