![]() |
|
|||||||
|
|
Thread Tools | Search this Thread | Rate Thread |
|
#1
|
|||
|
|||
Problems with different variables returning the same valueIm trying to create a program to display a curved line which is infact lots of smaller straight lines. The user inputs the corners of a polygon and the "weighting" of each of these. The program then passes the data through a formula and gives us first x,x01, and y,y01, coordinates after which a control variable is changed and the second x,x02, and y,y02, coordinates are returned giving the coordinates for a single line. The problem I go to display the line the values for x01,y01 and x02,y02 are the same giving me just a single dot. When I run the program without the graphics, and i printf after each "bit" of math the x01,x02,y01,y02 ar different but when i put the two programs together I get the same values and I cant see why. I would appreciate any help on this problem.
CPP / C++ / C Code:
|
|
#2
|
|||
|
|||
|
After playing around with the program and trying to rearrange pretty much everything to get it to work Iv found out that for some strange reason if i put,for instance(spelling), np=4 so now it would go through the loop 4 times and give me 4 graphics windows. The thing is every single graphics window is exactly the same, with just a single dot at(im guessing) 10,200 which is the first values i put in for x,y, and maybe the first value returned for x01,y01 but i cant b sure. I have no idea why the program would return me the values for x01,x02 equal to x0 that i input, when i have calculations which i know change these values.
|
|
#3
|
|||
|
|||
|
You declare np as an int, so the expression 1/np has value of 1 when np = 1, and has a value of 0 when np > 1.
Try 1.0/np instead of 1/np. Dave |
|
#4
|
|||
|
|||
|
It doesnt make any difference sadly, i thiNk whats wrong is its passing the values for x01 and y01 when u=0 which is the only value which would return the results i get. But i dont understand why it would pass this result np times when the value should change each time it goes through the loop.
|
|
#5
|
|||
|
|||
|
There is no way that I can test your program.
Here's a suggestion: put printf() statements after each calculation. For example: CPP / C++ / C Code:
Look at what happens when you use CPP / C++ / C Code:
Of course, if you do the calculations correctly you will never have u = 0, but look at what happens when you use CPP / C++ / C Code:
When you have the correct values for all calculated values, then you can debug your display routines. printf() is your friend. Good luck! Dave |
|
#6
|
|||
|
|||
|
Quote:
Of course, I didn't mean that you should put printf() statements in your program as it stands. I commented out the windows stuff and made a console program that uses your calculations and displays the results of all calculations with printf() statements. The idea is that I think it's vital that you convince yourself that the formulas in your program give expected results without having to worry about whether "the results are OK, but the display is bad," or whatever. Dave Last edited by davekw7x : 20-Mar-2004 at 17:12.
|
|
#7
|
|||
|
|||
|
My original program doesnt include windows.h just because it not my favourite thing to work with an djust diving straight in is never a good idea. I tested the return of the x01,x02,y01,y02 values compared to the u values and they seemed to work fine but i never thought to check the rest of the values. This is my program as it was:
CPP / C++ / C Code:
I put in the checker to see if the values for np...etc. were correct and found that after a while of calculator abuse they seem all to be correct which really leaves me lost as to why the winio program doesnt return the values that I expect and that are returned perfectly when I pass them without the winio code. |
|
#8
|
|||
|
|||
|
Quote:
Can't help you with winio. You still have an expression u=u+1/np. I can't believe that's right, but if you are satisfied with your calculated values, I'll shut up. Regards, Dave |
|
#9
|
|||
|
|||
|
Quote:
|
|
#10
|
|||
|
|||
|
Quote:
This was indeed the right answer, I thought this was not the case to start with seeing as winio wouldnt support an int and my first program operated fine, I didnt realise but you can switch an int into a float by sticking another variable of type float in: CPP / C++ / C Code:
Iv nearly completely finished the problem all i need now is to create a function to find the maximum value of 4 given values,x1,x2,x3,x4, and i was wondering if there was anyway of doing this more easily than constructing multiple if statements? As the code i have at the moment is full of these already. Just in case anyone is slightly interested this is my code so far: [c] #pragma windows 300000,500000,"cwp_ico.rc" //means dosbox is not displayed #include<stdio.h> #include<math.h> #include<clib.h> #include<windows.h> #include<dbos\graphics.h> float u=0, g, p, s, t, x0=0, y0=0, np=1; int b4=0, b3=0, b2=0, b1=1, r1=0, r2=0, r3=1, x1=1, x2=1, x3=1, x4=1, y1=1, y2=1, y3=1, y4=1, w1=1, w2=1, w3=1, w4=1, hand=0, ctrl, c=0, num=2, col=0, wid=2, Draw(); short int x[100],y[100];//array with a maximum of 100 values int main(void) { { winio("%bg%ca[Data Input Screen]&",RGB(100,255,100)); winio("%fn[Arial]%tsEnter in 4 values for the x coordinates: \t%rd\t% rd\t%rd\t%rd\n&",1.2, &x1, &x2, &x3, &x4); winio("Enter in 4 values for the y coordinates: \t%rd\t%rd\t%rd\t% rd\n&",&y1, &y2, &y3, &y4); winio("Enter in 4 values for the weighting: \t%rd\t%rd\t%rd\t% rd\n&",&w1, &w2, &w3, &w4); winio("Enter in the number of points to be on the line:\t\t\t\t\t\t% rd\n&",&num); winio("Please choose a colour:\t\t\t%4`ga%rb[Red]\t\t%rb[Blue]\t\t%rb [Green]\t%rb[Purple]\n&",&b1,&b2,&b3,&b4,&b1,&b2,&b3,&b4); //4 radial buttons return boolean answers only one can be "on" winio("Please select a line thickness:\t\t%3`ga%`rb[ Thin ]\t\t\t%`rb [Medium]\t\t%`rb[Thick ]&",&r1,&r2,&r3,&r1,&r2,&r3); //boolean answers only one can return "1" winio("\n\t\t %bc[red]%^bt[Draw]",Draw); np=(float)num;//converts num into a float { do { p = (pow(1 - u, 3));//=(1-u)(1-u)(1-u),to the power of g = (3 * (pow(1 - u, 2) * u)); s = (3 * pow((1 - u) * u, 2)); t = pow(u, 3); x0=((p*w1*x1)+(g*w2*x2)+(s*w3*x3)+(t*w4*x4))/ ((p*w1)+(g*w2)+(s*w3)+(t*w4)); //starting x coordinate for a line y0=((p*w1*y1)+(g*w2*y2)+(s*w3*y3)+(t*w4*y4))/ ((p*w1)+(g*w2)+(s*w3)+(t*w4)); //starting y coordinate for a line u=u+(1/(np-1)); x[c]=x0; y CPP / C++ / C Code:
So just to reiterate and make my problem clearer. I have 4 values ,x1,x2,x3,x4 and i need to find out the maximum and minimum values so that i can scale my graphical box accordingly but Id prefer not to use a large number of if statements and was wondering if there was any other way of doing this. Again sry Dave, i would have done better to state why I ignored your suggestion. |
Recent GIDBlog
US Elections and the ?Voter?s Responsibility? by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| passing variables out of an iframe by url | JUNK KED | MySQL / PHP Forum | 5 | 31-Jul-2007 10:33 |
| GeForce FX 5600 problems | Peacemaker | Computer Hardware Forum | 24 | 18-Jul-2004 06:50 |
| Chaintech Geforce 5600 FX problems | bartster74 | Computer Hardware Forum | 8 | 04-May-2004 14:16 |
| Apache on Windows XP and passing variables | Jos Elkink | Apache Web Server Forum | 4 | 21-Nov-2003 03:21 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The