public void TestWindingOrder_Colinear()
        {
            Vector3 a = new Vector3(+0.1f, +1.4f, -0.4f);
            Vector3 b = new Vector3(+0.2f, +2.8f, -0.8f);
            Vector3 c = new Vector3(-0.2f, -2.8f, +0.8f);


            TriangleUtils.WindingOrder actual   = TriangleUtils.DetermineWindingOrder(a, b, c);
            TriangleUtils.WindingOrder expected = TriangleUtils.WindingOrder.Colinear;

            Assert.AreEqual(expected, actual);
        }
        public void TestWindingOrder_CCW()
        {
            Vector3 a = new Vector3(+0.1f, +1.4f, -0.4f);
            Vector3 b = new Vector3(-0.1f, +1.4f, -0.5f);
            Vector3 c = new Vector3(-0.1f, +1.1f, -0.1f);


            TriangleUtils.WindingOrder actual   = TriangleUtils.DetermineWindingOrder(a, b, c);
            TriangleUtils.WindingOrder expected = TriangleUtils.WindingOrder.CounterClockWise;

            Assert.AreEqual(expected, actual);
        }
Пример #3
0
        public void TestEqualSideCountBadInput()
        {
            var sides = new double[] { -1, 2 };

            try
            {
                TriangleUtils.EqualSideCount(sides);
                Assert.True(false, "Exception not thrown");
            }
            catch (ArgumentException)
            {
                //Test pass
            }
        }
Пример #4
0
        public void TestIsEquilateralBadInput()
        {
            var sides = new double[] { -1, 4 };

            try
            {
                TriangleUtils.IsEquilateral(sides);
                Assert.True(false, "Exception not thrown");
            }
            catch (ArgumentException)
            {
                //Test pass
            }
        }
Пример #5
0
        static void Main(string[] args)
        {
            double a, b, c;

            a = SetPoint("Введите точку а: ");
            b = SetPoint("Введите точку b: ");
            c = SetPoint("Введите точку c: ");

            TriangleUtils utils = new TriangleUtils();

            TriangleUtils.TriangleType type = utils.GetTriangleType(a, b, c);

            Console.WriteLine("Тип треугольника: " + type);
            Console.ReadKey();
        }
Пример #6
0
        private void SubmitBTN_Click(object sender, EventArgs e)
        {
            try
            {
                List <Triangle> triangles = TriangleUtils.PointArrayToTriangles(DataGridViewUtils.GridToArray2 <int>(InputDGV));
                TriangleUtils   utils     = new TriangleUtils(triangles);

                utils.GetAnswer(out int[][] result);
                OutLB.Items.Clear();
                for (int i = 0; i < result.Length; i++)
                {
                    OutLB.Items.Add(new ArraysHelper().ArrayToStr <int>(result[i], "; ") + "\n");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #7
0
        static void Main(string[] args)
        {
            // Запускаем основной цикл приложения
            while (true)
            {
                int[,] trianglesPointsArray = StartProgram("Длина массива 6. Координаты точек вводятся в виде [X1 Y1 X2 Y2 X3 Y3]");

                TriangleUtils triangleUtils = new TriangleUtils(TriangleUtils.PointArrayToTriangles(trianglesPointsArray));

                triangleUtils.GetAnswer(out int[][] resultArr);
                string result = String.Empty;

                for (int i = 0; i < resultArr.Length; i++)
                {
                    result += new ArraysHelper().ArrayToStr <int>(resultArr[i], "; ") + "\n";
                }

                Console.WriteLine(result);

                // Спрашиваем у пользователя, желает ли он также сохранить
                // резульат работы программы в файл
                if (ConfirmAction("Желаете ли вы сохранить резултат работы программы в файл?"))
                {
                    SaveResultToFile(result);
                }

                // Спрашиваем, будет ли пользователь продолжать работу с программой
                if (ConfirmAction("Продолжить работу с программой?"))
                {
                    Console.Clear();
                }
                else
                {
                    break;
                }
            }
        }
Пример #8
0
        public void ComputeVertexMatricesForTriangles()
        {
            var triangles = TriangleList;
            var vertices  = VertexList;

            FourthVertexForTriangle = new Vector3[NumberOfTriangles];

            for (int i = 0; i < NumberOfTriangles; i++)
            {
                int v1 = triangles[i * 3 + 0];
                int v2 = triangles[i * 3 + 1];
                int v3 = triangles[i * 3 + 2];

                FourthVertexForTriangle[i] = TriangleUtils.CalculateFourthVertex(vertices[v1], vertices[v2], vertices[v3]);

                var vertexMat = TriangleUtils.CreateTriangleMatrix(vertices[v1], vertices[v2], vertices[v3]);

                VertexMatrices.Add(vertexMat);
                InverseVertexMatrices.Add(vertexMat.Inverse());

                Debug.Log("Matrix for Tri #" + i + " : " + vertexMat.ToString());
                Debug.Log("Inverse Matrix for Tri #" + i + " : " + InverseVertexMatrices[i].ToString());
            }
        }
Пример #9
0
        public void TestEqualSideCount1()
        {
            var sides = new double[] { 4, 2, 3 };

            Assert.Equal(0, TriangleUtils.EqualSideCount(sides));
        }
Пример #10
0
        static void Main(string[] args)
        {
            var sides = new double[3];

            Console.WriteLine("Enter 3 sides:");
            Console.Write("A: ");
            while (!Double.TryParse(Console.ReadLine(), out sides[0]))
            {
                Console.WriteLine("Invalid input");
                Console.Write("A: ");
            }
            Console.Write("B: ");
            while (!Double.TryParse(Console.ReadLine(), out sides[1]))
            {
                Console.WriteLine("Invalid input");
                Console.Write("B: ");
            }
            Console.Write("C: ");
            while (!Double.TryParse(Console.ReadLine(), out sides[2]))
            {
                Console.WriteLine("Invalid input");
                Console.Write("C: ");
            }
            try
            {
                if (TriangleUtils.IsTriangle(sides))
                {
                    Console.WriteLine($"There exists a triangle with sides: {sides[0]} {sides[1]} {sides[2]}.");
                }
                else
                {
                    Console.WriteLine($"There is no triangle with sides: {sides[0]} {sides[1]} {sides[2]}.");
                    Console.ReadKey();
                    return;
                }
                if (TriangleUtils.IsEquilateral(sides))
                {
                    Console.WriteLine("Triangle is equilateral.");
                }
                else if (TriangleUtils.IsRightAngled(sides))
                {
                    Console.WriteLine("Triangle is right-angled.");
                }
                else if (TriangleUtils.IsSharpAngled(sides))
                {
                    Console.WriteLine("Triangle is sharp-angled.");
                }
                else
                {
                    Console.WriteLine("Triangle is blunt-angled.");
                }
                Console.WriteLine($"Triangle has {TriangleUtils.EqualSideCount(sides)} equal sides.");
            } catch (ArgumentException e)
            {
                Console.WriteLine("Invalid input");
                Console.WriteLine(e.Message);
                Console.ReadKey();
                return;
            }
            Console.ReadKey();
        }
Пример #11
0
        public void TestIsTriangleTrue()
        {
            var sides = new double[] { 3, 4, 5 };

            Assert.True(TriangleUtils.IsTriangle(sides));
        }
Пример #12
0
        public void TestIsEquilateralFalse()
        {
            var sides = new double[] { 2, 2, 3 };

            Assert.False(TriangleUtils.IsEquilateral(sides));
        }
Пример #13
0
        public void TestIsEquilateralTrue()
        {
            var sides = new double[] { 3, 3, 3 };

            Assert.True(TriangleUtils.IsEquilateral(sides));
        }
Пример #14
0
        public void TestIsRightAngledFalse()
        {
            var sides = new double[] { 3, 4, 6 };

            Assert.False(TriangleUtils.IsRightAngled(sides));
        }
Пример #15
0
        public void TestIsBluntAngledTrue()
        {
            var sides = new double[] { 10, 10, 19 };

            Assert.True(TriangleUtils.IsBluntAngled(sides));
        }
Пример #16
0
        public void TestIsSharpAngledFalse()
        {
            var sides = new double[] { 10, 10, 19 };

            Assert.False(TriangleUtils.IsSharpAngled(sides));
        }
Пример #17
0
        public void TestIsSharpAngledTrue()
        {
            var sides = new double[] { 4, 4, 3 };

            Assert.True(TriangleUtils.IsSharpAngled(sides));
        }
Пример #18
0
        public void TestIsTriangleFalse()
        {
            var sides = new double[] { 1, 2, 5 };

            Assert.False(TriangleUtils.IsTriangle(sides));
        }
Пример #19
0
        public void TestIsBluntAngledFalse()
        {
            var sides = new double[] { 4, 4, 3 };

            Assert.False(TriangleUtils.IsBluntAngled(sides));
        }
        public void CalculateTriangleMatrices(int index)
        {
            var A = srcMesh.matricesForTriangle[index].A;
            var C = srcMesh.matricesForTriangle[index].C;

            var   inverseMat = srcMesh.InverseVertexMatrices[index];
            var   coefv1     = TriangleUtils.CalculateCoefficientV1(srcMesh.InverseVertexMatrices[index]);
            float coef       = 0;

            int v1 = index * 3 + 0;
            int v2 = index * 3 + 1;
            int v3 = index * 3 + 2;

            for (int i = 0, row = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++, row++)
                {
                    C[row] = 0;

                    /* coefficient of v1: -(a[0,i] + a[1,i] + a[2,i]) */
                    coef = coefv1[j];

                    if (!vertexConstraintList.ContainsKey(srcMesh.TriangleList[v1]))
                    {
                        A[row, 0] = coef;
                    }
                    else
                    {
                        var tgtVertIdx = vertexConstraintList[srcMesh.TriangleList[v1]];
                        C[row] -= coef * tgtMesh.VertexList[tgtVertIdx][i];
                    }


                    /* coefficient of v2: a[0,i]*/
                    coef = inverseMat[0, j];
                    if (!vertexConstraintList.ContainsKey(srcMesh.TriangleList[v2]))
                    {
                        A[row, 1] = coef;
                    }
                    else
                    {
                        var tgtVertIdx = vertexConstraintList[srcMesh.TriangleList[v2]];
                        C[row] -= coef * tgtMesh.VertexList[tgtVertIdx][i];
                    }

                    /* coefficient of v3: a[1,i] */
                    coef = inverseMat[1, j];
                    if (!vertexConstraintList.ContainsKey(srcMesh.TriangleList[v3]))
                    {
                        A[row, 2] = coef;
                    }
                    else
                    {
                        var tgtVertIdx = vertexConstraintList[srcMesh.TriangleList[v3]];
                        C[row] -= coef * tgtMesh.VertexList[tgtVertIdx][i];
                    }

                    /* coefficient of v4: a[2,i] */
                    A[row, 3] = inverseMat[2, j];
                }
            }
        }
Пример #21
0
        public void TestEqualSideCount3()
        {
            var sides = new double[] { 4, 4, 4 };

            Assert.Equal(3, TriangleUtils.EqualSideCount(sides));
        }