From a1625a54104da7872c15618db9e68656c6f6ec2a Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Fri, 8 Feb 2008 17:54:30 +0000 Subject: * Applying mantis 339 patches round 2 -- Thanks daedius --- OpenSim/Framework/Util.cs | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'OpenSim/Framework/Util.cs') diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index 5bfd8e1..856cac3 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs @@ -47,7 +47,12 @@ namespace OpenSim.Framework private static Dictionary capsURLS = new Dictionary(); #region Vector Equasions - + /// + /// Get the distance between two 3d vectors + /// + /// A 3d vector + /// A 3d vector + /// The distance between the two vectors public static double GetDistanceTo(LLVector3 a, LLVector3 b) { float dx = a.X - b.X; @@ -55,14 +60,43 @@ namespace OpenSim.Framework float dz = a.Z - b.Z; return Math.Sqrt(dx*dx + dy*dy + dz*dz); } + + /// + /// Get the magnitude of a 3d vector + /// + /// A 3d vector + /// The magnitude of the vector public static double GetMagnitude(LLVector3 a) { return Math.Sqrt((a.X * a.X) + (a.Y * a.Y) + (a.Z * a.Z)); } - public static LLVector3 GetNormal(LLVector3 a) + + /// + /// Get a normalized form of a 3d vector + /// + /// A 3d vector + /// A new vector which is normalized form of the vector + /// The vector paramater cannot be <0,0,0> + public static LLVector3 GetNormalizedVector(LLVector3 a) { + if (IsZeroVector(a)) + throw new ArgumentException("Vector paramater cannot be a zero vector."); + float Mag = (float)GetMagnitude(a); return new LLVector3(a.X / Mag, a.Y / Mag, a.Z / Mag); + } + /// + /// Returns if a vector is a zero vector (has all zero components) + /// + /// + public static bool IsZeroVector( LLVector3 v ) + { + if( v.X == 0 && v.Y == 0 && v.Z == 0) + { + return true; + } + + return false; } # endregion -- cgit v1.1