# 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]*$unitvectorBC[1])+($unitvectorAB[2]*$unitvectorBC[2]);