Ejemplo n.º 1
0
    //Is a line intersecting with a plane?
    private void LinePlane()
    {
        Vector3 planeNormal = planeTrans.forward;

        Vector3 planePos = planeTrans.position;

        Vector3 line_p1 = t1_p1_trans.position;

        Vector3 line_p2 = t1_p2_trans.position;


        //2d space
        MyVector2 planeNormal_2d = planeNormal.ToMyVector2();

        MyVector2 planePos_2d = planePos.ToMyVector2();

        MyVector2 line_p1_2d = line_p1.ToMyVector2();

        MyVector2 line_p2_2d = line_p2.ToMyVector2();


        bool isIntersecting = _Intersections.LinePlane(planePos_2d, planeNormal_2d, line_p1_2d, line_p2_2d);


        //Debug
        //TestAlgorithmsHelpMethods.DrawPlane(planePos_2d, planeNormal_2d, Color.blue);

        ////Line
        //Gizmos.color = Color.white;

        //Gizmos.DrawWireSphere(line_p1, 0.1f);
        //Gizmos.DrawWireSphere(line_p2, 0.1f);

        //if (isIntersecting)
        //{
        //    Gizmos.color = Color.red;

        //    MyVector2 intersectionPoint = Intersections.GetLinePlaneIntersectionPoint(planePos_2d, planeNormal_2d, line_p1_2d, line_p2_2d);

        //    Gizmos.DrawWireSphere(intersectionPoint.ToVector3(), 0.2f);
        //}

        //Gizmos.DrawLine(line_p1, line_p2);


        //Display with mesh
        //Plane
        TestAlgorithmsHelpMethods.DisplayPlaneMesh(planePos_2d, planeNormal_2d, 0.5f, Color.blue);

        //Line
        TestAlgorithmsHelpMethods.DisplayLineMesh(line_p1_2d, line_p2_2d, 0.5f, Color.white);

        if (isIntersecting)
        {
            MyVector2 intersectionPoint = _Intersections.GetLinePlaneIntersectionPoint(planePos_2d, planeNormal_2d, line_p1_2d, line_p2_2d);

            TestAlgorithmsHelpMethods.DisplayCircleMesh(intersectionPoint, 1f, 20, Color.red);
        }
    }
    //Is a plane intersecting with a plane
    private void PlanePlane()
    {
        Vector3 planeNormal_1 = planeTrans.forward;

        Vector3 planePos_1 = planeTrans.position;

        Vector3 planeNormal_2 = rayTrans.forward;

        Vector3 planePos_2 = rayTrans.position;

        //3d to 2d
        MyVector2 normal_1 = planeNormal_1.ToMyVector2();
        MyVector2 normal_2 = planeNormal_2.ToMyVector2();

        MyVector2 pos1 = planePos_1.ToMyVector2();
        MyVector2 pos2 = planePos_2.ToMyVector2();

        Plane2 plane_1 = new Plane2(pos1, normal_1);
        Plane2 plane_2 = new Plane2(pos2, normal_2);

        //Intersections
        bool isIntersecting = _Intersections.PlanePlane(plane_1, plane_2);

        Debug.Log("Are planes intersecting: " + isIntersecting);


        //Display
        //if (isIntersecting)
        //{
        //    MyVector2 intersectionPoint = Intersections.GetPlanePlaneIntersectionPoint(pos1, normal_1, pos2, normal_2);

        //    Gizmos.DrawWireSphere(intersectionPoint.ToVector3(), 0.2f);
        //}

        //Color planeColor = isIntersecting ? Color.red : Color.white;

        //TestAlgorithmsHelpMethods.DrawPlane(pos1, normal_1, planeColor);
        //TestAlgorithmsHelpMethods.DrawPlane(pos2, normal_2, planeColor);



        //Display with mesh
        TestAlgorithmsHelpMethods.DisplayPlaneMesh(pos1, normal_1, 0.5f, Color.blue);
        TestAlgorithmsHelpMethods.DisplayPlaneMesh(pos2, normal_2, 0.5f, Color.blue);

        if (isIntersecting)
        {
            MyVector2 intersectionPoint = _Intersections.GetPlanePlaneIntersectionPoint(plane_1, plane_2);

            TestAlgorithmsHelpMethods.DisplayCircleMesh(intersectionPoint, 1f, 20, Color.red);
        }
    }
Ejemplo n.º 3
0
    //Is a ray intersecting with a plane?
    private void RayPlane()
    {
        Vector3 planeNormal = planeTrans.forward;

        Vector3 planePos = planeTrans.position;

        Vector3 rayPos = rayTrans.position;

        Vector3 rayDir = rayTrans.forward;


        //2d space
        MyVector2 planeNormal_2d = planeNormal.ToMyVector2();

        MyVector2 planePos_2d = planePos.ToMyVector2();

        MyVector2 rayPos_2d = rayPos.ToMyVector2();

        MyVector2 rayDir_2d = rayDir.ToMyVector2();


        //Might as well test the distance from the point to the plane as well
        float distance = _Geometry.DistanceFromPointToPlane(planeNormal_2d, planePos_2d, rayPos_2d);

        Debug.Log(distance);

        bool isIntersecting = _Intersections.RayPlane(planePos_2d, planeNormal_2d, rayPos_2d, rayDir_2d);


        //Debug
        Gizmos.color = Color.blue;

        TestAlgorithmsHelpMethods.DrawPlane(planePos_2d, planeNormal_2d, Color.blue);


        //Ray
        //Gizmos.color = Color.white;

        //Gizmos.DrawWireSphere(rayPos, 0.1f);

        //if (isIntersecting)
        //{
        //    Gizmos.color = Color.red;

        //    MyVector2 intersectionPoint = Intersections.GetRayPlaneIntersectionPoint(planePos_2d, planeNormal_2d, rayPos_2d, rayDir_2d);

        //    Gizmos.DrawWireSphere(intersectionPoint.ToVector3(), 0.2f);
        //}

        //Gizmos.DrawRay(rayPos, rayDir * 100f);



        //Display with mesh
        //Plane
        TestAlgorithmsHelpMethods.DisplayPlaneMesh(planePos_2d, planeNormal_2d, 0.5f, Color.blue);

        //Ray
        TestAlgorithmsHelpMethods.DisplayArrowMesh(rayPos_2d, rayPos_2d + rayDir_2d * 6f, 0.5f, 0.5f + 0.5f, Color.white);

        if (isIntersecting)
        {
            MyVector2 intersectionPoint = _Intersections.GetRayPlaneIntersectionPoint(planePos_2d, planeNormal_2d, rayPos_2d, rayDir_2d);

            TestAlgorithmsHelpMethods.DisplayCircleMesh(intersectionPoint, 1f, 20, Color.red);
        }
    }