Math expression does not return what I expected.
-
I wanted to track the x,y coordinates of the tip of the second's clock hand.
That clock hand has a length of 30 so I just did
@ int posx = cos(360 * (time.second() / 60.0)) * 30 + 0;
int posy = sin(360 * (time.second() / 60.0)) * 30 + 0;qDebug() << "second: " + time.toString("ss"); qDebug() << "angle: " + QString::number(360 * (time.second() / 60.0)); qDebug() << "x:" + QString::number(posx)+"y:" + QString::number(posy);@
Now what I would expect is for values such as when the seconds are 0, 15, 30, 45, 60 the angles to be
0, 90, 180, 270, 0 and the positions of curse
@x:0, y:30,
x:30, y:0,
x:0, y:-30,
x:-30, y:0,
x:0, y:30@Yet this is not what I get from the piece of code posted above. instead some values are
@"angle: 60"
"x:-28y:-9"
"second: 11"
"angle: 66"
"x:-29y:0"
"second: 12"
"angle: 72"
"x:-29y:7"
"second: 13"
"angle: 78"
"x:-25y:15"
"second: 14"
"angle: 84"
"x:-20y:21"
"second: 15"
"angle: 90"
"x:-13y:26"
"second: 16"
"angle: 96"
"x:-5y:29"@What am I doing wrong here?
EDIT
just after pressing post for this question it came to me that there might be a slight possibility Qt's sin, and cos expressions use rads instead of degrees. That fixed the issue.