// Add a regular polygon with optional texture coordinates.
        public static void AddRegularPolygon(this MeshGeometry3D mesh,
                                             int numSides, Point3D center, Vector3D vx, Vector3D vy,
                                             Point[] textureCoords = null)
        {
            // Generate the points.
            Point3D[] points = G3.MakePolygonPoints(numSides, center, vx, vy);

            // Make the polygon.
            mesh.AddPolygon(points, textureCoords);
        }
Пример #2
0
        // Define the model.
        private void DefineModel(Model3DGroup group)
        {
            // Define a polygon in the XZ plane.
            Point3D center = new Point3D(0, 0, 4.5);

            Point3D[] polygon = G3.MakePolygonPoints(6, center,
                                                     new Vector3D(1, 0, 0), new Vector3D(0, 0, -1));

            // Make a transform to move the polygon in the -Z direction.
            TranslateTransform3D translate = new TranslateTransform3D(0, 0, -3);

            // Make a right pyramid.
            MeshGeometry3D mesh1 = new MeshGeometry3D();

            mesh1.AddPyramid(center, polygon, new Vector3D(0, 3, 0));
            group.Children.Add(mesh1.MakeModel(Brushes.Pink));

            // Make a skewed pyramid.
            translate.Transform(polygon);
            center = translate.Transform(center);
            MeshGeometry3D mesh2 = new MeshGeometry3D();

            mesh2.AddPyramid(center, polygon, new Vector3D(0, 3, 2));
            group.Children.Add(mesh2.MakeModel(Brushes.LightBlue));

            // Make a frustum with cutting plane parallel to the base.
            translate.Transform(polygon);
            center = translate.Transform(center);
            MeshGeometry3D mesh3 = new MeshGeometry3D();

            mesh3.AddFrustum(center, polygon, new Vector3D(0, 4, 0), 2);
            group.Children.Add(mesh3.MakeModel(Brushes.LightGreen));

            // Make a frustum with cutting plane not parallel to the base.
            translate.Transform(polygon);
            center = translate.Transform(center);
            MeshGeometry3D mesh4   = new MeshGeometry3D();
            Point3D        planePt = center + new Vector3D(0, 2, 0);
            Vector3D       planeN  = new Vector3D(1, 1, 1);

            mesh4.AddFrustum(center, polygon, new Vector3D(0, 4, 0), planePt, planeN);
            group.Children.Add(mesh4.MakeModel(Brushes.Orange));

            // Show the axes.
            MeshExtensions.AddAxes(group);
        }