public Model3D CreateModel(Point3DCollection points, Color colorStart, Color colorEnd) { var centroid = this.f.GetCentroid(); // center = Sum(p[i]) / 4 var center = points.Aggregate(new Vector3D(), (a, c) => a + (Vector3D)c) / (double)points.Count; //var normals = new Vector3DCollection(); var indices = new Int32Collection(); MakeFace(0, 1, 2, center, indices, points); var geometry = new MeshGeometry3D { Positions = points, TriangleIndices = indices }; var material = new MaterialGroup { Children = new MaterialCollection { new DiffuseMaterial(new LinearGradientBrush(colorStart, colorEnd, 0.0) { Opacity = 1.00 }) } }; return(new GeometryModel3D { Geometry = geometry, Material = material, BackMaterial = material }); }
/// <summary> /// Creates a model of the tetrahedron. Transparency is applied to the color. /// </summary> /// <param name="color"></param> /// <param name="radius"></param> /// <returns>A model representing the tetrahedron</returns> public Model3D CreateModel(Color color, double radius) { this.translation = new TranslateTransform3D(); var points = new Point3DCollection(Enumerable.Range(0, 4).Select(i => GetPosition(i))); // center = Sum(p[i]) / 4 var center = points.Aggregate(new Vector3D(), (a, c) => a + (Vector3D)c) / (double)points.Count; var normals = new Vector3DCollection(); var indices = new Int32Collection(); MakeFace(0, 1, 2, center, indices); MakeFace(0, 1, 3, center, indices); MakeFace(0, 2, 3, center, indices); MakeFace(1, 2, 3, center, indices); var geometry = new MeshGeometry3D { Positions = points, TriangleIndices = indices }; var material = new MaterialGroup { Children = new MaterialCollection { new DiffuseMaterial(new SolidColorBrush(color) { Opacity = 1.00 }), // give it some shine new SpecularMaterial(Brushes.LightYellow, 2.0) } }; pulseX = CreatePulseAnimation(2 * center.X); pulseY = CreatePulseAnimation(2 * center.Y); pulseZ = CreatePulseAnimation(2 * center.Z); expandX = CreateExpandAnimation(2 * center.X); expandY = CreateExpandAnimation(2 * center.Y); expandZ = CreateExpandAnimation(2 * center.Z); movePositive = CreateExpandAnimation(radius / 2); moveNegative = CreateExpandAnimation(-radius / 2); collapse = new DoubleAnimation { To = 0, Duration = TimeSpan.FromSeconds(1), EasingFunction = collapseEasing }; return(new GeometryModel3D { Geometry = geometry, Material = material, BackMaterial = material, Transform = translation }); }
/// <summary> /// Creates a model of the tetrahedron. Transparency is applied to the color. /// </summary> /// <param name="color"></param> /// <param name="radius"></param> /// <returns>A model representing the tetrahedron</returns> public int[][] MakeFaces() { var points = new Point3DCollection(Enumerable.Range(0, 4).Select(i => GetPosition(i))); var center = points.Aggregate(new Vector3D(), (a, c) => a + (Vector3D)c) / (double)points.Count; var indices = new int[4][]; indices[0] = MakeFace(0, 1, 2, center); indices[1] = MakeFace(0, 1, 3, center); indices[2] = MakeFace(0, 2, 3, center); indices[3] = MakeFace(1, 2, 3, center); return(indices); }