Finding the sine of the angle between 2 rays

  • Thread starter Thread starter Matterwave
  • Start date Start date
  • Tags Tags
    Angle Rays Sine
Matterwave
Science Advisor
Homework Helper
Gold Member
Messages
3,971
Reaction score
329
Hello, say you are on the unit sphere and you have 2 rays intersecting it from the origin. You know the spherical coordinates of where these 2 rays intersect the sphere ##(\theta_1,\phi_1),(\theta_2,\phi_2)##.

Now, because we know the dot product of two vectors, it is simple to get that the cosine of the angle between these 2 rays. You convert the spherical coordinates to Cartesian coordinates (with ##r=1##) and take the dot product product to get : $$\cos\theta=\cos\theta_1\cos\theta_2+\sin\theta_1\sin\theta_2(\cos\phi_1\cos\phi_2+\sin\phi_1\sin\phi_2)$$

What I want now is the sine of the angle. Of course, it is easy to do ##\sin\theta=\sin(\cos^{-1}(\cos\theta))##. However, for computational reasons, it would be much more beneficial to me if I could get this sine in terms of sines and cosines of ##\theta_1,\phi_1,\theta_2,\phi_2##. I can take the cross product and do a similar thing to get this, but that formula is horrendous. Because it involves a magnitude, there's a square root of a bunch of squares of a ton of terms. Anyone know what the final result of this computation is? I'm guessing that the terms will simplify significantly, but I wrote them down and aside from a few simple simplifications, could not simplify further.
 
Mathematics news on Phys.org
Compute the cosine and then use ##\cos^2 + \sin^2 = 1##. Of course, this is not a way around the square root, you will have to live with that.
 
This seems...equally horrendous..=/

At the end of the computation, I will have to average over all azimuthal angles of ##\phi_2## assuming spherical symmetry, and so actually I can use ##\cos\theta=\cos\theta_1\cos\theta_2## because the integrals of ##\sin x,\cos x## over 2 pi is 0. I was hoping for a similar simplicity in the sine result..
 
I feel like I've made a little progress. I looked at the formula for ##\sin(x-y)=\sin x\cos y-\cos x\sin y##. My formula should reduce to this formula if ##\phi_1=\phi_2=0##, since if we are in a plane, then the angle between our rays will simply be ##\theta_1-\theta_2##. So I looked at the monster that is the current, unsimpified form, of my formula and it looks like the monster formula could be some square of this. The last term in my formula is: $$-2\sin\theta_1\cos\theta_1\sin\theta_2\cos\theta_2(\sin\phi_1\sin\phi_2+\cos\phi_1\cos\phi_2+ \cos\phi_1\cos\phi_2\sin\phi_1\sin\phi_2)$$

It looks like if you took the square of $$\sin\theta_1\cos\theta_2(1+f_1(\phi_1,\phi_2))-\cos\theta_1\sin\theta_2(1+f_2(\phi_1,\phi_2))$$ you could get a term that matches the last term. I need to figure out what ##f_{1,2}(\phi_1,\phi_2)## are, but so far no luck.
 
I put my whole gigantic formula into wolfram..and it didn't come up with any simplifications...so maybe this can't be done :(
 
I had a play with the expression. It comes down to writing that expression f(\theta_i , \phi_i ) in the form:
1-f^2 = g^2 \iff f^2=1-g^2
For some 'nice' function g(\theta_i , \phi_i ). I don't think it's possible here either, and see no reason why it 'should' be.
 
Jack Davies said:
I had a play with the expression. It comes down to writing that expression f(\theta_i , \phi_i ) in the form:
1-f^2 = g^2 \iff f^2=1-g^2

How is this different from what I already said in #2?
 
Orodruin said:
How is this different from what I already said in #2?

Exactly the same. Apologies.
 
Ok, maybe if I post the full problem, we can perhaps come up with something.

Assume there is a sphere from which rays of stuff (in my case, neutrinos, but that's not important for this part of the problem) emanate. These rays are emitted from this sphere and they intersect. At some distance away from the sphere, we look at two rays which intersect. They both will intersect a radial ray at some polar angle and some azimuthal angle ##(\theta_1,\phi_1)## and ##(\theta_2,\phi_2)## while they make some angle ##\theta## with each other. What I want is ##\sin\theta## as some expression of ##(\theta_1,\phi_1)## and ##(\theta_2,\phi_2)##.

There is an additional simplification here. We never track the azimuthal angles in our simulations (the simulations assume azimuthal symmetry), and so two rays which differ by ##\theta## are tracked and assumed different, but two rays which differ only by ##\phi## are not. So, we want to average over all the azimuthal angles at the end of the day.

Up to this point in the simulation I've been working on, we have only required use of ##\cos\theta##. This was easy to find because we can exploit the dot product of 2 vectors to find $$\cos\theta=\cos\theta_1\cos\theta_2+\sin\theta_1\sin\theta_2(\cos\phi_1\cos\phi_2+\sin\phi_1\sin\phi_2)$$. We average over all the ##\phi## angles, and since $$\frac{1}{2\pi}\int_0^{2\pi}\sin\phi d\phi=0$$ $$\frac{1}{2\pi}\int_0^{2\pi}\cos\phi d\phi=0$$ the second half the expression disappears and we use ##\cos\theta=\cos\theta_1\cos\theta_2##.

I want to now do this same procedure on ##\sin\theta##, but as said before, the expression is horrendous.

Taking the cross product of 2 unit vectors, we know that $$\sin\theta=||\hat{k_1}\times\hat{k_2}||=\left|\left|\begin{pmatrix} \sin\theta_1\sin\phi_1\cos\theta_2-\sin\theta_2\sin\phi_2\cos\theta_1 \\ \sin\theta_2\cos\phi_2\cos\theta_1-\sin\theta_1\cos\phi_1\cos\theta_2 \\ \sin\theta_1\cos\phi_1\sin\theta_2\sin\phi_2-\sin\theta_1\sin\phi_1\sin\theta_2\cos\phi_2\end{pmatrix}\right|\right|$$ As you can probably tell, this will look horrible. So far I have gotten the expression down to: $$\sin^2\theta=\sin^2\theta_1\cos^2\theta_2+\sin^2\theta_2\cos^2\theta_1+\sin^2\theta_1\sin^2\theta_2(\cos^2\phi_1\sin^2\phi_2+\sin^2\phi_1\cos^2\phi_2)- \\ 2\sin\theta_1\cos\theta_2\sin\theta_2\cos\theta_1(\sin\phi_1\sin\phi_2+\cos\phi_1\cos\phi_2+\cos\phi_1\cos\phi_2\sin\phi_1\sin\phi_2)$$

I have not been able to simplify this further. Somehow, though if I set ##\phi_1=\phi_2=0## I should get ##\sin\theta=\sin\theta_1\cos\theta_2-\sin\theta_2\cos\theta_1## because that's the sin addition formula. I seem to be able to retrieve this result so it looks like my work is ok...Can someone check the math a bit? Any ideas on how this simplifies? How about what would happen if I took the integral of this around both ##\phi##?

I looked at the expression and tried to reproduce this expression for ##\sin^2\theta## by looking at the product ##(\sin\theta_1\cos\theta_2(1+\sin\phi_1\cos\phi_2)-\cos\theta_1\sin\theta_2(1+\cos\phi_1\sin\phi_2))^2## and although I reproduce the first 2 terms and the last term in that long expression above, I can't reproduce the middle expression and there are too many terms in this. But it really seems like some sort of simplification like this should be possible...
 
Last edited:
  • #10
1. I'm no expert on math, but I think I can prove that the expression for ##\sin\theta## has to contain a ##\sqrt{\ }## somewhere:
The angle between the 2 rays can be seen as ##2\pi-\theta## as well as ##\theta##.
The cosine of these 2 angles is the same, so you can find a formula for ##\cos \theta##.
But the sine of those 2 angles has a different sign, which is a strong hint that a square root is involved.

2. I tried to do the calculation as well. I've arrived at something different, but I did all simplifications on paper, so probably made a mistake somewhere. Anyway, why don't you use the symmetry and replace ##\phi_2## with ##\phi_2-\phi_1##, and ##\phi_1## with ##0##?
The expression can then be simplified to the form
$$\sin(\theta)=\sqrt{a + b \sin(\phi_2-\phi_1) + c \cos(\phi_2-\phi_1) + d \sin^2(\phi_2-\phi_1)}$$
which, with some luck, can be integrated over ##\phi_2-\phi_1##.
 
  • #11
So your a,b,c,d, are expressions with ##\theta_1,\theta_2## in them I am assuming?
 
  • #12
Matterwave said:
So your a,b,c,d, are expressions with ##\theta_1,\theta_2## in them I am assuming?
Yes. I'm not entirely sure how the "integration" part of your problem works, but if I understand it correctly, it does not depend on the ##\theta##s.
 
  • #13
In fact, it's kind of obvious that the thing under square root will be ##1-\cos^2\theta##.
 
  • #14
Well yes, but i want it in terms of ##\theta_1,\theta_2## not ##\theta##
 
  • #15
Matterwave said:
$$\cos\theta=\cos\theta_1\cos\theta_2+\sin\theta_1\sin\theta_2(\cos\phi_1\cos\phi_2+\sin\phi_1\sin\phi_2)$$
$$\cos\theta=\cos\theta_1\cos\theta_2+\sin\theta_1\sin\theta_2\cos(\phi_2-\phi_1)$$
 
  • #16
SlowThinker said:
$$\cos\theta=\cos\theta_1\cos\theta_2+\sin\theta_1\sin\theta_2\cos(\phi_2-\phi_1)$$

Yes, the posters above you have suggested it, but it seems this expression is still quite cumbersome when you square it and then square root it with a 1- in front).
 
  • #17
Hmm.
Going back to base assumptions. You seem to be put off by calculating the arithmetic mean or some type of "average". Consider an online algorithm. This takes a steam of input, does not store very much in memory and is low overhead, and VERY simple to implement. Maybe you do not need a "gigantic formula". I cannot tell.

Here is a version from Knuth of an online algorithm. You can adapt it to most procedural programming languages that support I/O from files or the tty. There is some exposition at the top followed by simple pseudocode. This is for a variance. You alter it for your needs.

https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Online_algorithm
 
Back
Top