Sponsors: Michael Fertik - Best JAVA Web hosting Company & 30% off


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-21-2010, 09:39 PM
Member
 
Join Date: Feb 2010
Posts: 2
Rep Power: 0
teken2004 is on a distinguished road
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:

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
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 02-22-2010, 12:38 PM
Member
 
Join Date: Feb 2010
Posts: 2
Rep Power: 0
teken2004 is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


Java Forums is supported by the best jsp hosting.

All times are GMT +2. The time now is 05:28 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org