From 821e00ce27292a616ca33e826a3bcb599ca57e50 Mon Sep 17 00:00:00 2001 From: benfry Date: Mon, 31 Aug 2009 19:10:08 +0000 Subject: [PATCH] fix for small values in PVector --- core/src/processing/core/PVector.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/src/processing/core/PVector.java b/core/src/processing/core/PVector.java index 5f9be436e..78209bb60 100644 --- a/core/src/processing/core/PVector.java +++ b/core/src/processing/core/PVector.java @@ -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)); }