コード例 #1
0
        bool ContainsPoint(ref Triangle3d triangle, ref Plane3d plane, Vector3D point)
        {
            // Generate a coordinate system for the plane.  The incoming triangle has
            // vertices <V0,V1,V2>.  The incoming plane has unit-length normal N.
            // The incoming point is P.  V0 is chosen as the origin for the plane. The
            // coordinate axis directions are two unit-length vectors, U0 and U1,
            // constructed so that {U0,U1,N} is an orthonormal set.  Any point Q
            // in the plane may be written as Q = V0 + x0*U0 + x1*U1.  The coordinates
            // are computed as x0 = Dot(U0,Q-V0) and x1 = Dot(U1,Q-V0).
            Vector3D U0 = Vector3D.Zero, U1 = Vector3D.Zero;

            Vector3D.GenerateComplementBasis(ref U0, ref U1, plane.Normal);

            // Compute the planar coordinates for the points P, V1, and V2.  To
            // simplify matters, the origin is subtracted from the points, in which
            // case the planar coordinates are for P-V0, V1-V0, and V2-V0.
            Vector3D PmV0  = point - triangle[0];
            Vector3D V1mV0 = triangle[1] - triangle[0];
            Vector3D V2mV0 = triangle[2] - triangle[0];

            // The planar representation of P-V0.
            Vector2D ProjP = new Vector2D(U0.Dot(PmV0), U1.Dot(PmV0));

            // The planar representation of the triangle <V0-V0,V1-V0,V2-V0>.
            Vector2dTuple3 ProjV = new Vector2dTuple3(
                Vector2D.Zero,
                new Vector2D(U0.Dot(V1mV0), U1.Dot(V1mV0)),
                new Vector2D(U0.Dot(V2mV0), U1.Dot(V2mV0)));

            // Test whether P-V0 is in the triangle <0,V1-V0,V2-V0>.
            QueryTuple2d query = new QueryTuple2d(ProjV);

            if (query.ToTriangle(ProjP, 0, 1, 2) <= 0)
            {
                Result    = IntersectionResult.Intersects;
                Type      = IntersectionType.Point;
                Quantity  = 1;
                Points[0] = point;
                return(true);
            }

            return(false);
        }
コード例 #2
0
 public QueryTuple2d(Vector2D v0, Vector2D v1, Vector2D v2)
 {
     mVertices = new Vector2dTuple3(v0, v1, v2);
 }
コード例 #3
0
 public QueryTuple2d(Vector2dTuple3 tuple)
 {
     mVertices = tuple;
 }