public static SphereF Merge(SphereF a, SphereF b) { if (a == b) { return(a); } var c1 = a.Origin; var c2 = b.Origin; var r1 = a.Radius; var r2 = b.Radius; var r = (c1 - c2).Length(); if (r + r1 < r2) { return(b); } if (r + r2 < r1) { return(a); } var newR = (r1 + r2 + r) * 0.5f; var newC = c1 + (c2 - c1) * (newR - r1) / r; return(new SphereF(newC, newR)); }
/// <summary> /// Determines whether the given sphere intersects the current instance of <see cref="ConeF"/>. /// </summary> /// <param name="sphere">The sphere to check.</param> /// <returns>True if the given sphere intersects the current instance of <see cref="ConeF"/>; False otherwise.</returns> public bool Intersects(SphereF sphere) { float sinAngle = MathEx.Sin(Angle); float cosAngle = MathEx.Cos(Angle); float invSin = 1.0f / sinAngle; float cosSqr = cosAngle * cosAngle; Vector3F cmv = sphere.Origin - Origin; Vector3F d = cmv + (sphere.Radius * invSin) * Axis; float lengthSqr = d.LengthSquared(); float e = Vector3F.Dot(d, Axis); if (e > 0 && e * e >= lengthSqr * cosSqr) { float sinSqr = sinAngle * sinAngle; lengthSqr = cmv.LengthSquared(); e = -Vector3F.Dot(cmv, Axis); if (e > 0.0f && e * e >= lengthSqr * sinSqr) { float rSqr = sphere.Radius * sphere.Radius; return(lengthSqr <= rSqr); } return(true); } return(false); }
public bool Equals(SphereF v, float epsilon) { if (!Origin.Equals(ref v.Origin, epsilon)) { return(false); } if (Math.Abs(Radius - v.Radius) > epsilon) { return(false); } return(true); }
public bool Intersects(ref SphereF s) { float x = s.Origin.X - Origin.X; float y = s.Origin.Y - Origin.Y; float z = s.Origin.Z - Origin.Z; float lengthSqr = x * x + y * y + z * z; float r = s.Radius + Radius; if (lengthSqr > r * r) { return(false); } return(true); }
public SphereF(SphereF source) { Origin = source.Origin; Radius = source.Radius; }
public bool Contains(SphereF s) { return(Contains(ref s)); }
public bool Contains(ref SphereF s) { return((Origin - s.Origin).Length() + s.Radius <= Radius); }
public bool Intersects(SphereF s) { return(Intersects(ref s)); }
public Sphere(SphereF source) { Origin = source.Origin.ToVector3(); Radius = source.Radius; }