Exemple #1
0
        //Test if we should flip an edge
        //a, b, c belongs to the triangle and d is the point on the other triangle
        //a-c is the edge, which is important so we can flip it, by making the edge b-d
        public static bool ShouldFlipEdge(MyVector2 a, MyVector2 b, MyVector2 c, MyVector2 d)
        {
            bool shouldFlipEdge = false;

            //Use the circle test to test if we need to flip this edge
            //We should flip if d is inside a circle formed by a, b, c
            IntersectionCases intersectionCases = _Intersections.PointCircle(a, b, c, d);

            if (intersectionCases == IntersectionCases.IsInside)
            {
                //Are these the two triangles forming a convex quadrilateral? Otherwise the edge cant be flipped
                if (_Geometry.IsQuadrilateralConvex(a, b, c, d))
                {
                    //If the new triangle after a flip is not better, then dont flip
                    //This will also stop the algorithm from ending up in an endless loop
                    IntersectionCases intersectionCases2 = _Intersections.PointCircle(b, c, d, a);

                    if (intersectionCases2 == IntersectionCases.IsOnEdge || intersectionCases2 == IntersectionCases.IsInside)
                    {
                        shouldFlipEdge = false;
                    }
                    else
                    {
                        shouldFlipEdge = true;
                    }
                }
            }

            return(shouldFlipEdge);
        }
Exemple #2
0
    //Is a point intersecting with a circle?
    private void PointCircle()
    {
        MyVector2 testPoint = pointTrans.position.ToMyVector2();

        MyVector2 circlePointA = t1_p1_trans.position.ToMyVector2();
        MyVector2 circlePointB = t1_p2_trans.position.ToMyVector2();
        MyVector2 circlePointC = t1_p3_trans.position.ToMyVector2();

        //Is a point in a circle determines by three other points
        IntersectionCases intersectionCases = _Intersections.PointCircle(circlePointA, circlePointB, circlePointC, testPoint);

        //print(isPointInCircle);


        //Display the circle
        //if (intersectionCases == IntersectionCases.NoIntersection)
        //{
        //    Gizmos.color = Color.white;
        //}
        //if (intersectionCases == IntersectionCases.IsInside)
        //{
        //    Gizmos.color = Color.red;
        //}
        //if (intersectionCases == IntersectionCases.IsOnEdge)
        //{
        //    Gizmos.color = Color.blue;
        //}


        MyVector2 centerOfCicle = _Geometry.CalculateCircleCenter(circlePointA, circlePointB, circlePointC);

        float radius = MyVector2.Distance(centerOfCicle, circlePointA);

        //Gizmos.DrawWireSphere(centerOfCicle.ToVector3(), radius);

        ////Display the points
        //float pointRadius = 0.2f;

        //Gizmos.DrawWireSphere(pointTrans.position, pointRadius);

        //Gizmos.DrawWireSphere(t1_p1_trans.position, pointRadius);
        //Gizmos.DrawWireSphere(t1_p2_trans.position, pointRadius);
        //Gizmos.DrawWireSphere(t1_p3_trans.position, pointRadius);


        //With mesh
        //Big circle
        TestAlgorithmsHelpMethods.DisplayCircleMesh(centerOfCicle, radius, 60, Color.white);

        //Small circle
        Color circleColor = (intersectionCases == IntersectionCases.IsInside) ? Color.red : Color.white;

        TestAlgorithmsHelpMethods.DisplayCircleMesh(testPoint, 1f, 20, circleColor);
    }