Why does deg(arcsin(sin(rad(degree)))) not produce degree?

592 Views Asked by At

I have an angle in degrees and I want it to be encoded between $-1, ..., 1$ to make it easier for using in a neural network.

I thought it might be a good idea to first convert the angle into radians and then take the sin of it. To get the angle back in degrees, first use arcsin and then convert to degrees.

In python (using NumPy math functions) this would look something like this:

np.rad2deg(np.arcsin(np.sin(np.deg2rad(264.0))))

but instead of 264 this produces -84 : why is that?

3

There are 3 best solutions below

1
On BEST ANSWER

Let's work this from the inside out:

  1. Converting 264° to radians gives 4.60766922526503.
  2. Taking the sine gives -0.9945218953682734.
  3. Taking the arcsine gives -1.4660765716752375. Note that this is a different number of radians than we got in Step 1, but complies with the identity $\sin(x) = \sin(\pi - x)$. Arcsine is conventionally defined to have the range $[-\frac{\pi}{2}, \frac{\pi}{2} ]$, which does not include the original angle of 264° ≈ 4.608 rad, but does include this new reduced angle of -84° ≈ -1.466 rad.
  4. Converting this angle to degrees gives -84.00000000000004, which is just -84 with a slight floating-point error. Note that 264 + (-84) = 180, reflecting the identity $\sin(x) = \sin(180° - x)$.

In short, the way that $\arcsin$ is conventionally defined ensures that your expression will always return a value in the interval $[-90, 90]$. If your original angle is outside that range, you'll get a different angle back.

0
On

There are 2 Issues here :

(1) $y=\sin(x)$ ( & other trigonometric functions ) are "PERIODIC" which means that $\sin(x)=\sin(x+2\pi)=\sin(x-2\pi)=\sin(x+4\pi)=\sin(x-4\pi)=\cdots=\cdots$

Hence , when we are given the function value , there are multiple Possible $x$ values to generate that function value.
This is unlike non-periodic 1-to-1 functions Eg $y=2x+8$ , where we have $x=(y-8)/2$ to get the inverse function.

In trigonometry , the inverse functions ( eg $x=\sin^{-1}(y)$ ) have to generate the value within 1 cycle of the period , which can be $(0,2\pi)$ or $(-\pi,+\pi)$.

(2) More-over , $y=\sin(x)$ is symmetric in each half-cycle , that is , 2 $x$ values within a cycle will generate the same $y$ value & the function must return 1 such value.
The general convention is to return the unique value in the range $(-\pi/2,+\pi/2)$ (there are other alternate conventions too)

Coming to your "Degree to radian to Degree" Issue :
When we take Example $x=45,135,360+45,360+135,720+45,720+135,\cdots,-360+45,-360+135,-720+45,-720+135,\cdots$
( where $360$ Degree is $2\pi$ radian ) , then $y=\sin(x)$ will be same $y=\sqrt{2}$.
When we try to invert that $y=\sqrt{2}$ to get back the "original" $x=\sin^{-1}(y)$ value , we will not know what Exactly we had : We will always get back $45$ , which is between $-90$ & $+90$.

Issue is not with "Degree to radian to Degree" , which is 1-to-1 & easy to invert.
Issue is with $\sin^{-1}()$ returning the value in the range $(-\pi/2,+\pi/2)$ [[ $(-90,+90)$ ]] & not returning the unknown "original" value back.
We will encounter the Issue with $\sin^{-1}(\sin(x))$ when $x$ is outside the range $(-\pi/2,+\pi/2)$
Similar Issue with $\cos^{-1}(\cos(x))$ when $x$ is outside the range $(0,+\pi)$.

We can see these 2 Issues in this Picture :

PERIODIC

The Sine Curve is "PERIODIC" , where 1 cycle can be the Grey line near the Origin , having Positive $x$ values. The cycle can even be the Blue line , having Positive & Negative $x$ values. The Choice is a convention.

The upper Purple line shows that there are multiple $x$ values with same $y$ value. We even see that there are 2 $x$ values even within a Cycle.
Hence half-cycle will have unique $x$ value matching a given $y$ value. The half-cycle is shown with the Pink line near the Origin , having Positive & Negative $x$ values , along with Positive & Negative $y$ values.

OP Example of $x=264$ will have $\sin()$ value $y=0.99452$. That is shown with the lower Purple line , where the corresponding $x$ value within the Grey cycle is shown with the Grey Square. Within the Pink half-cycle , the $x$ value is $-84$ , shown with the Pink Square , hence $sin^{-1}(0.99452)$ will have to give the Equivalent of $-84$.

0
On

This comes down to the fact that the sine function is not actually invertible, which means we can't say that $\arcsin(\sin(x))=x$ for every value of x.

For example, we know that $\sin$ of $0^\circ$ is equal to $0$. However, $\sin$ of $180^\circ$ is equal to $0$, too-- and not only that, but $\sin(360^\circ)=0$, and $\sin(540^\circ)=0$, and $\sin(720^\circ)=0$, etc. So, if we ask, "$\sin$ of what is equal to $0$?" should the answer be $0^\circ$, or $180^\circ$, or one of those other numbers? They all work, so which one should we choose?

What this means is that, in general, the answer to "$\sin$ of what is equal to $x$?" isn't a function, because functions have to produce only one answer.

Still, a function like that would be really useful to have, so we decided to make one anyway. Instead of having $\arcsin(x)$ ask the question "$\sin$ of what is equal to $x$?", we decided to make it ask "$\sin$ of which angle between $-90^\circ$ and $90^\circ$ is equal to $x$?"

Then we can confidently say that $\arcsin(0)=0^\circ$, and forget about $180^\circ$ and $360^\circ$ and all those other ones.

Why did we choose to the range $-90^\circ$ to $90^\circ$? Well, on that interval, the function produces a single answer, but beyond that, it's entirely arbitrary. $90^\circ$ to $270^\circ$ would have worked, too, and many others, but we chose $-90^\circ$ to $90^\circ$ because it was our favorite (probably because it has $0$ in it, and $0$ is a nice number).

Taking that back to your example, that's why you're getting $-84^\circ$. As it turns out, $\sin(264^\circ)$ is the same as $\sin(-84^\circ)$. So, when you put in $\arcsin(\sin(264^\circ))$, it computes the value of $\sin(264^\circ)$, then looks for which angle between $-90^\circ$ and $90^\circ$ has that value of $\sin$, finds $-84^\circ$, and gives it back to you.