public static bool CreateCircumscribed(Vector3 v0, Vector3 v1, Vector3 v2, Vector3 v3, out Sphere3 sphere) { Vector3 vector = v1 - v0; Vector3 vector2 = v2 - v0; Vector3 vector3 = v3 - v0; float[,] array = new float[3, 3]; array[0, 0] = vector.x; array[0, 1] = vector.y; array[0, 2] = vector.z; array[1, 0] = vector2.x; array[1, 1] = vector2.y; array[1, 2] = vector2.z; array[2, 0] = vector3.x; array[2, 1] = vector3.y; array[2, 2] = vector3.z; float[,] a = array; float[] b = new float[] { 0.5f * vector.sqrMagnitude, 0.5f * vector2.sqrMagnitude, 0.5f * vector3.sqrMagnitude }; Vector3 b2; if (LinearSystem.Solve3(a, b, out b2, 1E-05f)) { sphere.Center = v0 + b2; sphere.Radius = b2.magnitude; return(true); } sphere = default(Sphere3); return(false); }
public static bool CreateInscribed(Vector3 v0, Vector3 v1, Vector3 v2, Vector3 v3, out Sphere3 sphere) { Vector3 vector = v1 - v0; Vector3 vector2 = v2 - v0; Vector3 vector3 = v3 - v0; Vector3 value = v2 - v1; Vector3 vector4 = v3 - v1; Vector3 vector5 = vector4.Cross(value); Vector3 vector6 = vector2.Cross(vector3); Vector3 vector7 = vector3.Cross(vector); Vector3 vector8 = vector.Cross(vector2); if (Mathf.Abs(Vector3ex.Normalize(ref vector5, 1E-05f)) < 1E-05f) { sphere = default(Sphere3); return(false); } if (Mathf.Abs(Vector3ex.Normalize(ref vector6, 1E-05f)) < 1E-05f) { sphere = default(Sphere3); return(false); } if (Mathf.Abs(Vector3ex.Normalize(ref vector7, 1E-05f)) < 1E-05f) { sphere = default(Sphere3); return(false); } if (Mathf.Abs(Vector3ex.Normalize(ref vector8, 1E-05f)) < 1E-05f) { sphere = default(Sphere3); return(false); } float[,] array = new float[3, 3]; array[0, 0] = vector6.x - vector5.x; array[0, 1] = vector6.y - vector5.y; array[0, 2] = vector6.z - vector5.z; array[1, 0] = vector7.x - vector5.x; array[1, 1] = vector7.y - vector5.y; array[1, 2] = vector7.z - vector5.z; array[2, 0] = vector8.x - vector5.x; array[2, 1] = vector8.y - vector5.y; array[2, 2] = vector8.z - vector5.z; float[,] a = array; float[] b = new float[] { 0f, 0f, -vector8.Dot(vector3) }; Vector3 vector9; if (LinearSystem.Solve3(a, b, out vector9, 1E-05f)) { sphere.Center = v3 + vector9; sphere.Radius = Mathf.Abs(vector5.Dot(vector9)); return(true); } sphere = default(Sphere3); return(false); }
internal static bool HeightPlaneFit3(IList <Vector3> points, out float a, out float b, out float c) { float num = 0f; float num2 = 0f; float num3 = 0f; float num4 = 0f; float num5 = 0f; float num6 = 0f; float num7 = 0f; float num8 = 0f; int count = points.Count; for (int i = 0; i < count; i++) { num += points[i].x; num2 += points[i].y; num3 += points[i].z; num4 += points[i].x * points[i].x; num5 += points[i].x * points[i].y; num6 += points[i].x * points[i].z; num7 += points[i].y * points[i].y; num8 += points[i].y * points[i].z; } float[,] array = new float[3, 3]; array[0, 0] = num4; array[0, 1] = num5; array[0, 2] = num; array[1, 0] = num5; array[1, 1] = num7; array[1, 2] = num2; array[2, 0] = num; array[2, 1] = num2; array[2, 2] = (float)count; float[,] a2 = array; float[] b2 = new float[] { num6, num8, num3 }; float[] array2; bool flag = LinearSystem.Solve3(a2, b2, out array2, 1E-05f); if (flag) { a = array2[0]; b = array2[1]; c = array2[2]; } else { a = 3.40282347E+38f; b = 3.40282347E+38f; c = 3.40282347E+38f; } return(flag); }
public static bool Solve3(float[,] A, float[] B, out Vector3 X, float zeroTolerance = 1E-05f) { float[] array; bool flag = LinearSystem.Solve3(A, B, out array, zeroTolerance); if (flag) { X.x = array[0]; X.y = array[1]; X.z = array[2]; } else { X = Vector3ex.Zero; } return(flag); }