3
$\begingroup$

I'm working on a computer program that has to express sines/cosines of angles discretely, and in trying to figure out a multiplier ($n$ below) I stumbled on a really interesting problem:

Given a trig function $\sin x$ or $\cos x$, the result of which is to be multiplied by an integer $n$ and then rounded, what kind of resolution in degrees do you get given a certain $n$?

Here's an example, where I use $[x]$ to denote rounding $x$ to the nearest integer. Let $M$ be the set of all achievable discrete sine/cosine pairs $\left$, and let $L$ be the corresponding bijective set in the space of possible angles $x$ for sine/cosine.

If $n$ is $2$, then $$[n\sin x]\in\{-2, -1, 0, 1, 2\} \\ [n\cos x]\in\{-2, -1, 0, 1, 2\} \\ M = \{\left<-2, -2\right>, \left<-2, -1\right>, \left<-2, 0\right>, \left<-2, 1\right>, \left<-2, 2\right>, \left<-1, -2\right>, \left<-1, -1\right>, \left<-1, 0\right>, \left<-1, 1\right>, \left<-1, 2\right>, \left<0, -2\right>, \left<0, -1\right>, \left<0, 0\right>, \left<0, 1\right>, \left<0, 2\right>, \left<1, -2\right>, \left<1, -1\right>, \left<1, 0\right>, \left<1, 1\right>, \left<1, 2\right>, \left<2, -2\right>, \left<2, -1\right>, \left<2, 0\right>, \left<2, 1\right>, \left<2, 2\right>\}$$

Except some of these values in $M$ are duplicates when you consider that to get from $M$ (sine/cosine) to $L$ (the angles that got you there), the most convenient formula is $L_k = \arcsin\left(\frac{{M_k}_y}{{M_k}_x}\right)$ and clearly some combinations above in $M$ yield the same angles, like $\left<-2, -2\right>, \left<-1, 1\right>, \left<0, 0\right>,$ $\left<1, 1\right>$ and $\left<2, 2\right>$, all of which yield $\pi/2$. In short, $L$ here is actually as follows:

$$L = \{-90°, -63.435...°, -45°, 0°, 45°, 63.435...°, 90°\}$$

Originally I tried to solve this algebraically, assuming a minimum-uniquely-resolvable angle $x$ (basically the resolution) and an iterator $k$ as follows, so as you increase the input angle by $x$, the minimum amount that will yield an increase in output after rounding, you increase the discrete output $n\sin x$ by 1. Note that $k$ had to be restricted to less than $\frac{2\pi}{x}$ because any further than that and you've gone a full circle: $$n\sin(x\cdot k) + 1 = n\sin\left(x\cdot(k+1)\right) \quad\forall\quad 0 \leq k \leq \frac{2\pi}{x}$$

However, after spending a while with trig identities and not finding anything fruitful, I realized that solving for $x$ given $n$ in trig functions was complicated enough without the additional variable $k$, so I tried simplifying or re-expressing it as $$n\sin(x) + 1 = n\sin(2x)$$ or alternatively with k serving as an adder instead of a multiplier between $-2\pi$ and $2\pi - x$ as $$n\sin(k) + 1 = n\sin(k + x)$$

And yet this too escapes algebraic solutions. It seems the results just can't be extracted from the sine function, so finally I resorted to graphical results. Graphed with $x$ on the $x$ axis and $n$ on the $y$ axis, this should show all possible values for $x$, with the minimum-uniquely-resolvable $x$, or resolution as the lowest possible value of $x$ at the desired $n$ $y$ value. I animated k, with our new version of the function outputting the minimum point in $x$ along the desired $n$ $y$ value that stays in place as $k$ changes, but SE wouldn't accept the animated image, so here's a shot 3D graphed with $k$ as the $z$ axis, which makes it pretty clear that the for all $0 \leq k \leq \frac{2\pi}{x}$ condition isn't going to happen because there is no one value of $x$ consistent across $k$ at $z$, proving that this whole exercise was made with the very faulty assumption that there's some set resolution $x$ instead of an average resolution. 3D Image

How would I possibly find a reasonable result for this problem, now that you've seen a good part of my failed process above?

2 Answers 2

0

Here is an algebraic way.

For each rounded integer value $M_x$ or $M_y$, there is a range of $x$ values that give approximate sine or cosines. For example, if $M_x=2$, then we must have $$[n\sin x]=2\implies 1.5\le n\sin x<2.5.$$ If $n=2$ then

$$0.75\le \sin x<1.25.$$ And we can find the corresponding $x$ values that give this range of sine values. $$x\in [\pi+\arcsin(0.75),2\pi-\arcsin(0.75)].$$ This acts similarly on $\cos x$. We need to find intersections of the regions that give the right sine AND cosine values. Since the signs of cosine and sine are different in different quadrants, we have to be careful. I will set a table for the values: $$\begin{matrix} &&\sin x&\cos x\\ \hline -2&(-1.25,0.75]&[\pi+\arcsin(0.75),2\pi-\arcsin(0.75)]&[\pi-\arccos(0.75),\pi+\arccos(0.75)]\\ \hline -1&(-0.75,-0.25]&[\pi+\arcsin(0.25),\pi+\arcsin0.75)&[\pi-\arccos0.25,\pi-\arccos0.75)\\ &&\text{or }[2\pi-\arcsin0.75,2\pi-\arcsin0.25)&\text{or }(\pi+\arccos0.75,\pi+\arccos0.25]\\ \hline 0&(-0.25,0.25)&(\pi-\arcsin(0.25),\pi+\arcsin(0.25))&(\arccos(0.25),\pi-\arccos(0.25))\\ &&\text{or }(2\pi-\arcsin(0.25),2\pi)\cup[0,\arcsin(0.25))&\text{or }(\pi+\arccos(0.25),2\pi-\arccos(0.25))\\ \hline 1&[0.25,0.75)&[\arcsin(0.25),\arcsin(0.75))&(\arccos(0.75),\arccos(0.25)]\\ &&\text{or }(\pi-\arcsin(0.75),\pi-\arcsin(0.25)]&\text{or }[2\pi-\arccos(0.25),2\pi-\arccos(0.75))\\ \hline 2&[0.75,1.25)&[\arcsin(0.75),\pi-\arcsin(0.75)]&[2\pi-\arccos(0.75),2\pi]\cup[0,\arccos(0.75)] \end{matrix}$$

You can then find intersections to determine the range of $x$. It might be more convenient to transform these numbers to decimals or degrees.

For example, if the pair is $(-2, 2)$, then $[n\sin x]=-2$ and $[n\cos x]=2$. We find the corresponding ranges. For sine, $$x\in [\pi+\arcsin(0.75),2\pi-\arcsin(0.75)]\approx[3.99,5.44].$$ For cosine, $$x\in [2\pi-\arccos(0.75),2\pi]\cup[0,\arccos(0.75)]\approx[5.56, 6.28]\cup[0,0.72].$$

There is no intersection. So no $x$ values would give $(-2,2)$.

0

Let the scaling factor be $n$ and let us determine the corners of the $(c,s)$ cell inside which $[n\cos a]=c,[n\sin a]=s.$

We have,

$$ c-\frac12\le n\cos a

In the first quadrant, the range of angles corresponds to the lower-right and upper-left corners, and is obtained with

$$ \tan a_{min}=\frac{2s-1}{2c+1},\\ \tan a_{max}=\frac{2s+1}{2c-1}, $$

hence the range is

$$r=\arctan\frac{2s+1}{2c-1}-\arctan\frac{2s-1}{2c+1}.$$

You rationalize the expression by taking the tangent and finally get

$$r=\arctan\frac{2c+2s}{2c^2+2s^2-1}.$$


The worst cases occur closest to the origin. At $(1,0)$, $r=90°$ and at the origin $r=360°$ !

It is worth to note that these do not depend on $n$.