Commit in projects/lcsim/trunk/math/src/main/java/org/lcsim/spacegeom on MAIN
SpacePoint.java+202975 -> 2976
Add calculation of the opening angle between two points assuming the origin as the point of reference. Doesn't really belong on a Point, but included for convenience.

projects/lcsim/trunk/math/src/main/java/org/lcsim/spacegeom
SpacePoint.java 2975 -> 2976
--- projects/lcsim/trunk/math/src/main/java/org/lcsim/spacegeom/SpacePoint.java	2014-02-11 01:53:50 UTC (rev 2975)
+++ projects/lcsim/trunk/math/src/main/java/org/lcsim/spacegeom/SpacePoint.java	2014-02-11 22:37:32 UTC (rev 2976)
@@ -7,6 +7,8 @@
 import hep.physics.vec.Hep3Vector;
 
 import java.io.Serializable;
+import static java.lang.Math.acos;
+import static java.lang.Math.sqrt;
 
 /**
  * A SpacePoint represents a concrete point in 3D Space,
@@ -376,6 +378,24 @@
         return Math.sqrt( dx*dx + dy*dy + dz*dz );
     }
     
+   /**
+     * Return the opening angle between two space points, assuming the point of reference is the origin
+     * @param spt1 SpacePoint 1
+     * @param spt2 SpacePoint 2
+     * @return opening angle between points
+     */
+    public static double openingAngle(SpacePoint p1, SpacePoint p2)
+    {
+        // should check on point being non-zero...
+        //recall that cos(theta) = a . b / |a|*|b|
+        double dot = p1.x()*p2.x()+p1.y()*p2.y()+p1.z()*p2.z();
+        
+        double d1 = sqrt(p1.x()*p1.x()+p1.y()*p1.y()+p1.z()*p1.z());
+        double d2 = sqrt(p2.x()*p2.x()+p2.y()*p2.y()+p2.z()*p2.z());
+       
+        return acos(dot/(d1*d2));
+    }        
+    
     /**
      *Clone
      *
SVNspam 0.1


Use REPLY-ALL to reply to list

To unsubscribe from the LCDET-SVN list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCDET-SVN&A=1