0
$\begingroup$

I'm new here. In my sphere rotation poject I want to rotate any point on a sphere surface randomly. For any point I have to find different rotation axis. To do that I will use vectors scalar product which will end in a sum of two trigonometric functions. At the end I have to measure the $\arctan (x)$.

And this is the algorithm to do this. Let's say we have $\arctan(1.01236)$ and we substitute this to $\arctan(1.01236) = \pi/2 - \arctan(1/1.01236)= \pi/2 - \arctan(0.98779)$. $0.98779 > 2-\sqrt{3}$.

Do we have to jump to Taylor series equation from here or do we have to do step $3$ instructions and substitute it to

\begin{eqnarray}\arctan(1.01236) &=& \pi/2 + \pi/6 + \arctan\left(\frac{\sqrt{3}\cdot1.01236-1}{\sqrt{3}+1.01236}\right)\end{eqnarray} Have I written right? Have I done it right? How many times "$\pi$" do I have to write?

Read the following if you only want to know why I need to calculate the $arctan(x)$. //============ Text addition at 2016-12-01 00:10 (GMT+2) ======================

My main mission is to rotate things in 3D space randomly. I use Zdoom and Zdaemon game environment as a platform. Both applications have script editors where behaviour of bodies can be defined using ACS scripts. Not long ago I have managed to rotate whole 3D structure - a sphere - around an arbitrary axis that goes through sphere origin. The result is breathtaking. I don't want to stop and for online players (including me) to show a model of an example of how an electron is rotating around its nucleus. The rotation is chaotic. It means that in a time the rotation axis must change and the particle (projectile) vector associated with the axis must always be perpendicular to it. The only thing that is changing randomly is either azimuth $(\theta)$ either polar angle $(\phi)$. Lets say we have some projectile $P_1(x_1, y_1, z_1)$ which is set using special equations: $$x_1 = R\cdot cos(\theta_1)sin(\phi_1); $$ $$y_1 = R\cdot sin(\theta_1)sin(\phi_1); $$ $$x_1 = R\cdot cos(\phi_1); $$

An example of sphere point picking

So we need to find another point $P_2 (x_2,y_2,z_2)$ which would be perpendicular to vector $\vec {OP_1}$. Whole rotation will be around the center of the sphere. We can say that new coordinates can be defined this way: $$x_2 = R\cdot cos(\theta_2)sin(\phi_2); $$ $$y_2 = R\cdot sin(\theta_2)sin(\phi_2); $$ $$x_2 = R\cdot cos(\phi_2); $$ Two vectors scalar multiplication is equal to the multiplication of these vectors modules and the multiplication of the cosine of the angle between these vectors:$$\vec a \cdot \vec b = ab\,cos(\vec a,\vec b)$$ From here it is clear that two perpendicular vectors scalar product is zero because $cos⁡(90^\circ)=0$. Also: $\vec a \cdot \vec b = a_xb_x+a_yb_y+a_zb_z$. And if two perpendicular vectors scalar product is zero then: $\vec a \cdot \vec b = a_xb_x+a_yb_y+a_zb_z=0$.

We have $P_1(x_1, y_1, z_1)$. We have to find $P_2 (x_2,y_2,z_2)$ that $\vec {OP_1}\bot \vec {OP_2}$.

The equation now is: $$x_1 \cdot R\,cos(\theta_2)sin(\phi_2)+y_1 \cdot R\,sin(\theta_2)sin(\phi_2)+z_1 \cdot R\,cos(\phi_2)=0 \mid \frac {1}{R} $$ $$x_1\,cos(\theta_2)sin(\phi_2)+y_1\,sin(\theta_2)sin(\phi_2)+z_1\,cos(\phi_2)=0 $$ The equation would have two unknowns $\theta_2, \phi_2$ with which it means that the equation has infinitely many solutions. And as we can see it in the picture above the solution would be in the red ring. To come out from such a situation we must choose one of the angles. It can be azimuth or polar angle. This also gives us the opportunity to choose how to rotate our sphere point. Ok lets say we choose horizontal angle $\theta_2$ for the rotation axis. Now we are going to find the only remaining polar angle $\phi_2$ – the unknown.

We have: $x_1,y_1,z_1,R,\theta_2$. We must find $\phi_2$.

By multiplication directly known values we can get some numeric values and substitute them as new letters: $m=x_1\,cos⁡(\theta_2),\quad n=y_1\,sin⁡(θ_2)$ and we get this: $$m \cdot sin(\phi_2)+n \cdot sin(\phi_2)+z_1\,cos(\phi_2)=0$$ $$ (m+n)\,sin(\phi_2)+z_1\,cos(\phi_2)=0,\quad k=m+n,$$ $$z_1\,cos(\phi_2)+k\,sin(\phi_2)=0,\quad k\in R, z1\in R$$ Warning in equation above -> R is not sphere radius but a set of rational numbers.

The sum of two trigonometric functions can be substituted by one trigonometric function: $$z_1\,cos(\phi_2)+k\,sin(\phi_2)=L\,cos(\phi_2-\alpha)=\sqrt{z_1^2+k^2}\,cos\left(\phi_2-tan^{-1}\left(\frac{k}{z_1}\right)\right)=0,$$ $$cos\left(\phi_2-tan^{-1}\left(\frac{k}{z_1}\right)\right)=0$$ Here the $tan^{-1}\left(\frac{k}{z_1}\right)$ is the arctangent function of $\frac{k}{z_1}$. Lets substitute $b=\frac{k}{z_1}$, then $tan^{-1}\left(\frac{k}{z_1}\right)=arctan(b)$.

When we'll find the $arctan(b)$ we will get some angle $\alpha$ in radians. We'll need to convert it to either degrees or game angle system $[0, 1.0]$. When we will find angle $\alpha$ we will be able to find our unknown and needed angle $\phi_2$: $$arctan(b)=\alpha$$ $$cos(\phi_2-\alpha)=0$$ Two variants: $cos(\frac{\pi}{2})=0$ or $cos(\frac{3\pi}{2})=0$. So and thus: $$\phi_2-\alpha=\frac{\pi}{2}\quad or \quad\phi_2-\alpha=\frac{3\pi}{2}$$ $$\phi_2=\frac{\pi}{2}+\alpha\quad or\quad\phi_2=\frac{3\pi}{2}+\alpha$$

$\endgroup$
5
  • $\begingroup$ Hi, welcome to Math SE! As your post stands, it is very hard to read (and answer). Please take some time to edit your post to use math formatting. That will make the formulas far more readable. The first link you provide appears to have little impact on the question. It would be more interesting to know why you want to compute the atan yourself instead of using some calculator or program function. The second link will show broken formula images on Firefox as it uses ` instead of /` for paths. $\endgroup$
    – MvG
    Nov 29 '16 at 22:00
  • $\begingroup$ Because in a program I use there is no the arctan(x). Nor arcsin nor arccos. It only has sin(x) and cos(x) and returns value. I'm mapper and scripter of computer game ZDoom, ZDaemon which are latest improved platforms of a very old computer game Doom (1993-1995) by id software. The program called Doom Builder II has its own script editor with many game functions including sin cos. But it doesn't have the arctan(x) etc. I must to define its function by myself. I'm a kind of a coder. Then a script will find all my desired queries. $\endgroup$
    – Tomasm21
    Nov 30 '16 at 18:42
  • $\begingroup$ Besides.., read my edited post and you will see why I need it. $\endgroup$
    – Tomasm21
    Nov 30 '16 at 22:21
  • $\begingroup$ zdoom.org/wiki/VectorAngle writes: “This function is more commonly known as atan2. To get the value of atan(x), use VectorAngle(1.0, x)” Does this help? $\endgroup$
    – MvG
    Nov 30 '16 at 22:43
  • 1
    $\begingroup$ Yes it helps. Thanks a lot about it. I forgot about vectorangle. And I forgot the essence of it and how it would help in my thing. By now as I have $tan^{-1}\left(\frac{k}{z_1}\right)=arctan(b)$ then my atan would be VectorAngle(1.0, b); I will see it the other day. Thank you for your sharp insights. But still I would also be pleased to have direct technological algorithm to calculate the arctan(x) using Taylor series. @MvG link $\endgroup$
    – Tomasm21
    Nov 30 '16 at 23:46
1
$\begingroup$

For a tangent close to $1$, you'd better subtract $\pi/4$.

$$t:=\tan\left(\theta-\frac\pi4\right)=\frac{1-\tan\theta}{1+\tan\theta}$$

then

$$\tan\theta=\frac{t-1}{t+1}$$ and

$$\arctan1.01236=\arctan\frac{1.01236-1}{1.01236+1}+\frac\pi4=\arctan0.00614204+\frac\pi4.$$

$\endgroup$
2
  • $\begingroup$ Thank you for the offer. I will use it in my case if |x-1| < 0.09 $\endgroup$
    – Tomasm21
    Nov 30 '16 at 19:06
  • $\begingroup$ @Tomasm21: I assume that a good strategy would be to use the smallest among $x-\pi/6,x-\pi/4,x-\pi/3\cdots$. $\endgroup$
    – user65203
    Dec 1 '16 at 7:53

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.