diff options
Diffstat (limited to 'OpenSim/Framework/Util.cs')
-rw-r--r-- | OpenSim/Framework/Util.cs | 38 |
1 files changed, 36 insertions, 2 deletions
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 | |||
47 | private static Dictionary<LLUUID, string> capsURLS = new Dictionary<LLUUID, string>(); | 47 | private static Dictionary<LLUUID, string> capsURLS = new Dictionary<LLUUID, string>(); |
48 | 48 | ||
49 | #region Vector Equasions | 49 | #region Vector Equasions |
50 | 50 | /// <summary> | |
51 | /// Get the distance between two 3d vectors | ||
52 | /// </summary> | ||
53 | /// <param name="a">A 3d vector</param> | ||
54 | /// <param name="b">A 3d vector</param> | ||
55 | /// <returns>The distance between the two vectors</returns> | ||
51 | public static double GetDistanceTo(LLVector3 a, LLVector3 b) | 56 | public static double GetDistanceTo(LLVector3 a, LLVector3 b) |
52 | { | 57 | { |
53 | float dx = a.X - b.X; | 58 | float dx = a.X - b.X; |
@@ -55,14 +60,43 @@ namespace OpenSim.Framework | |||
55 | float dz = a.Z - b.Z; | 60 | float dz = a.Z - b.Z; |
56 | return Math.Sqrt(dx*dx + dy*dy + dz*dz); | 61 | return Math.Sqrt(dx*dx + dy*dy + dz*dz); |
57 | } | 62 | } |
63 | |||
64 | /// <summary> | ||
65 | /// Get the magnitude of a 3d vector | ||
66 | /// </summary> | ||
67 | /// <param name="a">A 3d vector</param> | ||
68 | /// <returns>The magnitude of the vector</returns> | ||
58 | public static double GetMagnitude(LLVector3 a) { | 69 | public static double GetMagnitude(LLVector3 a) { |
59 | return Math.Sqrt((a.X * a.X) + (a.Y * a.Y) + (a.Z * a.Z)); | 70 | return Math.Sqrt((a.X * a.X) + (a.Y * a.Y) + (a.Z * a.Z)); |
60 | } | 71 | } |
61 | public static LLVector3 GetNormal(LLVector3 a) | 72 | |
73 | /// <summary> | ||
74 | /// Get a normalized form of a 3d vector | ||
75 | /// </summary> | ||
76 | /// <param name="a">A 3d vector</param> | ||
77 | /// <returns>A new vector which is normalized form of the vector</returns> | ||
78 | /// <remarks>The vector paramater cannot be <0,0,0></remarks> | ||
79 | public static LLVector3 GetNormalizedVector(LLVector3 a) | ||
62 | { | 80 | { |
81 | if (IsZeroVector(a)) | ||
82 | throw new ArgumentException("Vector paramater cannot be a zero vector."); | ||
83 | |||
63 | float Mag = (float)GetMagnitude(a); | 84 | float Mag = (float)GetMagnitude(a); |
64 | return new LLVector3(a.X / Mag, a.Y / Mag, a.Z / Mag); | 85 | return new LLVector3(a.X / Mag, a.Y / Mag, a.Z / Mag); |
86 | } | ||
65 | 87 | ||
88 | /// <summary> | ||
89 | /// Returns if a vector is a zero vector (has all zero components) | ||
90 | /// </summary> | ||
91 | /// <returns></returns> | ||
92 | public static bool IsZeroVector( LLVector3 v ) | ||
93 | { | ||
94 | if( v.X == 0 && v.Y == 0 && v.Z == 0) | ||
95 | { | ||
96 | return true; | ||
97 | } | ||
98 | |||
99 | return false; | ||
66 | } | 100 | } |
67 | # endregion | 101 | # endregion |
68 | 102 | ||