/// <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))); }
/// <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))); }
/// <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)); }
/// <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))); }
void Scale(v3 v) { Matrix3 m = new Matrix3(); m.SetScaled(v.x, v.y, v.z); Set(this * m); }
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)); }
public static v3 Max(v3 x, params v3[] vecs) { foreach (var v in vecs) { x = Max(x, v); } return(x); }
/// <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); }
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)); }
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)); }
/// <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); }
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)); }
/// <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); }
/// <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); }
/// <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))); }
/// <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)); }
/// <summary>True if 'lhs' and 'rhs' are parallel</summary> public static bool Parallel(v3 lhs, v3 rhs) { return(FEql(Cross(lhs, rhs).LengthSq, 0)); }
/// <summary>Linearly interpolate between two vectors</summary> public static v3 Lerp(v3 lhs, v3 rhs, float frac) { return(lhs * (1f - frac) + rhs * (frac)); }
/// <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)); }
/// <summary>Triple product of XYZ components</summary> public static float Triple(v3 a, v3 b, v3 c) { return(Dot(a, Cross(b, c))); }
/// <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); }
/// <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); }
public static v3 Normalise(ref v3 vec) { return(vec /= vec.Length); }
/// <summary>Normalise 'vec' by the length of the XYZ components</summary> public static v3 Normalise(v3 vec) { return(vec / vec.Length); }
/// <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); }
return(IsPointInside(v1, v2, v3, point.X, point.Y));
/// <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)); }
/// <summary>Return the angle between two vectors</summary> public static float Angle(v3 lhs, v3 rhs) { return((float)Math.Acos(CosAngle(lhs, rhs))); }
/// <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); }
public V3Screen(v3.ZProcessor zproc) { cpu = zproc; Windows = new VM.Window[2]; }
/// <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); }