daemon2008 122 Report post Posted March 3, 2008 Hi there, Was just wondering if anyone had an example C or Java file, or formula for calculating the spherical distance between two 3d vector locations on a sphere. I made a method for Euclidean distance but its not as accurate. Is it as simple as just finding the dot product between two vectors? Thanks! Dan 0 Share this post Link to post Share on other sites
ibebrett 205 Report post Posted March 3, 2008 Off the top of my head i would say get the angle between the two and then multiply by the radius of the sphere to get the distance. 0 Share this post Link to post Share on other sites
Sneftel 1788 Report post Posted March 3, 2008 Quote:Original post by ibebrettOff the top of my head i would say get the angle between the two and then multiply by the radius of the sphere to get the distance.Indeed. BTW, the most robust and accurate way to get the angle between two 3D vectors is θ = atan2(||A×B||, A·B). 0 Share this post Link to post Share on other sites
daemon2008 122 Report post Posted March 3, 2008 Thanks for the fast reply!By : θ = atan2(||A×B||, A·B).I know AxB is the cross product, but what are the lines surrounding the cross product, it looks like the cardinality.Sorry im new to Geometry.Thanks!Dan 0 Share this post Link to post Share on other sites
jyk 2094 Report post Posted March 3, 2008 Quote:Original post by daemon2008Thanks for the fast reply!By : θ = atan2(||A×B||, A·B).I know AxB is the cross product, but what are the lines surrounding the cross product, it looks like the cardinality.Sorry im new to Geometry.Thanks!DanThe above equates to:angle = atan2(length(cross(A,B)), dot(A,B))Does that clear things up? 0 Share this post Link to post Share on other sites
daemon2008 122 Report post Posted March 3, 2008 Ah i get it now, thanks again! 0 Share this post Link to post Share on other sites
DonDickieD 2751 Report post Posted March 3, 2008 Shouldn't it be:theta = atan2( length( cross( A, B ) ), dot( A, B ) / length( A ) / length( B ) ) 0 Share this post Link to post Share on other sites
jyk 2094 Report post Posted March 3, 2008 Quote:Original post by DonDickieDShouldn't it be:theta = atan2( length( cross( A, B ) ), dot( A, B ) / length( A ) / length( B ) )You might be thinking of the method that uses acos().The method posted above works because:|AxB| = sin(angle(A,B))|A||B|A.B = cos(angle(A,B))|A||B|And:atan2(sin(angle(A,B))|A||B|, cos(angle(A,B))|A||B|) = angle(A,B)That's rather informal, but should show (more or less) why it's not necessary to factor in the product of the lengths explicitly. 0 Share this post Link to post Share on other sites
alvaro 21246 Report post Posted March 3, 2008 In what sense is that method better than the more direct R*acos(dot(v1,v2)/(R*R))? 0 Share this post Link to post Share on other sites