/// <summary> /// Test whether a <see cref="AABBd"/> intersects this plane. /// See: Ericson 2005, Real Time Collision Detection, p. 161 - 164 /// </summary> /// <param name="aabb">The axis aligned bounding box.</param> public bool Intersects(AABBd aabb) { var r = BoxExtendInNormalDirection(aabb); var s = SignedDistanceFromPoint(aabb.Center); return(System.Math.Abs(s) <= r); }
/// <summary> /// Calculates the bounding box around an existing bounding box and a single point. /// </summary> /// <param name="a">The bounding boxes to build the union from.</param> /// <param name="p">The point to be enclosed by the resulting bounding box</param> /// <returns>The smallest axis aligned bounding box containing the input box and the point.</returns> public static AABBd Union(AABBd a, double3 p) { AABBd ret; ret.min.x = (a.min.x < p.x) ? a.min.x : p.x; ret.min.y = (a.min.y < p.y) ? a.min.y : p.y; ret.min.z = (a.min.z < p.z) ? a.min.z : p.z; ret.max.x = (a.max.x > p.x) ? a.max.x : p.x; ret.max.y = (a.max.y > p.y) ? a.max.y : p.y; ret.max.z = (a.max.z > p.z) ? a.max.z : p.z; return(ret); }
/// <summary> /// Calculates the bounding box around two existing bounding boxes. /// </summary> /// <param name="a">One of the bounding boxes to build the union from</param> /// <param name="b">The other bounding box to build the union from</param> /// <returns>The smallest axis aligned bounding box containing both input boxes</returns> public static AABBd Union(AABBd a, AABBd b) { AABBd ret; ret.min.x = (a.min.x < b.min.x) ? a.min.x : b.min.x; ret.min.y = (a.min.y < b.min.y) ? a.min.y : b.min.y; ret.min.z = (a.min.z < b.min.z) ? a.min.z : b.min.z; ret.max.x = (a.max.x > b.max.x) ? a.max.x : b.max.x; ret.max.y = (a.max.y > b.max.y) ? a.max.y : b.max.y; ret.max.z = (a.max.z > b.max.z) ? a.max.z : b.max.z; return(ret); }
/// <summary> /// Test whether a <see cref="AABBd"/> intersects this plane. /// See: Ericson 2005, Real Time Collision Detection, p. 161 - 164 /// CAREFUL: the definition whats completely inside and outside is flipped in comparison to Ericson, /// because FUSEE defines a point with a negative signed distance to be inside. /// </summary> /// <param name="aabb">The axis aligned bounding box.</param> public bool InsideOrIntersecting(AABBd aabb) { var r = BoxExtendInNormalDirection(aabb); //Distance from aabb center to plane var s = SignedDistanceFromPoint(aabb.Center); //Completely inside if (s <= -r) { return(true); } //Completely outside else if (r <= s) { return(false); } //else intersecting return(true); }
/// <summary> /// Calculates the projection interval radius of aabb onto line L(t) = aabb.Center + t * plane.Normal (extend (radius) in direction of the plane normal). /// <param name="aabb">The axis aligned bounding box.</param> /// </summary> private double BoxExtendInNormalDirection(AABBd aabb) { var boxExtend = aabb.Size * 0.5f; return(boxExtend.x * System.Math.Abs(Normal.x) + boxExtend.y * System.Math.Abs(Normal.y) + boxExtend.z * System.Math.Abs(Normal.z)); }
/// <summary> /// Check if a point lies within a AABB /// </summary> /// <param name="aabb"></param> /// <param name="point"></param> /// <returns></returns> public static bool Intersects(AABBd aabb, double3 point) { return(aabb.Intersects(point)); }
/// <summary> /// Check if two AABBs intersect each other /// </summary> /// <param name="left"></param> /// <param name="right"></param> /// <returns></returns> public static bool Intersects(AABBd left, AABBd right) { return(left.Intersects(right)); }
/// <summary> /// Check if this AABB intersects with another /// </summary> /// <param name="b"></param> /// <returns></returns> public bool Intersects(AABBd b) { return((min.x <= b.max.x && max.x >= b.min.x) && (min.y <= b.max.y && max.y >= b.min.y) && (min.z <= b.max.z && max.z >= b.min.z)); }