Results 1 to 2 of 2
  1. #1
    teken2004 is offline Member
    Join Date
    Feb 2010
    Posts
    2
    Rep Power
    0

    Default 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:

    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);
            }
        }
    the variables used:
    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

  2. #2
    teken2004 is offline Member
    Join Date
    Feb 2010
    Posts
    2
    Rep Power
    0

    Default

    ok, the problem is because I did not follow the rule

    m = n+p+1

    where m+1 is the num of knots, n+1 is the num of control point, and p is the degree

Similar Threads

  1. Finding where to draw
    By flok in forum AWT / Swing
    Replies: 4
    Last Post: 11-24-2009, 05:55 PM
  2. how to draw an arc
    By Baker in forum New To Java
    Replies: 1
    Last Post: 04-16-2009, 09:05 PM
  3. How to draw images in SWT
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-02-2008, 08:02 PM
  4. How to Draw Arc in Java
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-23-2008, 11:12 PM
  5. help me draw... please...
    By kureikougaiji in forum New To Java
    Replies: 1
    Last Post: 01-28-2008, 12:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •