Example #1
0
        public static Circle2D GetCircumscribedCircle(Triangle2D triangle)
        {
            var x1 = triangle.a.Coordinate.x;
            var y1 = triangle.a.Coordinate.y;
            var x2 = triangle.b.Coordinate.x;
            var y2 = triangle.b.Coordinate.y;
            var x3 = triangle.c.Coordinate.x;
            var y3 = triangle.c.Coordinate.y;

            float x1_2 = x1 * x1;
            float x2_2 = x2 * x2;
            float x3_2 = x3 * x3;
            float y1_2 = y1 * y1;
            float y2_2 = y2 * y2;
            float y3_2 = y3 * y3;

            // 外接円の中心座標を計算
            float c  = 2f * ((x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1));
            float x  = ((y3 - y1) * (x2_2 - x1_2 + y2_2 - y1_2) + (y1 - y2) * (x3_2 - x1_2 + y3_2 - y1_2)) / c;
            float y  = ((x1 - x3) * (x2_2 - x1_2 + y2_2 - y1_2) + (x2 - x1) * (x3_2 - x1_2 + y3_2 - y1_2)) / c;
            float _x = (x1 - x);
            float _y = (y1 - y);

            float r = Mathf.Sqrt((_x * _x) + (_y * _y));

            return(new Circle2D(new Vector2(x, y), r));
        }
Example #2
0
 bool ExternalPSLG(Triangle2D t)
 {
     // return ExternalPSLG(t.s0) && ExternalPSLG(t.s1) && ExternalPSLG(t.s2);
     return
         (ExternalPSLG(t.a.Coordinate) ||
          ExternalPSLG(t.b.Coordinate) ||
          ExternalPSLG(t.c.Coordinate)
         );
 }
Example #3
0
        public Triangle2D AddTriangle(Vertex2D a, Vertex2D b, Vertex2D c)
        {
            var s0 = CheckAndAddSegment(a, b);
            var s1 = CheckAndAddSegment(b, c);
            var s2 = CheckAndAddSegment(c, a);
            var t  = new Triangle2D(s0, s1, s2);

            T.Add(t);
            return(t);
        }
Example #4
0
 void RemoveCommonTriangles(Triangle2D target)
 {
     for (int i = 0, n = T.Count; i < n; i++)
     {
         var t = T[i];
         if (t.HasCommonPoint(target))
         {
             RemoveTriangle(t);
             i--;
             n--;
         }
     }
 }
Example #5
0
 bool HasOuterSegments(Triangle2D t)
 {
     if (!ContainsSegments(t.s0, S))
     {
         return(ExternalPSLG(t.s0));
     }
     if (!ContainsSegments(t.s1, S))
     {
         return(ExternalPSLG(t.s1));
     }
     if (!ContainsSegments(t.s2, S))
     {
         return(ExternalPSLG(t.s2));
     }
     return(false);
 }
 void RemoveTriangle(Triangle2D t)
 {
     T.Remove(t);
     if (t.s0.Decrement() <= 0)
     {
         RemoveSegment(t.s0);
     }
     if (t.s1.Decrement() <= 0)
     {
         RemoveSegment(t.s1);
     }
     if (t.s2.Decrement() <= 0)
     {
         RemoveSegment(t.s2);
     }
 }
Example #7
0
        public static bool CheckEqual(Triangle2D t0, Triangle2D t1)
        {
            // 0,1,2 == 0,1,2
            // 0,1,2 == 0,2,1
            // 0,1,2 == 1,0,2
            // 0,1,2 == 1,2,0
            // 0,1,2 == 2,0,1
            // 0,1,2 == 2,1,0
            return
                ((CheckEqual(t0.s0, t1.s0) && CheckEqual(t0.s1, t1.s1) && CheckEqual(t0.s2, t1.s2)) ||
                 (CheckEqual(t0.s0, t1.s0) && CheckEqual(t0.s1, t1.s2) && CheckEqual(t0.s2, t1.s1)) ||

                 (CheckEqual(t0.s0, t1.s1) && CheckEqual(t0.s1, t1.s0) && CheckEqual(t0.s2, t1.s2)) ||
                 (CheckEqual(t0.s0, t1.s1) && CheckEqual(t0.s1, t1.s2) && CheckEqual(t0.s2, t1.s0)) ||

                 (CheckEqual(t0.s0, t1.s2) && CheckEqual(t0.s1, t1.s0) && CheckEqual(t0.s2, t1.s1)) ||
                 (CheckEqual(t0.s0, t1.s2) && CheckEqual(t0.s1, t1.s1) && CheckEqual(t0.s2, t1.s0)));
        }
Example #8
0
        public void RemoveTriangle(Triangle2D t)
        {
            var idx = T.IndexOf(t);

            if (idx < 0)
            {
                return;
            }

            T.RemoveAt(idx);
            if (t.s0.Decrement() <= 0)
            {
                RemoveSegment(t.s0);
            }
            if (t.s1.Decrement() <= 0)
            {
                RemoveSegment(t.s1);
            }
            if (t.s2.Decrement() <= 0)
            {
                RemoveSegment(t.s2);
            }
        }
 public bool HasCommonPoint(Triangle2D t)
 {
     return(HasPoint(t.a) || HasPoint(t.b) || HasPoint(t.c));
 }
 public bool Equals(Triangle2D t)
 {
     return(HasPoint(t.a) && HasPoint(t.b) && HasPoint(t.c));
 }
Example #11
0
        void SplitTriangle(Triangle2D t)
        {
            var c = t.Circumcenter();

            UpdateTriangulation(c);
        }