Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Finding the sine of the angle between 2 rays

  1. Oct 9, 2015 #1

    Matterwave

    User Avatar
    Science Advisor
    Gold Member

    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.
     
  2. jcsd
  3. Oct 9, 2015 #2

    Orodruin

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper
    Gold Member

    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.
     
  4. Oct 9, 2015 #3

    Matterwave

    User Avatar
    Science Advisor
    Gold Member

    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..
     
  5. Oct 9, 2015 #4

    Matterwave

    User Avatar
    Science Advisor
    Gold Member

    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.
     
  6. Oct 9, 2015 #5

    Matterwave

    User Avatar
    Science Advisor
    Gold Member

    I put my whole gigantic formula into wolfram..and it didn't come up with any simplifications...so maybe this can't be done :(
     
  7. Oct 9, 2015 #6
    I had a play with the expression. It comes down to writing that expression [itex]f(\theta_i , \phi_i )[/itex] in the form:
    [tex] 1-f^2 = g^2[/tex] [tex] \iff f^2=1-g^2[/tex]
    For some 'nice' function [itex]g(\theta_i , \phi_i )[/itex]. I don't think it's possible here either, and see no reason why it 'should' be.
     
  8. Oct 9, 2015 #7

    Orodruin

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper
    Gold Member

    How is this different from what I already said in #2?
     
  9. Oct 9, 2015 #8
    Exactly the same. Apologies.
     
  10. Oct 9, 2015 #9

    Matterwave

    User Avatar
    Science Advisor
    Gold Member

    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: Oct 9, 2015
  11. Oct 11, 2015 #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##.
     
  12. Oct 11, 2015 #11

    Matterwave

    User Avatar
    Science Advisor
    Gold Member

    So your a,b,c,d, are expressions with ##\theta_1,\theta_2## in them I am assuming?
     
  13. Oct 11, 2015 #12
    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.
     
  14. Oct 11, 2015 #13
    In fact, it's kind of obvious that the thing under square root will be ##1-\cos^2\theta##.
     
  15. Oct 11, 2015 #14

    Matterwave

    User Avatar
    Science Advisor
    Gold Member

    Well yes, but i want it in terms of ##\theta_1,\theta_2## not ##\theta##
     
  16. Oct 11, 2015 #15
    $$\cos\theta=\cos\theta_1\cos\theta_2+\sin\theta_1\sin\theta_2\cos(\phi_2-\phi_1)$$
     
  17. Oct 11, 2015 #16

    Matterwave

    User Avatar
    Science Advisor
    Gold Member

    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).
     
  18. Oct 12, 2015 #17

    jim mcnamara

    User Avatar

    Staff: Mentor

    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
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Finding the sine of the angle between 2 rays
  1. Angle between 2 vectors (Replies: 10)

  2. Sine Waves Sine Angles (Replies: 7)

Loading...