Hi....
I'm having difficulties with my codes to list coordinates (in my example codes is 4x4 pixel). I tried two different codes and the results are different.Basic ally, I tried to declare the sub coordinates for x and y, and then print it. But, if I make a change by declaring sub coordinates for x and print it, and the declare sub coordinate for y and print it, the results are different.
I have tried to calculated manually, the right answers is the last codes.
I just carious if I have something wrong in my codes, because I want to find the max and min value for each array and other stuffs and I have to do it separately like listing the coordinate. And that not so efficient.
So, could you help me, please, to find the wrong lines?
Thank you...
Here is my first codes:
I'm having difficulties with my codes to list coordinates (in my example codes is 4x4 pixel). I tried two different codes and the results are different.Basic ally, I tried to declare the sub coordinates for x and y, and then print it. But, if I make a change by declaring sub coordinates for x and print it, and the declare sub coordinate for y and print it, the results are different.
I have tried to calculated manually, the right answers is the last codes.
I just carious if I have something wrong in my codes, because I want to find the max and min value for each array and other stuffs and I have to do it separately like listing the coordinate. And that not so efficient.
So, could you help me, please, to find the wrong lines?
Thank you...
Here is my first codes:
Code:
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include <conio.h>
#define size 4
#define size2 size*size
#define point1 (size+1)
#define point2 (size+1)*(size+1)
#define rotation 45
#define deg rotation*3.14159265/180
int main()
{
float xr[point2], yr[point2]; // coordinates before rotation
float xb[point2], yb[point2]; // coordinates after rotation
float bx[size][4],by[size][4]; // Group of coordinates after rotation
float bx_max[size],bx_min[size],by_max[size],by_min[size]; //maksimum and minimum value for bx and by
int i,j;
int a;
FILE*ftulis;
ftulis=fopen("hasilrena.txt","w");
fprintf (ftulis,"xr\t \t yr\n");
for (i = 0; i < point1; i++){
for (j = 0; j < point1; j++){
xr[j+i*point1] = -(size/2) + j;
yr[j+i*point1] = (size/2) - i;
}
}
for ( i = 0; i < point2; i++){
fprintf (ftulis,"%f\t%f\n",xr[i],yr[i]);
}
// NEW COORDINATES
fprintf (ftulis,"xb\t \t yb\n");
for (i = 0; i < point2; i++){
xb[i] = xr[i]*cos(deg) - yr[i]*sin(deg);
yb[i] = xr[i]*sin(deg) + yr[i]*cos(deg);
//printf ("%f\t%f\n",xb[i],yb[i]);
fprintf (ftulis,"%f\t%f\n",xb[i],yb[i]);
}
//Subcoordinate -x
for (i = 0; i < size; i++){
for (j = 0; j < size; j++){
bx[j+i*size][0]=xb[j+i*point1];
bx[j+i*size][1]=xb[1+j+i*point1];
bx[j+i*size][2]=xb[j+(i+1)*point1];
bx[j+i*size][3]=xb[1+j+(i+1)*point1];
}
}
//Subcoordinate -y
for (i = 0; i < size; i++){
for (j = 0; j < size; j++){
a=j+i*size;
by[a][0]=xr[a+i]*sin(deg) + yr[a+i]*cos(deg);
by[a][1]=xr[a+1+i]*sin(deg) + yr[a+1+i]*cos(deg);
by[a][2]=xr[a+i+point1]*sin(deg) + yr[a+i+point1]*cos(deg);
by[a][3]=xr[a+i+1+point1]*sin(deg) + yr[a+i+1+point1]*cos(deg);
}
}
[B]//Print subcoordinat -x
fprintf (ftulis,"\n");
fprintf (ftulis,"\tbx[0]\t\tbx[1]\t\tbx[2]\t\tbx[3]\n");
for ( i = 0; i < size2; i++){
fprintf(ftulis,"bx[%d]\t%f\t%f\t%f\t%f\n",i,bx[i][0],bx[i][1],bx[i][2],bx[i][3]);
}
//Print subcoordinate -y
fprintf (ftulis,"\n");
fprintf (ftulis,"\tby[0]\t\tby[1]\t\tby[2]\t\tby[3]\n");
for ( i = 0; i < size2; i++){
fprintf(ftulis,"by[%d]\t%f\t%f\t%f\t%f\n",i,by[i][0],by[i][1],by[i][2],by[i][3]);
}
[/B]
fclose(ftulis);
getch();
}
And, here my second codes:
#include <stdlib.h>
------------------------------------
---------------------------------
same with above until print the new coordinates
//Subcoordinate -x
for (i = 0; i < size; i++){
for (j = 0; j < size; j++){
bx[j+i*size][0]=xb[j+i*point1];
bx[j+i*size][1]=xb[1+j+i*point1];
bx[j+i*size][2]=xb[j+(i+1)*point1];
bx[j+i*size][3]=xb[1+j+(i+1)*point1];
}
}
fprintf (ftulis,"\n");
fprintf (ftulis,"\tbx[0]\t\tbx[1]\t\tbx[2]\t\tbx[3]\n");
[B]//Print subcoordinate -x
for ( i = 0; i < size2; i++){
fprintf(ftulis,"bx[%d]\t%f\t%f\t%f\t%f\n",i,bx[i][0],bx[i][1],bx[i][2],bx[i][3]);
} [/B]
for (i = 0; i < size; i++){
for (j = 0; j < size; j++){
a=j+i*size;
by[a][0]=xr[a+i]*sin(deg) + yr[a+i]*cos(deg);
by[a][1]=xr[a+1+i]*sin(deg) + yr[a+1+i]*cos(deg);
by[a][2]=xr[a+i+point1]*sin(deg) + yr[a+i+point1]*cos(deg);
by[a][3]=xr[a+i+1+point1]*sin(deg) + yr[a+i+1+point1]*cos(deg);
}
}
fprintf (ftulis,"\n");
fprintf (ftulis,"\tby[0]\t\tby[1]\t\tby[2]\t\tby[3]\n");
[B]//print subcoordinate-y
for (i = 0; i < size2; i++){
fprintf(ftulis,"by[%d]\t%f\t%f\t%f\t%f\n",i,by[i][0],by[i][1],by[i][2],by[i][3]);
} [/I][/B]
fprintf (ftulis,"\n");
fclose(ftulis);
getch();
}