• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Triangle类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Triangle的典型用法代码示例。如果您正苦于以下问题:C# Triangle类的具体用法?C# Triangle怎么用?C# Triangle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Triangle类属于命名空间,在下文中一共展示了Triangle类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: isScaleneTest

 public void isScaleneTest()
 {
     Triangle tritest = new Triangle(3.0, 4.0, 5.0);
     Assert.IsTrue(tritest.isScalene());
     Assert.IsFalse(tritest.isIsosceles());
     Assert.IsFalse(tritest.isEquilateral());
 }
开发者ID:sslnustudent,项目名称:Uppgift-1,代码行数:7,代码来源:UnitTest1.cs


示例2: MeshGrid

        public MeshGrid(int sizeX, int sizeZ, float squareSideSize)
        {
            //this.device = device;
            //basicEffect = new BasicEffect(device);
            this.sizeX = sizeX;
            this.sizeZ = sizeZ;
            this.Vertices = new VertexPositionNormalTexture[sizeX + 1, sizeZ + 1];
            this.Triangles = new Triangle[sizeX*sizeZ*2];
            var rand = new Random();

            int texParam = 2;

            for (int x = 0; x < sizeX+1; x++)
                for (int z = 0; z < sizeZ+1; z++)
                    this.Vertices[x, z] = new VertexPositionNormalTexture(
                        new Vector3(squareSideSize*x, Noise.Generate(x, z)/4, squareSideSize*z),
                        Vector3.Up,
                        new Vector2(texParam * (float)x/(float)SizeX,texParam * (float)z/(float)SizeZ));

            for (int x = 0; x < sizeX; x++)
                for (int z = 0; z < sizeZ; z++)
                {
                    Triangles[x * 2 * sizeZ + z] = new Triangle(x, z, x, z + 1, x + 1, z);
                    Triangles[x * 2 * sizeZ + sizeZ + z] = new Triangle(x, z + 1, x + 1, z, x + 1, z + 1);
                }
        }
开发者ID:JGrzybowski,项目名称:MonoGameTraining,代码行数:26,代码来源:MeshGrid.cs


示例3: AddVertex

        protected void AddVertex(Face face, Vertex vertex)
        {
            base.AddVertex(vertex);
            Faces.Remove(face);

            HalfEdge h1 = face.HalfEdge;
            HalfEdge h2 = h1.Next;
            HalfEdge h3 = h2.Next;

            HalfEdge h4 = new HalfEdge(h1.Origin);
            HalfEdge h5 = new HalfEdge(h2.Origin);
            HalfEdge h6 = new HalfEdge(h3.Origin);
            HalfEdge h7 = new HalfEdge(vertex);
            HalfEdge h8 = new HalfEdge(vertex);
            HalfEdge h9 = new HalfEdge(vertex);
            HalfEdges.AddRange(new List<HalfEdge> {h4, h5, h6, h7, h8, h9});

            h4.Twin = h7;
            h7.Twin = h4;
            h5.Twin = h8;
            h8.Twin = h5;
            h6.Twin = h9;
            h9.Twin = h6;

            // Set all next
            h1.Next = h5;
            h5.Prev = h1;
            h5.Next = h7;
            h7.Prev = h5;
            h7.Next = h1;
            h1.Prev = h7;

            h2.Next = h6;
            h6.Prev = h2;
            h6.Next = h8;
            h8.Prev = h6;
            h8.Next = h2;
            h2.Prev = h8;

            h3.Next = h4;
            h4.Prev = h3;
            h4.Next = h9;
            h9.Prev = h4;
            h9.Next = h3;
            h3.Prev = h9;

            Triangle t1 = new Triangle(h1);
            Triangle t2 = new Triangle(h2);
            Triangle t3 = new Triangle(h3);

            Faces.Add(t1);
            Faces.Add(t2);
            Faces.Add(t3);

            Tree.Add(vertex, t1, t2, t3);

            LogEntry logEntry = new LogEntry("Adding edges.", this);
            logEntry.Objects.Add(vertex);
            Log.Add(logEntry);
        }
开发者ID:LuukvH,项目名称:Voronoi-Game,代码行数:60,代码来源:Triangulation.cs


示例4: arrayConstructorTest

 public void arrayConstructorTest()
 {
     double[] arraySides;
     arraySides = new double[] { 1.3, 3.5, 2.3 };
     Triangle tria = new Triangle(arraySides);
     Assert.IsTrue(tria.isCorrectTriangle());
 }
开发者ID:juhaniaa,项目名称:Uppgift-1,代码行数:7,代码来源:UnitTest1.cs


示例5: IsEar

        /// <summary>
        /// Checks if a given set of points forms an ear for a given polygon
        /// </summary>
        /// <param name="polygonPoints">The points describing the polygon</param>
        /// <param name="ear">The resulting ear, if applicable</param>
        /// <returns>True if these points form an ear</returns>
        private static bool IsEar(Point2D p1, Point2D p2, Point2D p3, List<Point2D> polygonPoints, out Triangle ear)
        {
            // for now, assign null to the ear
            ear = null;

            // Check if these points form a concave angle
            //if (Point2D.CalculateAngle(p1, p2, p3) > 0)
            //    return false; // Can't be an ear

            // Make a triangle from the given points
            Triangle t = new Triangle(p1, p2, p3);

            // Check all other points of the polygon, if one falls within this triangle, this isn't an ear
            foreach (Point2D p in polygonPoints)
                if (!p.Equals(p1) && !p.Equals(p2) && !p.Equals(p3))
                    if (Triangle.PointInTriangle(t, p))
                        return false;

            // Sort our points counter-clockwise (this is how wpf indices-triangles face 'up')
            t.Points = Point2D.SortPoints(true, p1, p2, p3).ToArray();

            // This is an ear
            ear = t;

            // Remove the center point out of the polygon
            polygonPoints.Remove(p1);

            // Report succes
            return true;
        }
开发者ID:BjornDeRijcke,项目名称:OpenStreetMap-3D,代码行数:36,代码来源:Polygon.cs


示例6: Main

        static void Main()
        {
            var trianlgle = new Triangle(3, 4, 5);
            Console.WriteLine(trianlgle.CalcTriangleArea(new HeronsFormulaArea()));

            Console.WriteLine(ConvertNumberToString(5));

            Console.WriteLine(FindMaxNumber(5, -1, 3, 2, 14, 2, 3));

            PrintInNumericFormat(1.3, "fixed-point");
            PrintInNumericFormat(0.75, "percentage");
            PrintInNumericFormat(2.30, "leftIndented");

            bool horizontal, vertical;
            Console.WriteLine(CalcPointDistance(3, -1, 3, 2.5));
            Console.WriteLine("Horizontal? " + CheckIfHorizontal(3, -1, 3, 2.5, out horizontal));
            Console.WriteLine("Vertical? " + CheckIfVertical(3, -1, 3, 2.5, out vertical));

            Student peter = new Student("Peter", "Ivanov", "From Sofia, born at 17.03.1992");
            
            Student stella = new Student("Stella", "Markova", "From Vidin, gamer, high results, born at 03.11.1993");
            
            Console.WriteLine("{0} older than {1} -> {2}",
                peter.FirstName, stella.FirstName, peter.IsOlderThan(stella));
        }
开发者ID:PlamenaMiteva,项目名称:Quality-Programming-Code,代码行数:25,代码来源:Methods.cs


示例7: AssignChildren

 public void AssignChildren(Triangle cm, Triangle ct, Triangle cl, Triangle cr)
 {
     childMid = cm;
     childTop = ct;
     childLeft = cl;
     childRight = cr;
 }
开发者ID:beardhero,项目名称:HEX,代码行数:7,代码来源:Triangle.cs


示例8: SetSize

        public void SetSize(float left, float right, float bottom, float top)
        {
            var tris = new Triangle<VertexTP2>[2];
            var p1 = new Vector2(left , bottom);
            var p2 = new Vector2(right, bottom);
            var p3 = new Vector2(right, top);
            var p4 = new Vector2(left, top);
            var t1 = new Vector2(0f, 0f);
            var t2 = new Vector2(1f, 0f);
            var t3 = new Vector2(1f, 1f);
            var t4 = new Vector2(0f, 1f);

            tris[0].A.Position = p1;
            tris[0].A.TexCoord = t1;
            tris[0].B.Position = p2;
            tris[0].B.TexCoord = t2;
            tris[0].C.Position = p3;
            tris[0].C.TexCoord = t3;
            tris[1].A.Position = p3;
            tris[1].A.TexCoord = t3;
            tris[1].B.Position = p4;
            tris[1].B.TexCoord = t4;
            tris[1].C.Position = p1;
            tris[1].C.TexCoord = t1;

            GL.BindBuffer(BufferTarget.ArrayBuffer, vbo);
            var sizeInBytes = Marshal.SizeOf(new Triangle<VertexTP2>());
            GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(sizeInBytes * 2), tris, BufferUsageHint.StaticDraw);
        }
开发者ID:det,项目名称:Rimbalzo,代码行数:29,代码来源:Image.cs


示例9: PlotTriple

 public void PlotTriple(Site s1, Site s2, Site s3) {
     if (Debug) {
         Console.WriteLine("triple {0} {1} {2}", s1, s2, s3);
     }
     var triangle = new Triangle(s1, s2, s3) { New = true };
     Triangles.Add(triangle);
 }
开发者ID:craigge,项目名称:dx11,代码行数:7,代码来源:VoronoiGraph.cs


示例10: Main

        static void Main(string[] args)
        {
            List<String> triangles = new List<String>();

            try {
                FileStream file = new FileStream("triangles.txt", FileMode.Open);
                StreamReader stream = new StreamReader(file);

                while(!stream.EndOfStream) {
                    triangles.Add(stream.ReadLine());
                }

                stream.Close();
                file.Close();
            }
            catch(Exception e) {
                Console.WriteLine(e);
            }

            int count = 0;
            for (int i = 0; i < triangles.Count; i++) {
                bool result = new Triangle(triangles[i]).Score();
                if(result) {
                    count++;
                }
            }

            Console.WriteLine(count);
            Console.ReadLine();
        }
开发者ID:ThRM,项目名称:BackOnTheWeb,代码行数:30,代码来源:Program.cs


示例11: Main

 public static void Main()
 {
     Triangle triangle = new Triangle(3, 4, 5);
     AreaCalculator areaCalculator = new AreaCalculator(triangle);
     double triangleArea = areaCalculator.CalcArea();
     Console.WriteLine(triangleArea);
 }
开发者ID:ValMomchilova,项目名称:TelerikAcademyHomeWorks,代码行数:7,代码来源:AreaCalculatorMain.cs


示例12: Main

    static void Main()
    {
        var shapes = new Shape[numberOfShapes];

        for (int i = 0; i < shapes.Length; i++)
        {
            switch (vladoRandoma.Next() % 3)
            {
                case 0:
                    shapes[i] = new Triangle(widths[vladoRandoma.Next(0, widths.Length)],
                                                 heights[vladoRandoma.Next(0, heights.Length)]);
                    break;
                case 1: shapes[i] = new Rectangle(widths[vladoRandoma.Next(0, widths.Length)],
                                                 heights[vladoRandoma.Next(0, heights.Length)]);
                    break;
                case 2: shapes[i] = new Circle(heights[vladoRandoma.Next(0, heights.Length)]);
                    break;

                default:
                    break;
            }
        }

        foreach (var item in shapes)
        {
            Console.WriteLine(item.ToString().Replace(',', '.'));
        }
    }
开发者ID:tddold,项目名称:Telerik-Academy-Homework-Solutions,代码行数:28,代码来源:Test.cs


示例13: ExpectArgumentExceptionWhenCreateInvalidTriangle

        public void ExpectArgumentExceptionWhenCreateInvalidTriangle()
        {
            var validExceptionsCount = 3;
            var exceptionCount = 0;
            var sideCases = new List<Sides>
            {
                new Sides(1.0, 2.0, 5.0),
                new Sides(-2.0, 4.0, 5.0),
                new Sides(0, 1.0, 2.0)
            };

            foreach (var side in sideCases)
            {
                try
                {
                    var triangle = new Triangle(side.A, side.B, side.C);
                }
                catch (ArgumentException)
                {
                    exceptionCount++;
                }
                catch (Exception ex)
                {
                    Assert.Fail("Возникло не ожидаемое исключение. Детали: {0}", ex.Message);
                }
            }

            Assert.AreEqual(validExceptionsCount, exceptionCount);
        }
开发者ID:Never4GMS,项目名称:Com.Math,代码行数:29,代码来源:TriangleTest.cs


示例14: Main

    /*1.	Define abstract class Shape with only one abstract method CalculateSurface() and fields width and height.
        * Define two new classes Triangle and Rectangle that implement the virtual method and
        * return the surface of the figure (height*width for rectangle and height*width/2 for triangle).
        * Define class Circle and suitable constructor so that
        * on initialization height must be kept equal to width and implement the CalculateSurface() method.
        * Write a program that tests the behavior of  the CalculateSurface() method for different shapes (Circle, Rectangle, Triangle) stored in an array.*/
    static void Main()
    {
        Shape rectangle = new Rectangle(4.0, 5.5);
        Console.WriteLine("Surface of rectangle is: {0}", rectangle.CalculateSurface());

        Shape triangle = new Triangle(4.0, 5.5);
        Console.WriteLine("Surface of triangle is: {0}", triangle.CalculateSurface());

        Shape circle = new Circle(4.5);
        Console.WriteLine("Surface of circle is: {0:F6}", circle.CalculateSurface());

        Console.WriteLine();
        Console.WriteLine("---different shapes---");
        Shape[] shapes = {rectangle,
                            triangle,
                            circle,
                            new Circle(6.3),
                            new Triangle(4.6, 7.3)
                };

        foreach (var shape in shapes)
        {
            Console.WriteLine("Surface of {0} is {1}", shape.GetType(), shape.CalculateSurface());
        }
    }
开发者ID:ralikuman,项目名称:TelerikAcademy,代码行数:31,代码来源:ShapeExample.cs


示例15: TestInterpolatedEmissiveWorldTriangle

        public void TestInterpolatedEmissiveWorldTriangle()
        {
            Triangle triangle = new Triangle( new Point( 0.0f, 0.0f, 3.0f ),
                                              new Point( 1.0f, 0.0f, 3.0f ),
                                              new Point( 1.0f, 1.0f, 3.0f ) );

            BarycentricInterpolatedEmissiveMaterial I = new BarycentricInterpolatedEmissiveMaterial( new Color3( 1.0f, 0.0f, 0.0f ),
                                                                                                     new Color3( 0.0f, 1.0f, 0.0f ),
                                                                                                     new Color3( 0.0f, 0.0f, 1.0f ) );

            SimpleObject so = new SimpleObject( triangle, null, new EmissiveMaterialBase[] { I, I }, null, null, null );

            ListScene scene = new ListScene();
            scene.Add( so );

            Framebuffer fb = new Framebuffer( Color3.Black, 500, 500 );

            Cameras.Pinhole( scene, RenderMethod.RecursiveRayTrace,
                             fb, 0, 0.0001f, 0, 1.0f, true,
                             1.0f, 1.0f, 1.0f,
                             new Point( 0.0f, 0.0f, -2.0f ),
                             new Vector( 0.0f, 0.0f, 1.0f ),
                             new Vector( 0.0f, 1.0f, 0.0f ),
                             1, 1, false );

            Assert.IsTrue( Pfm.Compare( fb, 0.01f, 0.02f, "..\\..\\TestImages\\TestInterpolatedEmissiveWorldTriangle.pfm" ) );
        }
开发者ID:BradleyMarie,项目名称:IrisSharp,代码行数:27,代码来源:RenderingTest.cs


示例16: btnCalculate_Click

        // Button Methods
        private void btnCalculate_Click(object sender, EventArgs e)
        {
            double length;

            // TryParse method must be evaluated first so it can set the length variable
            if (Double.TryParse(txtLength.Text, out length) && length > 0)
            {
                RegularPolygon selectedPolygon;

                // Select child class based on what radio button the user has selected
                if (rbTriangle.Checked)
                {
                    selectedPolygon = new Triangle(length);
                }
                else if (rbSquare.Checked)
                {
                    selectedPolygon = new Square(length);
                }
                else
                {
                    selectedPolygon = new Pentagon(length);
                }

                // Calculate and display the perimeter and area of the regular polygon
                lblCalculatedPerimeter.Text = String.Format("{0}", selectedPolygon.CalculatePerimeter());
                lblCalculatedArea.Text = String.Format("{0}", selectedPolygon.CalculateArea());
            }
            else
            {
                MessageBox.Show("You have entered an invaild length.\nPlease enter a positive numeric value and try agian.", "Invalid Length", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                ClearAllFields();
            }
        }
开发者ID:natemartin519,项目名称:College-Assignments,代码行数:34,代码来源:RegularPolygonCalculator.cs


示例17: isScalenetest

 public void isScalenetest()
 {
     Triangle tri = new Triangle(1.0, 2.0, 3.0);
     Assert.IsTrue(tri.isScalene());
     Assert.IsFalse(tri.isIsosceles());
     Assert.IsFalse(tri.isEquilateral());
 }
开发者ID:TimEmanuelsson,项目名称:VS2012,代码行数:7,代码来源:UnitTest1.cs


示例18: TriangleOver

        public TriangleOver(Triangle t)
        {
            triangles = (float[][])Arrays.CreateJaggedArray(typeof(float), t.GetTriangleCount() * 6 * 3, 2);

            int tcount = 0;
            for (int i = 0; i < t.GetTriangleCount(); i++) {
                float cx = 0;
                float cy = 0;
                for (int p = 0; p < 3; p++) {
                    float[] pt = t.GetTrianglePoint(i, p);
                    cx += pt[0];
                    cy += pt[1];
                }

                cx /= 3;
                cy /= 3;

                for (int p_0 = 0; p_0 < 3; p_0++) {
                    int n = p_0 + 1;
                    if (n > 2) {
                        n = 0;
                    }

                    float[] pt1 = t.GetTrianglePoint(i, p_0);
                    float[] pt2 = t.GetTrianglePoint(i, n);

                    pt1[0] = (pt1[0] + pt2[0]) / 2;
                    pt1[1] = (pt1[1] + pt2[1]) / 2;

                    triangles[(tcount * 3) + 0][0] = cx;
                    triangles[(tcount * 3) + 0][1] = cy;
                    triangles[(tcount * 3) + 1][0] = pt1[0];
                    triangles[(tcount * 3) + 1][1] = pt1[1];
                    triangles[(tcount * 3) + 2][0] = pt2[0];
                    triangles[(tcount * 3) + 2][1] = pt2[1];
                    tcount++;
                }

                for (int p_1 = 0; p_1 < 3; p_1++) {
                    int n_2 = p_1 + 1;
                    if (n_2 > 2) {
                        n_2 = 0;
                    }

                    float[] pt1_3 = t.GetTrianglePoint(i, p_1);
                    float[] pt2_4 = t.GetTrianglePoint(i, n_2);

                    pt2_4[0] = (pt1_3[0] + pt2_4[0]) / 2;
                    pt2_4[1] = (pt1_3[1] + pt2_4[1]) / 2;

                    triangles[(tcount * 3) + 0][0] = cx;
                    triangles[(tcount * 3) + 0][1] = cy;
                    triangles[(tcount * 3) + 1][0] = pt1_3[0];
                    triangles[(tcount * 3) + 1][1] = pt1_3[1];
                    triangles[(tcount * 3) + 2][0] = pt2_4[0];
                    triangles[(tcount * 3) + 2][1] = pt2_4[1];
                    tcount++;
                }
            }
        }
开发者ID:hellogithubtesting,项目名称:LGame,代码行数:60,代码来源:TriangleOver.cs


示例19: Optimized_Heightmap

        /// <summary>
        /// Optimized Heightmap, using cells to optimize process of drawing and modifying.
        /// The heightmap is divided into cells which are each surrounded by a bounding box and
        /// hidden if they are outside of the field of view or too far away. The bounding boxes 
        /// are also used to speed up the ray detection test when making modifications to the terrain.
        /// </summary>
        /// <param name="divisions">Size of the map, ex: 256x256</param>
        /// <param name="cellsize">The size of a single quad, ex: 50x50</param>
        /// <param name="cellDivisions">Number of quads in each heightmap cell, ex: 16x16</param>
        public Optimized_Heightmap(GraphicsDevice graphicsDevice, Point divisions, Vector2 cellsize, Point cellDivisions)
        {
            this.size = divisions;
            this.cellSize = cellsize;
            this.cellDivisions = cellDivisions;

            //basicEffect = new BasicEffect(graphicsDevice, null);
            //basicEffect.VertexColorEnabled = true;
            effect = Editor.content.Load<Effect>(@"content\shaders\opt_heightmap");
            effectParams = new EffectParams(ref effect, "TransformWireframe");

            int w = (int)((float)divisions.X / (float)cellDivisions.X);
            int h = (int)((float)divisions.Y / (float)cellDivisions.Y);

            cell = new HeightmapCell[w, h];

            //Build the cells
            for (int y = 0; y < w; y++)
            {
                for (int x = 0; x < h; x++)
                {
                    //get the adjacent cells (max 3) : [0,0],[0,1],[1,0]
                    HeightmapCell[,] adjacent_cell = new HeightmapCell[2, 2];
                    if (x > 0) adjacent_cell[0, 1] = cell[x - 1, y];
                    if (y > 0) adjacent_cell[1, 0] = cell[x, y - 1];
                    if (x > 0 && y > 0) adjacent_cell[0, 0] = cell[x - 1, y - 1];

                    cell[x, y] = new HeightmapCell(graphicsDevice, new Point(x, y), cellDivisions, cellsize, adjacent_cell);
                }
            }

            HeightmapCell.Tri collisionTri = cell[0,0].triangle[0];
            testTri = new Triangle(collisionTri.p1, collisionTri.p2, collisionTri.p3, Color.White);
        }
开发者ID:GodLesZ,项目名称:svn-dump,代码行数:43,代码来源:Optimized_Heightmap.cs


示例20: clip

    public static List<List<Vector2>> clip(List<Vector2> boundary, Triangle piece)
    {
        //create Boundary Polygon
        Polygons boundaryPoly = createPolygons(boundary);

        //create Polygon from the triangular piece
        Polygons subjPoly = createPolygons(piece);

        //clip triangular polygon against the boundary polygon
        Polygons result = new Polygons();
        Clipper c = new Clipper();
        c.AddPaths(subjPoly, PolyType.ptClip, true);
        c.AddPaths(boundaryPoly, PolyType.ptSubject, true);
        c.Execute(ClipType.ctIntersection, result, PolyFillType.pftEvenOdd, PolyFillType.pftEvenOdd);

        List<List<Vector2>> clippedPolygons = new List<List<Vector2>>();

        foreach (Polygon poly in result)
        {
            List<Vector2> clippedPoly = new List<Vector2>();
            foreach (IntPoint p in poly)
            {
                clippedPoly.Add(new Vector2(p.X, p.Y) / multiplier);
            }
            clippedPolygons.Add(clippedPoly);

        }
        return clippedPolygons;
        
    }
开发者ID:Cyberbanan,项目名称:Unity-2D-Destruction,代码行数:30,代码来源:ClipperHelper.cs



注:本文中的Triangle类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# TriangulationPoint类代码示例发布时间:2022-05-24
下一篇:
C# TrendChart类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap