コード例 #1
0
        public void Calculate()
        {
            MeshGeometry3D myMeshGeometry3D = new MeshGeometry3D();

            // Create a collection of vertex positions for the MeshGeometry3D.
            Point3DCollection myPositionCollection = new Point3DCollection();

            // Create a collection of triangle indices for the MeshGeometry3D.
            Int32Collection myTriangleIndicesCollection = new Int32Collection();

            // Apply the mesh to the geometry model.
            myGeometryModel.Geometry = myMeshGeometry3D;

            ax3d = new AxisAngleRotation3D(new Vector3D(0, 2, 0), 1);
            RotateTransform3D myRotateTransform = new RotateTransform3D(ax3d);
            myGeometryModel.Transform = myRotateTransform;

            List<Point3DCollection>
                Discs = new List<Point3DCollection>();
            for (double betta = 0; betta <= Math.PI/2; betta += step_betta)
            {
                double Z = Radius * Math.Sin(betta);
                Point3DCollection disc = new Point3DCollection();
                double r1 = Math.Sqrt(Radius * Radius - Math.Pow(Z, 2));
                for (double alfa = 0; alfa <= 2 * Math.PI; alfa += step_alfa)
                {
                    double Y = r1 * Math.Sin(alfa);
                    double tempVal = Math.Max(Radius * Radius - Math.Pow(Y, 2) - Math.Pow(Z, 2), 0);
                    double X = Math.Sqrt(tempVal);
                    disc.Add(new Point3D(X, Y, Z));
                }

                Discs.Add(disc);
            }

            LinearGradientBrush myHorizontalGradient = new LinearGradientBrush();
            myHorizontalGradient.StartPoint = new Point(0, 0);
            myHorizontalGradient.EndPoint = new Point(1, 1);
            myHorizontalGradient.GradientStops.Add(new GradientStop(Colors.White, 0.0));
            myHorizontalGradient.GradientStops.Add(new GradientStop(Colors.Black, 1.0));

            DiffuseMaterial myDiffuseMaterial = new DiffuseMaterial(myHorizontalGradient);
            MaterialGroup myMaterialGroup = new MaterialGroup();
            myMaterialGroup.Children.Add(myDiffuseMaterial);

            PointCollection myTextureCoordinatesCollection = new PointCollection();

            myMeshGeometry3D.TextureCoordinates = myTextureCoordinatesCollection;
            myGeometryModel.Material = myMaterialGroup;

            m_result.Clear();

            Triangle t1 = null;
            for (int i = 1; i < Discs.Count; i++)
            {
                Point3DCollection disc1 = Discs[i - 1];
                Point3DCollection disc2 = Discs[i];
                t1 = null;
                for (int j = 1; j < disc1.Count; j++)
                {
                    Point3D p1 = disc1[j - 1];
                    Point3D p2 = disc1[j];
                    Point3D p3 = disc2[j];
                    Point3D p4 = disc2[j - 1];

                    if (j == 1)
                    {
                        Vector3D v21 = p2 - p1;
                        Double distanceBetween21 = v21.Length;

                        Vector3D v43 = p4 - p3;
                        Double distanceBetween43 = v43.Length;

                        Vector3D v32 = p3 - p2;
                        Double distanceBetween32 = v32.Length;

                        Vector3D v41 = p4 - p1;
                        Double distanceBetween41 = v41.Length;

                        Double h = (distanceBetween43 - distanceBetween21)/2;
                        h = Math.Sqrt(Math.Pow(distanceBetween32, 2) - Math.Pow(h, 2));

                        m_result.Add(string.Format("{0:00.00}|{1:00.00}|{2:00.00}|h-{3:00.00}", distanceBetween21, distanceBetween43, distanceBetween32, h));
                    }

                    if (t1 != null)
                    {
                        Triangle t2 = new Triangle(p1, p2, p3);
                        double angle = t2.GetAngle(t1);
                        m_result.Add(string.Format("angle-{0:00.00}", angle));
                    }
                    t1 = new Triangle(p1, p2, p3);

                    myTextureCoordinatesCollection.Add(new Point(p1.X, p1.Y));
                    myTextureCoordinatesCollection.Add(new Point(p2.X, p2.Y));
                    myTextureCoordinatesCollection.Add(new Point(p3.X, p3.Y));
                    myTextureCoordinatesCollection.Add(new Point(p4.X, p4.Y));

                    myPositionCollection.Add(p4);
                    myPositionCollection.Add(p3);
                    myPositionCollection.Add(p1);

                    myPositionCollection.Add(p1);
                    myPositionCollection.Add(p3);
                    myPositionCollection.Add(p2);
                }
            }

            myMeshGeometry3D.Positions = myPositionCollection;

            myMeshGeometry3D.TriangleIndices = myTriangleIndicesCollection;
        }
コード例 #2
0
ファイル: Points.cs プロジェクト: pruginkad/webinterest
 public double GetAngle(Triangle plane2)
 {
     Vector3D norm2 = plane2.Normal;
     return Vector3D.AngleBetween(Normal, norm2);
 }