I'm writing a program, where I have to rotate o point. But something in calculations isn't right.
That's function to rotate (Y-axis):
point3 rotY(point3 a, float angle){
float x,z;
z=a.z*cos(angle)-a.x*sin(angle);
x=a.z*sin(angle)+a.x*cos(angle);
a.z=z;
a.x=x;
return a;
}
That's point3 structure:
struct point3{
float x,y,z;
point3(){
x=y=z=0.0f;
}
point3(float a,float b,float c){
x=a;y=b;z=c;
}
};
Calling code:
point3 a(0.0f,l,0.0f);
a=rotX(a,S->angle*rad);
std::vector <point3> pocz(S->amount);
for(int i=0;i<S->amount;i++)
pocz[i]=rotY(a,(i*(360.0f/S->amount))*rad);
This (i*(360.0f/S->amount))*rad
is rotation as on this picture
I know that for expample when
a.x=0.0f
, a.y=2.36880779
and a.z=2.36880779
and i want to rotate it by 180 degrees this function will return
a.x=-2.07087751e-007
, a.y=2.36880779
and a.z=-2.36880779
.
But it should return a.x=0.0
, a.y=2.36880779
and a.z=-2.36880779
.
What can be wrong here?