I must rotate a set of random numbers 0.122 radians, to do it i found the center of equilibrium of the system, which code you recomend me to rotate it?
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <math.h>
usingnamespace std;
int main()
{
srand(time(NULL));
int x, y;
bool xsign, ysign; // true if negative
int arrX[5];
int arrY[5];
for (int i = 0; i<5; 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 < 5; i++)
{
printf("%3d %3d\n", arrX[i], arrY[i]);
}
double n, m;
printf("centre of gravity is");
n = (arrX[1]+arrX[2]+arrX[0]+arrX[3]+arrX[4])/5;
m = (arrY[1]+arrY[2]+arrY[0]+arrY[3]+arrY[4])/5;
printf("%lf , %lf\n", n, m);
return 0;
}
Lets say that rotation is 90 degrees and the point is (3,1).
Rotation around (0,0) transforms it to (-1,3).
Rotation around (4,1) would transform to (4,0).
PS. Your code sample gives mixed signals:
(1) You do include <iostream> that is a C++ -only feature.
(2) You use only C's functions.
The other equation was already in my first comment.
Letsa work it out with that example:
The point v is (3,1) and the center c is (4,1).
v-c == (-1,0)
Rotating that by 90 degrees (around origo) gives: (0,-1)
Add c and you get (0,-1) + (4,1) == (4,0)