Rotation from 0 to 360 Degree
Hi
I have counter range from -65536 to 65536. I am getting these counter as in this Range but i want to only show the degree 0 to 360. like if counter is 390 then it should show 30 degree . So how can i do it ?
First, my feeling is that your angle should be in [0, 359] range, not [0, 360]
Anyway, if I can suppose that :
* -65536 corresponds to 0,
* and 65536 corresponds to 359,
then it's a simple scaling question :
* scale down your value in the [0, 1] range,
* then multiply the scaled value by 359.
e.g.
v in [-65536, 65536]
v' = (v - (-65536))/(65536 - ((-65536))
v' = (v+65536)/(2*65536)
v'' = v' * 359
v'' is your value in the [0, 359] range.
Hope it helps
Anyway, if I can suppose that :
* -65536 corresponds to 0,
* and 65536 corresponds to 359,
then it's a simple scaling question :
* scale down your value in the [0, 1] range,
* then multiply the scaled value by 359.
e.g.
v in [-65536, 65536]
v' = (v - (-65536))/(65536 - ((-65536))
v' = (v+65536)/(2*65536)
v'' = v' * 359
v'' is your value in the [0, 359] range.
Hope it helps
The following code is untested and probably not the best possible sollution for you problem. On the positive side: it should work!
int c = int(counter) + 65536; int angle = c %360;
Hi
Thanx for reply But there is some confusion in post.
From Counter -Value to +Value i am getting is not fixed . for example if rotate object from once from 0 to 359 and next counter will be 360 ,361,362.....and on... if i rotate in negative direction then it starting decrease to 362....360... to 0 ... -200,
So my problem is value i am getting in any range but it should be converted to 0 to 359 degree.
Thanx for reply But there is some confusion in post.
From Counter -Value to +Value i am getting is not fixed . for example if rotate object from once from 0 to 359 and next counter will be 360 ,361,362.....and on... if i rotate in negative direction then it starting decrease to 362....360... to 0 ... -200,
So my problem is value i am getting in any range but it should be converted to 0 to 359 degree.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement