Results 1 to 2 of 2
Thread: problem for draw a bspline
 02212010, 10:39 PM #1Member
 Join Date
 Feb 2010
 Posts
 2
 Rep Power
 0
problem for draw a bspline
Hi,
I am new to computer graphic calculations. When I tried to write a program to draw a bspline 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 bspline basis and set the path like below:
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 = (uU[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,p1); double n2 =bsplineBasis(u,i+1,p1); 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; 02222010 at 05:35 AM. Reason: something new
 02222010, 01:38 PM #2Member
 Join Date
 Feb 2010
 Posts
 2
 Rep Power
 0
Similar Threads

Finding where to draw
By flok in forum AWT / SwingReplies: 4Last Post: 11242009, 06:55 PM 
how to draw an arc
By Baker in forum New To JavaReplies: 1Last Post: 04162009, 09:05 PM 
How to draw images in SWT
By Java Tip in forum SWT TipsReplies: 0Last Post: 07022008, 08:02 PM 
How to Draw Arc in Java
By Java Tip in forum java.awtReplies: 0Last Post: 06232008, 11:12 PM 
help me draw... please...
By kureikougaiji in forum New To JavaReplies: 1Last Post: 01282008, 01:22 PM
Bookmarks