From: m9305474@student.anu.edu.au (John McLaughlin) Newsgroups: sci.math Subject: Re: sperical coords question Date: Sat, 29 Apr 1995 10:31:01 +1000 In article , m9305474@student.anu.edu.au (John McLaughlin) wrote: > Hi, > I need to solve the following problem for a programming algorithm I am > working on. > > Given the spherical coordinates of two points on the unit sphere, what is the > angle between the two points? > > Thanks for any help. Email replies would be preferred. > > -John McLaughlin Thanks for the responses. This was the best reply so far (from Ron Winther). It was the final trig simplification that had me stumped. Are there any further possible simplifications? -John McLaughlin --CUT HERE-- Probably you'll get lots of responses, so here's my contribution to the flood; I am assuming the "angle between the points" that you speak of has its vertex at the center of the sphere (i.e., at the origin). Let P1 and P2 be vectors from the origin to the two points on the unit sphere. Suppose the spherical coords of the points are (1, theta1, phi1) and (1, theta2, phi2) (where phi is the angle with respect to the +z-axis). Using the coord transforms x = r*cos(theta)*sin(phi), y = r*sin(theta)*sin(phi), z = r*cos(phi) we may write P1 = and P2 = . The dot product P1.P2 = |P1|*|P2|*cos(A) where A is the angle between P1 and P2. Since the pts. lie on a unit sphere, |P1| = |P2| = 1, so A = acos(P1.P2) There is a slight trigonometric simplification of the dot product; it may be written as cos(theta1 - theta2)*sin(phi1)*sin(phi2) + cos(phi1)*cos(phi2). The "north pole" and "south pole", for which theta is not defined, are of course special cases but easily dealt with. Best wishes, Ron Winther Ames Laboratory ============================================================================== From: lanzi@inland.com Newsgroups: sci.math Subject: Re: sperical coords questionexit Date: 3 May 95 12:01:55 CST In article , m9305474@student.anu.edu.au (John McLaughlin) writes: > Hi, > I need to solve the following problem for a programming algorithm I am > working on. > > Given the spherical coordinates of two points on the unit sphere, what is the > angle between the two points? > > Thanks for any help. Email replies would be preferred. > > -John McLaughlin Since others might be interested, here's the answer: cos(psi) = sin(th1)*sin(th2)*cos(ph1-ph2) + cos(th1)*cos(th2). where th = theta, ph = phi in standard spherical coordinates. Look it up in any textbook on spherical trigonometry; it's the Law of Cosines for spherical triangles. --OL lanzi@inland.com