0
$\begingroup$

I have a rectangle that is facing up. ($0^\circ$)

I'm getting a number bettween $-1000$ to $1000$ or even more, and this number is the angle that is rotating the rectangle.

How can I know the degrees it is facing now?

$\endgroup$
  • 1
    $\begingroup$ Rotating by $360^\circ$ is equivalent to not rotating at all, so just keep adding or subtracting multiples of it until you get something in $[0,360]$. (More specifically, $x\to x-360\lfloor x/360\rfloor$, where $\lfloor\cdot\rfloor$ is the floor function.) Also... he? $\endgroup$ – anon Aug 28 '11 at 9:05
  • 1
    $\begingroup$ Cool it works :) but why didn't you put it as answer ? lol $\endgroup$ – Danpe Aug 28 '11 at 9:14
  • 2
    $\begingroup$ Also, if your programming language (I assume you're doing this in a computer program) has an fmod function or something equivalent, $x \mapsto \operatorname{fmod}(x, 360)$ is probably easier than $x \mapsto x - 360 \cdot \lfloor x/360 \rfloor$. $\endgroup$ – Ilmari Karonen Aug 28 '11 at 12:08
2
$\begingroup$

This question was answered in a comment:

Rotating by $360^{\circ}$ is equivalent to not rotating at all, so just keep adding or subtracting multiples of it until you get something in $[0,360]$. (More specifically, $x\mapsto x−360⌊x/360⌋$, where $⌊\cdot⌋$ is the floor function.) – anon Aug 28 '11 at 9:05

$\endgroup$
0
$\begingroup$

If the angle $\alpha\in\mathbb{Z}$, you may also use the remainder of $\alpha$ when divided by 360. Implementing this on a computer, you then could use the modulo operation which is quite efficient (compared to a division, a floor and a multiplication) and in most languages shorter to type (e.g. alpha%360 in C++)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.