Search code examples
functionmathrotationtrigonometryangle

How to flip the trigonometric circle around the 45° angle?


I am looking for a mathematical function capable of flipping the trigonometric circle around the "axis" located on the 45° vector (or pi/4 radians).

Such as :

|---------|---------|
|   x     |   f(x)  |
|---------|---------|
|   0     |   90    |
|   45    |   45    |
|   90    |   0     |
|   135   |   315   |
|   180   |   270   |
|   225   |   225   |
|   270   |   180   |
|   315   |   135   |
|---------|---------|

Just to give a few examples.

So basically I need to turn a compass rose :

Compass rose

into a trigonometric circle :

enter image description here

I only found things like "180 - angle" but that is not the kind of rotation I'm looking for. Is it possible ?


Solution

  • The main difficulty in your problem is the "jump" in the result, where f(90) should be 0 but f(91) should be 359. A solution is to use a jumpy operator--namely, the modulus operator, which is often represented by the % character.

    In a language like Python, where the modulus operator always returns a positive result, you could use

    def f(x):
        return (90 - x) % 360
    

    Some languages can return a negative result if the number before the operator is negative. You can treat that by adding 360 before taking the modulus, and this should work in all languages with a modulus operator:

    def f(x):
        return (450 - x) % 360
    

    You can demonstrate either function with:

    for a in range(0, 360, 45):
        print(a, f(a))
    

    which prints what was desired:

    0 90
    45 45
    90 0
    135 315
    180 270
    225 225
    270 180
    315 135
    

    If your language does not have the modulus operator, it can be simulated by using the floor or int function. Let me know if you need a solution using either of those instead of modulus.