fix for small values in PVector

This commit is contained in:
benfry
2009-08-31 19:10:08 +00:00
parent c156633968
commit 821e00ce27
+4 -3
View File
@@ -529,9 +529,10 @@ public class PVector {
* @return the angle between the vectors
*/
static public float angleBetween(PVector v1, PVector v2) {
float dot = v1.dot(v2);
float theta = (float) Math.acos(dot / (v1.mag() * v2.mag()));
return theta;
double dot = v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
double v1mag = Math.sqrt(v1.x * v1.x + v1.y * v1.y + v1.z * v1.z);
double v2mag = Math.sqrt(v2.x * v2.x + v2.y * v2.y + v2.z * v2.z);
return (float) Math.acos(dot / (v1mag * v2mag));
}