示例#1
0
 /// <summary>Clamp the components of 'vec' within the ranges of 'min' and 'max'</summary>
 public static v3 Clamp(v3 vec, v3 min, v3 max)
 {
     return(new v3(
                Clamp(vec.x, min.x, max.x),
                Clamp(vec.y, min.y, max.y),
                Clamp(vec.z, min.z, max.z)));
 }
示例#2
0
 /// <summary>Return a vector containing the maximum components</summary>
 public static v3 Max(v3 lhs, v3 rhs)
 {
     return(new v3(
                Math.Max(lhs.x, rhs.x),
                Math.Max(lhs.y, rhs.y),
                Math.Max(lhs.z, rhs.z)));
 }
示例#3
0
 /// <summary>Approximate equal</summary>
 public static bool FEqlAbsolute(v3 a, v3 b, float tol)
 {
     return
         (FEqlAbsolute(a.x, b.x, tol) &&
          FEqlAbsolute(a.y, b.y, tol) &&
          FEqlAbsolute(a.z, b.z, tol));
 }
示例#4
0
 /// <summary>Component absolute value</summary>
 public static v3 Abs(v3 vec)
 {
     return(new v3(
                Math.Abs(vec.x),
                Math.Abs(vec.y),
                Math.Abs(vec.z)));
 }
示例#5
0
            void Scale(v3 v)
            {
                Matrix3 m = new Matrix3();

                m.SetScaled(v.x, v.y, v.z);
                Set(this * m);
            }
示例#6
0
 public v3 Cross(v3 rhs)
 {
     return(new v3(
                y * rhs.z - z * rhs.y,
                z * rhs.x - x * rhs.z,
                x * rhs.y - y * rhs.x));
 }
示例#7
0
 public static v3 Max(v3 x, params v3[] vecs)
 {
     foreach (var v in vecs)
     {
         x = Max(x, v);
     }
     return(x);
 }
示例#8
0
        /// <summary>Returns a vector perpendicular to 'vec'</summary>
        public static v3 Perpendicular(v3 vec)
        {
            Debug.Assert(!FEql(vec, v3.Zero), "Cannot make a perpendicular to a zero vector");
            var v = Cross(vec, CreateNotParallelTo(vec));

            v *= vec.Length / v.Length;
            return(v);
        }
示例#9
0
            public float Distance(v3 other)
            {
                float dX = x - other.x;
                float dY = y - other.y;
                float dZ = z - other.z;

                return((float)Math.Sqrt(dX * dX + dY * dY + dZ * dZ));
            }
示例#10
0
            float AngleBetween(v3 other)
            {
                v3 a = GetNormalized();
                v3 b = other.GetNormalized();

                float d = a.x * b.x + a.y * b.y + a.z * b.z;

                return((float)Math.Acos(d));
            }
示例#11
0
        /// <summary>Normalise 'vec' by the length of the XYZ components or return 'def' if zero</summary>
        public static v3 Normalise(v3 vec, v3 def)
        {
            if (vec == v3.Zero)
            {
                return(def);
            }
            var norm = Normalise(vec);

            return(norm != v3.Zero ? norm : def);
        }
示例#12
0
        public static bool FEqlRelative(v3 a, v3 b, float tol)
        {
            var max_a = MaxElement(Abs(a));
            var max_b = MaxElement(Abs(b));

            if (max_b == 0)
            {
                return(max_a < tol);
            }
            if (max_a == 0)
            {
                return(max_b < tol);
            }
            var abs_max_element = Max(max_a, max_b);

            return(FEqlRelative(a, b, tol * abs_max_element));
        }
示例#13
0
        /// <summary>Returns a vector perpendicular to 'vec' favouring 'previous' as the preferred perpendicular</summary>
        public static v3 Perpendicular(v3 vec, v3 previous)
        {
            Debug.Assert(!FEql(vec, v3.Zero), "Cannot make a perpendicular to a zero vector");

            // If 'previous' is parallel to 'vec', choose a new perpendicular (includes previous == zero)
            if (Parallel(vec, previous))
            {
                return(Perpendicular(vec));
            }

            // If 'previous' is still perpendicular, keep it
            if (FEql(Dot(vec, previous), 0))
            {
                return(previous);
            }

            // Otherwise, make a perpendicular that is close to 'previous'
            var v = Cross(Cross(vec, previous), vec);

            v *= (float)Math.Sqrt(vec.LengthSq / v.LengthSq);
            return(v);
        }
示例#14
0
        /// <summary>Return the minimum element value in 'v'</summary>
        public static float MinElement(v3 v)
        {
            var i = v.x <= v.y ? v.x : v.y;

            return(i <= v.z ? i : v.z);
        }
示例#15
0
        /// <summary>Returns a vector guaranteed to not be parallel to 'vec'</summary>
        public static v3 CreateNotParallelTo(v3 vec)
        {
            bool x_aligned = Abs(vec.x) > Abs(vec.y) && Abs(vec.x) > Abs(vec.z);

            return(new v3(SignF(!x_aligned), 0, SignF(x_aligned)));
        }
示例#16
0
 /// <summary>Return true if any components of 'vec' are NaN</summary>
 public static bool IsNaN(v3 vec)
 {
     return(IsNaN(vec.x) || IsNaN(vec.y) || IsNaN(vec.z));
 }
示例#17
0
 /// <summary>True if 'lhs' and 'rhs' are parallel</summary>
 public static bool Parallel(v3 lhs, v3 rhs)
 {
     return(FEql(Cross(lhs, rhs).LengthSq, 0));
 }
示例#18
0
 /// <summary>Linearly interpolate between two vectors</summary>
 public static v3 Lerp(v3 lhs, v3 rhs, float frac)
 {
     return(lhs * (1f - frac) + rhs * (frac));
 }
示例#19
0
 /// <summary>Cross product of XYZ components</summary>
 public static v3 Cross(v3 lhs, v3 rhs)
 {
     return(new v3(lhs.y * rhs.z - lhs.z * rhs.y, lhs.z * rhs.x - lhs.x * rhs.z, lhs.x * rhs.y - lhs.y * rhs.x));
 }
示例#20
0
 /// <summary>Triple product of XYZ components</summary>
 public static float Triple(v3 a, v3 b, v3 c)
 {
     return(Dot(a, Cross(b, c)));
 }
示例#21
0
 /// <summary>Return 'a/b', or 'def' if 'b' is zero</summary>
 public static v3 Div(v3 a, v3 b, v3 def)
 {
     return(b != v3.Zero ? a / b : def);
 }
示例#22
0
 /// <summary>Dot product of XYZ components</summary>
 public static float Dot(v3 lhs, v3 rhs)
 {
     return(lhs.x * rhs.x + lhs.y * rhs.y + lhs.z * rhs.z);
 }
示例#23
0
 public static v3 Normalise(ref v3 vec)
 {
     return(vec /= vec.Length);
 }
示例#24
0
 /// <summary>Normalise 'vec' by the length of the XYZ components</summary>
 public static v3 Normalise(v3 vec)
 {
     return(vec / vec.Length);
 }
示例#25
0
        /// <summary>Return the maximum element value in 'v'</summary>
        public static float MaxElement(v3 v)
        {
            var i = v.x >= v.y ? v.x : v.y;

            return(i >= v.z ? i : v.z);
        }
示例#26
0
 return(IsPointInside(v1, v2, v3, point.X, point.Y));
示例#27
0
 /// <summary>Return the cosine of the angle between two vectors</summary>
 public static float CosAngle(v3 lhs, v3 rhs)
 {
     Debug.Assert(lhs.LengthSq != 0 && rhs.LengthSq != 0, "CosAngle undefined for zero vectors");
     return(Clamp(Dot(lhs, rhs) / (float)Math.Sqrt(lhs.LengthSq * rhs.LengthSq), -1f, 1f));
 }
示例#28
0
 /// <summary>Return the angle between two vectors</summary>
 public static float Angle(v3 lhs, v3 rhs)
 {
     return((float)Math.Acos(CosAngle(lhs, rhs)));
 }
示例#29
0
        /// <summary>Return the index of the maximum element in 'v'</summary>
        public static int MaxElementIndex(v3 v)
        {
            int i = v.y >= v.z ? 1 : 2;

            return(v.x >= v[i] ? 0 : i);
        }
示例#30
0
 public V3Screen(v3.ZProcessor zproc)
 {
     cpu = zproc;
     Windows = new VM.Window[2];
 }
示例#31
0
        /// <summary>Return the index of the minimum element in 'v'</summary>
        public static int MinElementIndex(v3 v)
        {
            int i = v.y <= v.z ? 1 : 2;

            return(v.x <= v[i] ? 0 : i);
        }