예제 #1
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);
    }