Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Thank you!# points are A, B, C each with 3 coordinates (x, y, z) # stored as array elements [0],[1],[2] # value desired is cos(theta) between AB and BC that # should range 0 to 1, where 1 is a straight line A to C # Calculate by cos(theta) = AB*BC (dot product) @AB = ($B[0]-$A[0], $B[1]-$A[1], $B[2]-$A[2]); @BC = ($C[0]-$B[0], $C[1]-$B[1], $C[2]-$B[2]); $lengthAB = sqrt((($AB[0])**2)+(($AB[1])**2)+(($AB[2])**2); $lengthBC = sqrt((($BC[0])**2)+(($BC[1])**2)+(($BC[2])**2); @unitvectorAB=($AB[0]/$lengthAB, $AB[1]/$lengthAB, $AB[2]/$lengthAB); @unitvectorBC=($BC[0]/$lengthBC, $BC[1]/$lengthBC, $BC[2]/$lengthBC); $costheta = ($unitvectorAB[0]*$unitvectorBC[0])+($unitvectorAB[1]*$uni +tvectorBC[1])+($unitvectorAB[2]*$unitvectorBC[2]);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Calculate Angle Between Three 3D Points
by dws (Chancellor) on Aug 20, 2003 at 18:41 UTC | |
by Anonymous Monk on Aug 20, 2003 at 19:22 UTC | |
|
Re: Calculate Angle Between Three 3D Points
by Zeroth (Beadle) on Aug 20, 2003 at 18:21 UTC | |
by Anonymous Monk on Aug 20, 2003 at 18:48 UTC | |
by dragonchild (Archbishop) on Aug 20, 2003 at 19:06 UTC |