Browse Source

-added normalize()

Anton Rohr 11 năm trước cách đây
mục cha
commit
5f7e942601
1 tập tin đã thay đổi với 31 bổ sung2 xóa
  1. 31 2
      bbiwarg/Utility/Vector.cs

+ 31 - 2
bbiwarg/Utility/Vector.cs

@@ -129,8 +129,19 @@ namespace bbiwarg.Utility
             }
             return result;
         }
+        public Vector<T> normalize() 
+        {
+            T norm = this.norm();
+            Vector<T> result = new Vector<T>(this);
+            for (int i = 0; i < result.length(); i++)
+            {
+                result[i] = (result[i] / (dynamic)norm);
+            }
+            return result;
+        }
 
-        public T subDistance(Vector<T> vector, int subLength) {
+        public T subDistance(Vector<T> vector, int subLength)
+        {
             return (vector - this).subNorm(subLength);
         }
 
@@ -167,6 +178,24 @@ namespace bbiwarg.Utility
             }
             return result;
         }
+        public static bool operator ==(Vector<T> vector1, Vector<T> vector2)
+        {
+            checkLength(vector1, vector2);
+            bool result = true;
+            for (int i = 0; i < vector1.length(); i++)
+            {
+                if (vector1[i] != (dynamic)vector2[i])
+                {
+                    result = false;
+                    break;
+                }
+            }
+            return result;
+        }
+        public static bool operator !=(Vector<T> vector1, Vector<T> vector2)
+        {
+            return !(vector1 == vector2);
+        }
         public static Vector<T> crossProduct(Vector<T> vector1, Vector<T> vector2)
         {
             if (vector1.length() != 3 || vector2.length() != 3)
@@ -197,7 +226,7 @@ namespace bbiwarg.Utility
 
             Vector<T> ab = planeB - planeA;
             Vector<T> ac = planeC - planeA;
-            Vector<T> normal = crossProduct(ab, ac);
+            Vector<T> normal = crossProduct(ab, ac).normalize();
 
             Vector<T> temp = point - planeA;
             temp = pointwiseMultiply(temp, normal);