1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
#include<stdio.h>
#include <time.h>
#include <cstdlib>
#include <math.h>
int randfun(int arrX[], int arrY[],int size);
int cenfun(int arrX[], int arrY[],int size);
int rotatefun(int arrX[], int arrY[],int size,double center_x,double center_y);
int distfun(int arrX[], int arrY[],int size);
int main()
{
const int size = 6;
int arrX[size];
int arrY[size];
randfun(arrX, arrY,size);
double b = 0;
double a = cenfun(arrX, arrY, size);
rotatefun(arrX, arrY,size,a,b);
double distance = distfun(arrX, arrY, size);
return 0;
}
int randfun(int arrX[], int arrY[],int size)
{
srand((unsigned)time(NULL));
int x, y;
int xsign, ysign;
printf("random numbers are\n");
for (int i = 0; i < size; i++)
{
x = rand() % 100;
y = rand() % 100;
xsign = rand() % 2;
ysign = rand() % 2;
if (xsign) x *= -1;
if (ysign) y *= -1;
arrX[i] = x;
arrY[i] = y;
}
for (int i = 0; i < size; i++)
{
printf("%3d %3d\n", arrX[i], arrY[i]);
}
return 0;
}
int cenfun(int arrX[], int arrY[], int size)
{
double center_x,center_y;
center_y = 0;
center_x = 0;
for (int i = 0; i < size; i++)
{
center_x += arrX[i] / size;
center_y += arrY[i] / size;
}
printf("center of gravity is ");
printf("%lf %lf\n", center_x, center_y);
return 0;
}
int rotatefun(int arrX[], int arrY[],int size,double center_x,double center_y)
{
for (int i = 0; i < size; i++)
{
double rot_x, rot_y;
printf("rotate points are ");
rot_x = ((arrX[i] - center_x) * cos(0.122) + center_x) - ((arrY[i] - center_y) * sin(0.122) + center_y);
rot_y = ((arrX[i] - center_x) * cos(0.122) + center_x) + ((arrY[i] - center_y) * sin(0.122) + center_y);
printf("%lf %lf\n", rot_x, rot_y);
}
return 0;
}
int distfun(int arrX[], int arrY[], int size)
{
double dist_total = 0,dist;
for (int i = 0; i < size; i++)
{
dist =(arrX[i] * arrX[i] + arrY[i] * arrY[i]);
dist_total += sqrt(dist);
}
printf("total distance is ");
printf("%lf\n", dist_total);
return 0;
}
|