Im trying to do a simple rotation to a point, but i dont know why im not getting it accurate.
as i know the cos and sin expect an angle in radian.
f.e. I want to rotate a point A(x1,y1) around a Point (xo,yo) with 270 degree.
lets assume
qreal xo,yo,x1,y1,radianAngle,angle;
qreal newX,newY;
angle = 270;
radianAngel = angle * M_PI/180;
xo = 0;
yo = 0;
x1 = 0;
y1 = 1000;
qreal c = cos(radianAngel);
qreal s = sin(radianAngel);
newX= (x1-xo) * c - (y1-yo) * s+yo;
newY= (x1-xo) * s + (y1-yo) * c+yo;
qDebug
()<<
QString("rotatin x=%1 , y=%2 with %3 = newx=%4 newy=%5") .arg(x1)
.arg(y1)
.arg(angel)
.arg(newX)
.arg(newY);
// this is what i get !!
// "rotating x=0 , y=1000 with 270 = newx=1000 newy=-1.83691e-13"
qreal xo,yo,x1,y1,radianAngle,angle;
qreal newX,newY;
angle = 270;
radianAngel = angle * M_PI/180;
xo = 0;
yo = 0;
x1 = 0;
y1 = 1000;
qreal c = cos(radianAngel);
qreal s = sin(radianAngel);
newX= (x1-xo) * c - (y1-yo) * s+yo;
newY= (x1-xo) * s + (y1-yo) * c+yo;
qDebug()<< QString("rotatin x=%1 , y=%2 with %3 = newx=%4 newy=%5")
.arg(x1)
.arg(y1)
.arg(angel)
.arg(newX)
.arg(newY);
// this is what i get !!
// "rotating x=0 , y=1000 with 270 = newx=1000 newy=-1.83691e-13"
To copy to clipboard, switch view to plain text mode
I don't know why for the newY im not getting "0" instead i'm getting "-1.83691e-13".
so the issue is when i transfer to radian and get the cos and sin im not getting the exact correct value.
any suggestion, or what mistake im doing.
Thanks
Bookmarks