示例#1
0
    //Is a triangle intersecting with a triangle?
    private void TriangleTriangle()
    {
        //3d to 2d
        Triangle2 t1 = new Triangle2(
            t1_p1_trans.transform.position.ToMyVector2(),
            t1_p2_trans.transform.position.ToMyVector2(),
            t1_p3_trans.transform.position.ToMyVector2());

        Triangle2 t2 = new Triangle2(
            t2_p1_trans.transform.position.ToMyVector2(),
            t2_p2_trans.transform.position.ToMyVector2(),
            t2_p3_trans.transform.position.ToMyVector2());

        bool isIntersecting = _Intersections.TriangleTriangle2D(t1, t2, do_AABB_test: false);



        //Display
        //Color color = isIntersecting ? Color.red : Color.white;

        //TestAlgorithmsHelpMethods.DisplayTriangle(t1.p1.ToVector3(), t1.p2.ToVector3(), t1.p3.ToVector3(), color);
        //TestAlgorithmsHelpMethods.DisplayTriangle(t2.p1.ToVector3(), t2.p2.ToVector3(), t2.p3.ToVector3(), color);


        //With mesh to better see what's going on
        TestAlgorithmsHelpMethods.DisplayTriangleMesh(t1.p1, t1.p2, t1.p3, Color.white);

        Color meshColor = isIntersecting ? Color.red : Color.white;

        TestAlgorithmsHelpMethods.DisplayTriangleMesh(t2.p1, t2.p2, t2.p3, meshColor);
    }
示例#2
0
    //Is a point intersecting with a triangle?
    private void PointTriangle()
    {
        MyVector2 p = pointTrans.position.ToMyVector2();

        MyVector2 t_p1 = t1_p1_trans.position.ToMyVector2();
        MyVector2 t_p2 = t1_p2_trans.position.ToMyVector2();
        MyVector2 t_p3 = t1_p3_trans.position.ToMyVector2();

        Triangle2 t = new Triangle2(t_p1, t_p2, t_p3);

        bool isIntersecting = _Intersections.PointTriangle(t, p, includeBorder: true);

        //Display
        //Gizmos.color = isIntersecting ? Color.red : Color.white;

        //Gizmos.DrawWireSphere(p.ToVector3(), 0.1f);

        //Gizmos.DrawLine(t.p1.ToVector3(), t.p2.ToVector3());
        //Gizmos.DrawLine(t.p2.ToVector3(), t.p3.ToVector3());
        //Gizmos.DrawLine(t.p3.ToVector3(), t.p1.ToVector3());


        //With mesh to better see what's going on
        //Triangle
        TestAlgorithmsHelpMethods.DisplayTriangleMesh(t_p1, t_p2, t_p3, Color.white);

        //Point
        Color pointColor = isIntersecting ? Color.red : Color.white;

        TestAlgorithmsHelpMethods.DisplayCircleMesh(p, 1f, 20, pointColor);
    }