private static void IntersectionPoint( ref PlaneD a, ref PlaneD b, ref PlaneD c, out Vector3D result ) { /* Formula used * d1 ( N2 * N3 ) + d2 ( N3 * N1 ) + d3 ( N1 * N2 ) * P = ------------------------------------------------------------------- * N1 . ( N2 * N3 ) * * Note: N refers to the normal, d refers to the displacement. '.' means dot * product. '*' means cross product */ Vector3D v1, v2, v3; Vector3D cross; Vector3D.Cross(ref b.Normal, ref c.Normal, out cross); double f; Vector3D.Dot(ref a.Normal, ref cross, out f); f *= -1.0f; Vector3D.Cross(ref b.Normal, ref c.Normal, out cross); Vector3D.Multiply(ref cross, a.D, out v1); // v1 = (a.D * (Vector3D.Cross(b.Normal, c.Normal))); Vector3D.Cross(ref c.Normal, ref a.Normal, out cross); Vector3D.Multiply(ref cross, b.D, out v2); // v2 = (b.D * (Vector3D.Cross(c.Normal, a.Normal))); Vector3D.Cross(ref a.Normal, ref b.Normal, out cross); Vector3D.Multiply(ref cross, c.D, out v3); // v3 = (c.D * (Vector3D.Cross(a.Normal, b.Normal))); result.X = (v1.X + v2.X + v3.X) / f; result.Y = (v1.Y + v2.Y + v3.Y) / f; result.Z = (v1.Z + v2.Z + v3.Z) / f; }
/// <summary> /// Gets whether or not a specified <see cref="PlaneD"/> intersects with this sphere. /// </summary> /// <param name="plane">The plane for testing.</param> /// <param name="result">Type of intersection as an output parameter.</param> public void Intersects(ref PlaneD plane, out PlaneIntersectionTypeD result) { double distance = default(double); // TODO: We might want to inline this for performance reasons. Vector3D.Dot(ref plane.Normal, ref this.Center, out distance); distance += plane.D; if (distance > this.Radius) { result = PlaneIntersectionTypeD.Front; } else if (distance < -this.Radius) { result = PlaneIntersectionTypeD.Back; } else { result = PlaneIntersectionTypeD.Intersecting; } }
public void Intersects(ref PlaneD plane, out double?result) { double den = Vector3D.Dot(Direction, plane.Normal); if (Math.Abs(den) < 0.00001f) { result = null; return; } result = (-plane.D - Vector3D.Dot(plane.Normal, Position)) / den; if (result < 0.0f) { if (result < -0.00001f) { result = null; return; } result = 0.0f; } }
public void Intersects(ref PlaneD plane, out PlaneIntersectionTypeD result) { // See http://zach.in.tu-clausthal.de/teaching/cg_literatur/lighthouse3d_view_frustum_culling/index.html Vector3D positiveVertex; Vector3D negativeVertex; if (plane.Normal.X >= 0) { positiveVertex.X = Max.X; negativeVertex.X = Min.X; } else { positiveVertex.X = Min.X; negativeVertex.X = Max.X; } if (plane.Normal.Y >= 0) { positiveVertex.Y = Max.Y; negativeVertex.Y = Min.Y; } else { positiveVertex.Y = Min.Y; negativeVertex.Y = Max.Y; } if (plane.Normal.Z >= 0) { positiveVertex.Z = Max.Z; negativeVertex.Z = Min.Z; } else { positiveVertex.Z = Min.Z; negativeVertex.Z = Max.Z; } // Inline Vector3D.Dot(plane.Normal, negativeVertex) + plane.D; double distance = ( plane.Normal.X * negativeVertex.X + plane.Normal.Y * negativeVertex.Y + plane.Normal.Z * negativeVertex.Z + plane.D ); if (distance > 0) { result = PlaneIntersectionTypeD.Front; return; } // Inline Vector3D.Dot(plane.Normal, positiveVertex) + plane.D; distance = ( plane.Normal.X * positiveVertex.X + plane.Normal.Y * positiveVertex.Y + plane.Normal.Z * positiveVertex.Z + plane.D ); if (distance < 0) { result = PlaneIntersectionTypeD.Back; return; } result = PlaneIntersectionTypeD.Intersecting; }