GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 04-Mar-2004, 03:51
warny_maelstrom warny_maelstrom is offline
Junior Member
 
Join Date: Jan 2004
Posts: 41
warny_maelstrom will become famous soon enough

Bezier curve.


My code has no errors or warnings but it just closes after asking for the values for w, and i have no clue y. Im trying to work out the coordinates on a bezier curve, the maths is fine i think but the code just doesnt work like i want it to.
CPP / C++ / C Code:
#include<stdio.h>
#include<math.h>

main()
{
float u,g,p,s,t,x,y;
int xr0,xr1,xr2,xr3,yr0,yr1,yr2,yr3,w0,w1,w2,w3;

u=0;


printf("Enter in r values for the x coordinates e.g. x0,x1,x2,x3\n");
scanf("%d,%d,%d,%d",&xr0,&xr1,&xr2,&xr3);
printf("Enter in r values for the y coordinates e.g. y0,y1,y2,y3\n");
scanf("%d,%d,%d,%d",&yr0,&yr1,&yr2,&yr3);
printf("Enter in w values e.g. w0,w1,w2,w3\n");
scanf("%d,%d,%d,%d",&w0,&w1,&w2,&w3);


if (u=0,u<1)
        {
        p=(pow(1-u,3));
        g=(3*(pow(1-u,2)*u));
        s=(3*pow((1-u)*u,2));
        t=pow(u,3);

        x=((p*w0*xr0)+(g*w1*xr1)+(s*w2*xr2)+(t*w3*xr3))/((p*w0)+(g*w1)+(s*w2)+(t*w3));
        printf("\n",x);

        y=((p*w0*yr0)+(g*w1*yr1)+(s*w2*yr2)+(t*w3*yr3))/((p*w0)+(g*w1)+(s*w2)+(t*w3));
        printf("\t",y);
        u=(u+0.2);
        }
else
return 0;

}
Edit: i managed to solve the first problem myself so now the title is wrong and misleading but i couldnt delete this post.
  #2  
Old 04-Mar-2004, 08:42
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Warny, you may want to repost your code if you fixed the problem and are still having problems with something else. I see several things that look wrong in this program, but I don't want to comment on something that you already fixed.
  #3  
Old 04-Mar-2004, 09:15
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,372
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
And be specific. "It doesn't do what I want it to" is not a problem. What it does do is, as well as what it's supposed to do. Both these are needed for a solution.
  #4  
Old 04-Mar-2004, 09:23
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,303
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Here's a suggestion whenever your program doesn't give the answers that
you expect:

Every time you obtain input values (from user console input or from a
file), print out their values. For example:

CPP / C++ / C Code:
printf("Enter in r values for the x coordinates e.g. x0,x1,x2,x3\n");
scanf("%d,%d,%d,%d",&xr0,&xr1,&xr2,&xr3);
printf("Debug: Here is what you entered: <%d> <%d> <%d> <%d>\n\n", xr0, xr1, xr2, xr3);

Note that using scanf() requires the user to input the data exactly as indicated
in the specificaton. So, for example, the user must enter integer values
separated by commas in each case.

I am sure that your if( ) condition is not doing what you had in mind,
but: first things first. Verify the input!

Dave
  #5  
Old 04-Mar-2004, 10:52
warny_maelstrom warny_maelstrom is offline
Junior Member
 
Join Date: Jan 2004
Posts: 41
warny_maelstrom will become famous soon enough
My code works perfectly now i managed to fix my problem, which as i didnt state it b4 was the fact that i wasnt given any output for values of x and y. Now when i print the values of x and y i get the output:
x1 y5
x2 y6
x3 y7
whereas id prefer the numbers for the y values to b y1,y2,y3. Is there any way of doing this.
CPP / C++ / C Code:
#include<stdio.h>
#include<math.h>

int main(void) /* main returns an int */
{
    float u, g, p, s, t, x, y;
    int xr0, xr1, xr2, xr3, yr0, yr1, yr2, yr3, w0, w1, w2, w3;
    u = 0;

    printf("Enter in r values for the x coordinates e.g. x0,x1,x2,x3\n");
    scanf("%d,%d,%d,%d", &xr0, &xr1, &xr2, &xr3);
    printf("Enter in r values for the y coordinates e.g. y0,y1,y2,y3\n");
    scanf("%d,%d,%d,%d", &yr0, &yr1, &yr2, &yr3);
    printf("Enter in w values e.g. w0,w1,w2,w3\n");
    scanf("%d,%d,%d,%d", &w0, &w1, &w2, &w3);

for ( u = 0 ; u < 1 ; u += 0.2 ) {
        p = (pow(1 - u, 3));
        g = (3 * (pow(1 - u, 2) * u));
        s = (3 * pow((1 - u) * u, 2));
        t = pow(u, 3);

        x = ((p * w0 * xr0) + (g * w1 * xr1) + (s * w2 * xr2) + (t * w3 * xr3)) / ((p * w0) + (g * w1) + (s * w2) + (t * w3));
        printf("\nx%f", x); 

        y = ((p * w0 * yr0) + (g * w1 * yr1) + (s * w2 * yr2) + (t * w3 * yr3)) / ((p * w0) + (g * w1) + (s * w2) + (t * w3));
        printf("\ty%f\n\n", y); 
        u = (u + 0.2);
        }
    return 0;
}
  #6  
Old 04-Mar-2004, 11:30
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Quote:
Originally Posted by warny_maelstrom
whereas id prefer the numbers for the y values to b y1,y2,y3. Is there any way of doing this.
I don't know what you mean here. Do you mean that you want the values of y to be 1,2,3 respectively as you go through your loop? Wouldn't that depend on your input values of yr0 through yr3?

Also, did you mean to double index your for loop? (you are incrementing by 0.4 each time you go through the loop

CPP / C++ / C Code:


for ( u = 0 ; u < 1 ; u += 0.2 ) {
         //....
        u = (u + 0.2);
        }
  #7  
Old 04-Mar-2004, 11:37
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,303
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Well, I claim that if the output doesn't look like you want it to, that the "code" isn't working "perfectly". (Just my little attempt at humor; but, seriously, output is an important part of the code --- actually it is (usually) the only thing that the user sees.)

You want to print the results for what value(s) of u?

As a debugging aid, I suggest the following:


In place of your statement
CPP / C++ / C Code:
printf("\nx%f", x);

I suggest you put
CPP / C++ / C Code:
printf("For u = %f:   ", u);
printf("\nx = %f", x); 

and see if it's really what you want.

Similarly, for the y value, try

CPP / C++ / C Code:
printf("\ty = %f\n\n", y); 

Tell us how it turns out.

Regards,

Dave
  #8  
Old 04-Mar-2004, 12:25
warny_maelstrom warny_maelstrom is offline
Junior Member
 
Join Date: Jan 2004
Posts: 41
warny_maelstrom will become famous soon enough
Quote:
Originally Posted by dsmith
Also, did you mean to double index your for loop? (you are incrementing by 0.4 each time you go through the loop
k, screw wot i was asking b4 coz uv alrdy solved it or i realised that it was a really dumb question(hopeing u dont realise wot im refering to). Some im all good now cheers for helping, i might need more help if i realise that i want more from the program.
  #9  
Old 04-Mar-2004, 13:12
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,372
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Quote:
Originally Posted by warny_maelstrom
k, screw wot i was asking b4 coz uv alrdy solved it...

I don't know about the rest of you, but I'd prefer posts are written in English as opposed to lazy-geek-ish. English will be required when you get into the business sector for communication, so you might as well learn it now. Also, my brain won't hurh trying to translate messages.
  #10  
Old 04-Mar-2004, 13:19
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 564
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
Yeah, honestly, I think it's appalling how many people use such bad grammar and spelling when communicating over the internet. It's still communication, and the person on the other side is still going to get the idea that you can't speak english.
 
 

Recent GIDBlogVista ?Widgets? on Windows XP by LocalTech

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 08:02.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.