public void Constructor_MinMax() { var actual = new AABBf(new float3(0, 0, 0), new float3(1, 1, 1)); Assert.Equal(new float3(0, 0, 0), actual.min); Assert.Equal(new float3(1, 1, 1), actual.max); }
/// <summary> /// Test whether a <see cref="AABBf"/> 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(AABBf aabb) { var r = BoxExtendInNormalDirection(aabb); var s = SignedDistanceFromPoint(aabb.Center); return(System.Math.Abs(s) <= r); }
public void Size_Is1() { var aabbf = new AABBf(new float3(0, 0, 0), new float3(1, 1, 1)); var actual = aabbf.Size; Assert.Equal(new float3(1, 1, 1), actual); }
public void Center_Is1() { var aabbf = new AABBf(new float3(0, 0, 0), new float3(2, 2, 2)); var actual = aabbf.Center; Assert.Equal(new float3(1, 1, 1), actual); }
public static IEnumerable <object[]> GetUnion() { var a = new AABBf(new float3(0, 0, 0), new float3(1, 1, 1)); var b = new AABBf(new float3(1, 1, 1), new float3(2, 2, 2)); yield return(new object[] { a, b, new AABBf(new float3(0, 0, 0), new float3(2, 2, 2)) }); yield return(new object[] { b, a, new AABBf(new float3(0, 0, 0), new float3(2, 2, 2)) }); }
/// <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 boxe to build the union from</param> /// <returns>The smallest axis aligned bounding box containing both input boxes</returns> public static AABBf Union(AABBf a, AABBf b) { AABBf 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> /// 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 AABBf Union(AABBf a, float3 p) { AABBf 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); }
public static IEnumerable <object[]> GetTransform() { var a = new AABBf(new float3(0, 0, 0), new float3(1, 1, 1)); var xRot = new float4x4(1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1); var yRot = new float4x4(0, 0, 1, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 0, 1); var zRot = new float4x4(0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); yield return(new object[] { xRot, a, new AABBf(new float3(0, -1, 0), new float3(1, 0, 1)) }); yield return(new object[] { yRot, a, new AABBf(new float3(0, 0, -1), new float3(1, 1, 0)) }); yield return(new object[] { zRot, a, new AABBf(new float3(-1, 0, 0), new float3(0, 1, 1)) }); }
/// <summary> /// Test whether a <see cref="AABBf"/> 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(AABBf 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); }
public void Transform_IsTransform(float4x4 m, AABBf box, AABBf expected) { var actual = m * box; Assert.Equal(expected, actual); }
public void Union_IsUnion(AABBf a, AABBf b, AABBf expected) { var actual = AABBf.Union(a, b); Assert.Equal(expected, actual); }
/// <summary> /// Check if a point lies within a AABB /// </summary> /// <param name="aabb"></param> /// <param name="point"></param> /// <returns></returns> public static bool Intersects(AABBf aabb, float3 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(AABBf left, AABBf right) { return(left.Intersects(right)); }
/// <summary> /// Check if this AABB intersects with another /// </summary> /// <param name="b"></param> /// <returns></returns> public bool Intersects(AABBf 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)); }
/// <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 float BoxExtendInNormalDirection(AABBf 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)); }