Im writing a program in C (using allegro lib) which display points (i could say some sequence) from txt file(two columns X & Y). These are floating points and they can be less than zero. Size of a window is 800x600. As we know values of x increase from left to right, but y ones increase from up to down. I have a big problem with declaring variables and scaling then. Here is a piece of code I have a problem with:
Array col1 consists of X values, col2 consists of Y values. I sort them with qsort and then get min and max. Then i declare height and width of the window and the scale..
float x_max, x_min, y_max, y_min;
x_max=(col1[(n-1)]);
x_min=(col1[0]);
y_max=(col2[(n-1)]);
y_min=(col2[0]);
int height, width;
height=600;
width=800;
float x_scale, y_scale;
y_scale = height/(fabsf(y_max)+ fabsf(y_min));
x_scale = width/(fabsf(x_max)+ fabsf(x_min));
Now i reopen txt file and create arrays not sorted arrays col1 and col2. Now i declare xpn and ypn to get the value of x or y from the array, then i mutliply it by scale and eventually i want to display it, but.. not all are displayed and they are they all are displayed wrong. I use abs and fabsf, its bad I know..
Could you help me with this code, declarationa of values of x and y and scaling them? I've tried almost everything and it doesnt work... Thx in advance :)
float xpn, ypn;
int xpoint, ypoint;
hline( screen, 5, 300, 795, makecol( 0, 0, 0 ) );
vline( screen, 400, 5, 595, makecol( 0, 0, 0 ) );
for(i=0;i<n;i++)
{
float xpn, ypn;
xpn=fabsf(col1[i]);
ypn=fabsf(col2[i]);
int xpoint, ypoint;
xpoint=abs(xpn*x_scale);
ypoint=abs(ypn*y_scale);
putpixel(screen,xpoint,ypoint,makecol(0,0,0));