コード例 #1
0
        /// <summary>
        /// tested on 30-Aug-10
        /// </summary>
        /// <param name="eq"></param>
        /// <param name="p"></param>
        /// <returns></returns>
        public static Point3D GetPtOnPlanePassingThroughAPtOnItsNormal(PlaneEquation eq, Point3D p)
        {
            //x = x1 + Ak
            //y = y1 + Bk
            //z = z1 + Ck
            //Ax + By + Cz + D = 0
            //A(x1 + Ak) + B(y1 + Bk) + C(z1 + Ck) + D = 0
            //(A*A + B*B + C*C)k = -Ax1 - By1 - Cz1 - D

            var k = -(eq.A * p.X + eq.B * p.Y + eq.C * p.Z + eq.D) / (eq.A * eq.A + eq.B * eq.B + eq.C * eq.C);

            return(new Point3D(p.X + eq.A * k, p.Y + eq.B * k, p.Z + eq.C * k));
        }
コード例 #2
0
 public static double ValueInPlaneEquation(PlaneEquation p, Point3D pt)
 {
     return(pt.X * p.A + pt.Y * p.B + pt.Z * p.C + p.D);
 }
コード例 #3
0
        public static double ValueInPlaneEquation(Point3D pt, double a, double b, double c, double d)
        {
            var p = new PlaneEquation(a, b, c, d);

            return(pt.X * p.A + pt.Y * p.B + pt.Z * p.C + p.D);
        }
コード例 #4
0
        /// <summary>
        /// gets a box for a triangle
        /// </summary>
        /// <param name="triangle"></param>
        /// <returns></returns>
        public static GeometryModel3D GetBoxForATriange(Triangle triangle)
        {
            //Get the equation of the triangle plane
            var trianglePlane = new PlaneEquation(triangle.V1, triangle.V2, triangle.V3);

            //todo: logic to decide how far the second plane should be

            //make a parallel plane
            var parallelPlane = new PlaneEquation(trianglePlane.A, trianglePlane.B, trianglePlane.C, trianglePlane.D + .02);

            var p1 = PlaneEquation.GetPtOnPlanePassingThroughAPtOnItsNormal(parallelPlane, triangle.V1);
            var p2 = PlaneEquation.GetPtOnPlanePassingThroughAPtOnItsNormal(parallelPlane, triangle.V2);
            var p3 = PlaneEquation.GetPtOnPlanePassingThroughAPtOnItsNormal(parallelPlane, triangle.V3);

            var mesh = new MeshGeometry3D();

            //add the triangle positions
            mesh.Positions.Add(triangle.V1);
            mesh.Positions.Add(triangle.V2);
            mesh.Positions.Add(triangle.V3);

            mesh.Positions.Add(p1);
            mesh.Positions.Add(p2);
            mesh.Positions.Add(p3);

            //add the triangle indices for the first triangle
            mesh.TriangleIndices.Add(0);
            mesh.TriangleIndices.Add(1);
            mesh.TriangleIndices.Add(2);

            //add the indices for the second triangle
            mesh.TriangleIndices.Add(3);
            mesh.TriangleIndices.Add(5);
            mesh.TriangleIndices.Add(4);

            //first side 031 341
            mesh.TriangleIndices.Add(0);
            mesh.TriangleIndices.Add(3);
            mesh.TriangleIndices.Add(1);

            mesh.TriangleIndices.Add(3);
            mesh.TriangleIndices.Add(4);
            mesh.TriangleIndices.Add(1);

            //second side 142 452
            mesh.TriangleIndices.Add(1);
            mesh.TriangleIndices.Add(4);
            mesh.TriangleIndices.Add(2);

            mesh.TriangleIndices.Add(4);
            mesh.TriangleIndices.Add(5);
            mesh.TriangleIndices.Add(2);

            //third side 502 530
            mesh.TriangleIndices.Add(5);
            mesh.TriangleIndices.Add(0);
            mesh.TriangleIndices.Add(2);

            mesh.TriangleIndices.Add(5);
            mesh.TriangleIndices.Add(3);
            mesh.TriangleIndices.Add(0);

            //Add a default material
            var material = new DiffuseMaterial(new SolidColorBrush(Colors.SteelBlue));

            return(new GeometryModel3D(mesh, material));
        }