public int QuerySide(ref Sphere3 sphere, float epsilon = 1E-05f) { float num = this.Normal.Dot(sphere.Center) - this.Constant; if (num > sphere.Radius - epsilon) { return(1); } if (num >= -sphere.Radius + epsilon) { return(0); } return(-1); }
public void Include(ref Sphere3 sphere) { Vector3 a = sphere.Center - this.Center; float sqrMagnitude = a.sqrMagnitude; float num = sphere.Radius - this.Radius; float num2 = num * num; if (num2 >= sqrMagnitude) { if (num >= 0f) { this = sphere; } return; } float num3 = Mathf.Sqrt(sqrMagnitude); if (num3 > 1E-05f) { float d = (num3 + num) / (2f * num3); this.Center += d * a; } this.Radius = 0.5f * (num3 + this.Radius + sphere.Radius); }
public bool QuerySidePositive(ref Sphere3 sphere, float epsilon = 1E-05f) { float num = this.Normal.Dot(sphere.Center) - this.Constant; return(num >= sphere.Radius - epsilon); }
public void Include(Sphere3 sphere) { this.Include(ref sphere); }
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); }
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); }