// Return a MeshGeometry3D representing this mesh's wireframe.
        public static MeshGeometry3D ToWireframe(this MeshGeometry3D mesh, double thickness)
        {
            // Make a mesh to hold the wireframe.
            MeshGeometry3D wireframe = new MeshGeometry3D();

            // Make a HashSet to keep track of edges
            // that have already been added.
            HashSet <Edge> already_added = new HashSet <Edge>();

            // Loop through the mesh's triangles.
            for (int triangle = 0; triangle < mesh.TriangleIndices.Count; triangle += 3)
            {
                // Get the triangle's corner indices.
                int     index1 = mesh.TriangleIndices[triangle];
                int     index2 = mesh.TriangleIndices[triangle + 1];
                int     index3 = mesh.TriangleIndices[triangle + 2];
                Point3D point1 = mesh.Positions[index1];
                Point3D point2 = mesh.Positions[index2];
                Point3D point3 = mesh.Positions[index3];

                // Make the triangle's three segments.
                wireframe.AddEdge(already_added, point1, point2, thickness);
                wireframe.AddEdge(already_added, point2, point3, thickness);
                wireframe.AddEdge(already_added, point3, point1, thickness);
            }

            return(wireframe);
        }
        // Add an outline wireframe for a polygon.
        public static void AddPolygonWireframe(this MeshGeometry3D mesh,
                                               double thickness, params Point3D[] points)
        {
            // Make a HashSet to keep track of edges
            // that have already been added.
            HashSet <Edge> already_added = new HashSet <Edge>();

            // Loop through the polygon's vertices.
            for (int i = 0; i < points.Length - 1; i++)
            {
                mesh.AddEdge(already_added, points[i], points[i + 1], thickness);
            }
            mesh.AddEdge(already_added, points[points.Length - 1], points[0], thickness);
        }
Example #3
0
        // Define the model.
        private void DefineModel(Model3DGroup group)
        {
            // Axes.
            MeshExtensions.AddAxes(group);

            // Make the generator.
            const int    numPoints = 20;
            const double tmin      = 1.1 * Math.PI;
            const double tmax      = tmin + 1.8 * Math.PI;

            Point3D[] generator = new Point3D[numPoints];
            double    t         = tmin;
            double    dt        = (tmax - tmin) / (numPoints - 1);

            for (int i = 0; i < numPoints; i++)
            {
                generator[i] = new Point3D(1 + 0.5 * Math.Sin(t), 3 - t * 0.5, 0);
                t           += dt;
            }

            // Make the transformation.
            const int         numRot = 20;
            const double      dangle = 360.0 / numRot;
            RotateTransform3D rot    = D3.Rotate(D3.YVector(), D3.Origin, dangle);

            // Make the surface of transformation.
            MeshGeometry3D mesh1 = new MeshGeometry3D();

            mesh1.AddTransformSurface(generator, rot, numRot,
                                      false, false, true, true,
                                      false);
            group.Children.Add(mesh1.MakeModel(Brushes.LightBlue));

            // Make a wireframe.
            HashSet <Edge> edges = new HashSet <Edge>();
            MeshGeometry3D mesh2 = new MeshGeometry3D();

            mesh2.AddTransformSurface(generator, rot, numRot,
                                      false, false, true, true,
                                      false, edges, 0.02);
            group.Children.Add(mesh2.MakeModel(Brushes.Blue));

            // Display the generator.
            edges = new HashSet <Edge>();
            MeshGeometry3D mesh3 = new MeshGeometry3D();

            for (int i = 1; i < numPoints; i++)
            {
                mesh3.AddEdge(edges, 0.1, generator[i - 1], generator[i]);
            }
            group.Children.Add(mesh3.MakeModel(Brushes.Black));
        }