示例#1
0
    /*
    // Update is called once per frame
    void Update()
    {
        update_flag = 1;

        Rx_MPC1 = Rx_Seen_MPC_Script.seen_MPC1;
        Rx_MPC2 = Rx_Seen_MPC_Script.seen_MPC2;
        Rx_MPC3 = Rx_Seen_MPC_Script.seen_MPC3;

        Tx_MPC1 = Tx_Seen_MPC_Script.seen_MPC1;
        Tx_MPC2 = Tx_Seen_MPC_Script.seen_MPC2;
        Tx_MPC3 = Tx_Seen_MPC_Script.seen_MPC3;


    }
    */

    private void FixedUpdate()
    {
        Rx_MPC1 = Rx_Seen_MPC_Script.seen_MPC1;
        Rx_MPC2 = Rx_Seen_MPC_Script.seen_MPC2;
        Rx_MPC3 = Rx_Seen_MPC_Script.seen_MPC3;

        Tx_MPC1 = Tx_Seen_MPC_Script.seen_MPC1;
        Tx_MPC2 = Tx_Seen_MPC_Script.seen_MPC2;
        Tx_MPC3 = Tx_Seen_MPC_Script.seen_MPC3;



        ///////////////////////////////////////////////////////////////////////////////////
        /// LOS
        ///////////////////////////////////////////////////////////////////////////////////
        // float startTime = Time.realtimeSinceStartup;
        if (!Physics.Linecast(Tx.transform.position, Rx.transform.position))
        {
            float LOS_distance = (Tx.transform.position - Rx.transform.position).magnitude;
            if (LOS_Tracer)
            {
                Debug.DrawLine(Tx.transform.position, Rx.transform.position, Color.magenta);
            }
        }
        // Debug.Log(((Time.realtimeSinceStartup - startTime) * 1000000f) + "microsec");
        ///////////////////////////////////////////////////////////////////////////////////
        /// MPC1
        ///////////////////////////////////////////////////////////////////////////////////
        List<int> common_mpc1 = new List<int>();

        CommonMPC1(Rx_MPC1, Tx_MPC1, out common_mpc1);

        List<int> active_MPC1 = new List<int>();
        for (int i = 0; i < common_mpc1.Count; i++)

        {
            // defining peprendicular to the considered normal that is parallel to the ground. 
            Vector3 n_perp = new Vector3(-MPC1[common_mpc1[i]].Normal.z, 0, MPC1[common_mpc1[i]].Normal.x);
            float rx_distance = (Rx.transform.position - MPC1[common_mpc1[i]].Coordinates).magnitude;
            float tx_distance = (Rx.transform.position - MPC1[common_mpc1[i]].Coordinates).magnitude;
            Vector3 rx_direction = (Rx.transform.position - MPC1[common_mpc1[i]].Coordinates).normalized;
            Vector3 tx_direction = (Tx.transform.position - MPC1[common_mpc1[i]].Coordinates).normalized;

            if ((Vector3.Dot(n_perp, rx_direction) * Vector3.Dot(n_perp, tx_direction)) < 0)
            {
                active_MPC1.Add(common_mpc1[i]);
                if (MPC1_Tracer)
                {
                    Debug.DrawLine(Rx.transform.position, MPC1[common_mpc1[i]].Coordinates, Color.red);
                    Debug.DrawLine(Tx.transform.position, MPC1[common_mpc1[i]].Coordinates, Color.blue);
                }
            }
        }




        ///////////////////////////////////////////////////////////////////////////////////
        /// MPC2
        ///////////////////////////////////////////////////////////////////////////////////
        List<Path2> second_order_paths = new List<Path2>();

        int brute_force = 1;
        for (int i = 0; i < Rx_MPC2.Count; i++)
        {
            List<GeoComp> temp_list = new List<GeoComp>();
            if (brute_force == 1)
            {
                temp_list = GlobeCom2[Rx_MPC2[i]];
            }
            else
            {
                for (int j = 0; j < MPC2.Count; j++)
                {
                    float dist_xxx = (MPC2[j].Coordinates - MPC2[Rx_MPC2[i]].Coordinates).magnitude;
                    if (dist_xxx < 70)
                    {
                        if (!Physics.Linecast(MPC2[j].Coordinates, MPC2[Rx_MPC2[i]].Coordinates))
                        {
                            float aod = Mathf.Acos(Vector3.Dot((MPC2[j].Coordinates - MPC2[Rx_MPC2[i]].Coordinates).normalized, MPC2[j].Normal));
                            float aoa = Mathf.Acos(-Vector3.Dot((MPC2[j].Coordinates - MPC2[Rx_MPC2[i]].Coordinates).normalized, MPC2[Rx_MPC2[i]].Normal));
                            GeoComp asd = new GeoComp(j, dist_xxx, aod, aoa);
                            temp_list.Add(asd);
                        }
                    }
                }
            }

            for (int ii = 0; ii < Tx_MPC2.Count; ii++)
            {
                if (temp_list.Any(geocom => geocom.MPCIndex == Tx_MPC2[ii]))
                {
                    int temp_index = temp_list.FindIndex(geocom => geocom.MPCIndex == Tx_MPC2[ii]);
                    // defining peprendicular to the considered normal that is parallel to the ground. 
                    V6 temp_Rx_MPC2 = MPC2[Rx_MPC2[i]];
                    V6 temp_Tx_MPC2 = MPC2[Tx_MPC2[ii]];

                    Vector3 n_perp1 = new Vector3(-temp_Rx_MPC2.Normal.z, 0, temp_Rx_MPC2.Normal.x);
                    Vector3 Rx_dir1 = (Rx.transform.position - temp_Rx_MPC2.Coordinates).normalized;
                    Vector3 RT = (temp_Tx_MPC2.Coordinates - temp_Rx_MPC2.Coordinates).normalized;

                    Vector3 n_perp2 = new Vector3(-temp_Tx_MPC2.Normal.z, 0, temp_Tx_MPC2.Normal.x);
                    Vector3 Tx_dir2 = (Tx.transform.position - temp_Tx_MPC2.Coordinates).normalized;
                    Vector3 TR = (temp_Rx_MPC2.Coordinates - temp_Tx_MPC2.Coordinates).normalized;

                    if ((Vector3.Dot(n_perp1, Rx_dir1) * Vector3.Dot(n_perp1, RT) < 0) && (Vector3.Dot(n_perp2, Tx_dir2) * Vector3.Dot(n_perp2, TR) < 0))
                    {
                        float rx_distance2MPC2 = (Rx.transform.position - MPC2[Rx_MPC2[i]].Coordinates).magnitude;
                        float tx_distance2MPC2 = (Tx.transform.position - MPC2[Tx_MPC2[ii]].Coordinates).magnitude;
                        float MPC2_distance = temp_list[temp_index].Distance;
                        float total_distance = rx_distance2MPC2 + MPC2_distance + tx_distance2MPC2;

                        Path2 temp_path2 = new Path2(Rx.transform.position, MPC2[Rx_MPC2[i]].Coordinates, MPC2[Tx_MPC2[ii]].Coordinates, Tx.transform.position, total_distance, 0.0f);
                        second_order_paths.Add(temp_path2);
                        if (MPC2_Tracer)
                        {
                            Debug.DrawLine(temp_path2.Rx_Point, temp_path2.MPC2_1, Color.green);
                            Debug.DrawLine(temp_path2.MPC2_1, temp_path2.MPC2_2, Color.yellow);
                            Debug.DrawLine(temp_path2.MPC2_2, temp_path2.Tx_Point, Color.cyan);
                        }
                    }
                }
            }

        }



    }
示例#2
0
    // Start is called before the first frame update
    void Start()
    {
        GameObject          MPC_Spawner = GameObject.Find("Direct_Solution");
        Correcting_polygons MPC_Script  = MPC_Spawner.GetComponent <Correcting_polygons>();
        List <V6>           MPC1        = MPC_Script.SeenV6_MPC1;
        List <V6>           MPC2        = MPC_Script.SeenV6_MPC2;
        List <V6>           MPC3        = MPC_Script.SeenV6_MPC3;

        Debug.Log("LookUpTableGen Script");
        Debug.Log("#MPC1 = " + MPC1.Count + "; #MPC2 = " + MPC2.Count + "; #MPC3 = " + MPC3.Count);


        string do_we_need_third_order = "n";

        // for MPC1, we do not need to have a LookUp table
        // LookUpTable for MPC2
        double angle_threshold2 = 0.1;
        int    level_start2     = 0;

        for (int i = 0; i < MPC2.Count; i++)
        {
            List <int>     tempV6list    = new List <int>();
            List <GeoComp> temp_goeComps = new List <GeoComp>();
            int            temp_seen_mpc = 0;
            for (int ii = 0; ii < MPC2.Count; ii++)
            {
                if (i != ii)
                {
                    Vector3 temp_direction = (MPC2[ii].Coordinates - MPC2[i].Coordinates).normalized;
                    //RaycastHit hit;
                    //if (Physics.Linecast(MPC2[i].Coordinates, MPC2[ii].Coordinates, out hit))
                    //{ Debug.Log("name of the hit object" + hit.transform.name); }
                    if (!Physics.Linecast(MPC2[i].Coordinates, MPC2[ii].Coordinates))
                    {
                        if (Vector3.Dot(temp_direction, MPC2[ii].Normal) < -angle_threshold2 && Vector3.Dot(temp_direction, MPC2[i].Normal) > angle_threshold2)
                        {
                            float dist = (MPC3[ii].Coordinates - MPC3[i].Coordinates).magnitude;
                            if (dist < MaxSeenDistanceMPC2)
                            {
                                tempV6list.Add(ii);
                                temp_seen_mpc += 1;


                                float   aod       = Mathf.Acos(Vector3.Dot(temp_direction, MPC2[i].Normal));
                                float   aoa       = Mathf.Acos(-Vector3.Dot(temp_direction, MPC2[ii].Normal));
                                GeoComp all_comps = new GeoComp(ii, dist, aod, aoa);

                                Linear_GC2.Add(all_comps);

                                temp_goeComps.Add(all_comps);

                                if (do_we_need_third_order == "y")
                                {
                                    if (i == 20)
                                    {
                                        Debug.DrawLine(MPC2[i].Coordinates, MPC2[ii].Coordinates, Color.yellow, 5.0f);

                                        Debug.Log("The normal of seen mpc " + MPC2[ii].Normal + "; the connecting line direction " + temp_direction);
                                        Debug.DrawLine(MPC2[ii].Coordinates, MPC2[ii].Coordinates + temp_direction * 3.0f, Color.green, 5.0f);
                                        Debug.DrawLine(MPC2[ii].Coordinates, MPC2[ii].Coordinates + MPC2[ii].Normal * 3.0f, Color.red, 5.0f);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            LUT2.Add(tempV6list);
            GC2.Add(temp_goeComps);

            Vector2Int layer_edges = new Vector2Int(level_start2, level_start2 + temp_seen_mpc - 1);
            Indexes_GC2.Add(layer_edges);
            level_start2 += temp_seen_mpc;
            if (MaxLengthOfSeenMPC2Lists < temp_seen_mpc)
            {
                MaxLengthOfSeenMPC2Lists = temp_seen_mpc;
            }
        }



        // LookUpTable for MPC3
        double angle_threshold3 = 0.3;
        int    level_start3     = 0;

        for (int i = 0; i < MPC3.Count; i++)
        {
            List <int>     tempV6list    = new List <int>();
            List <GeoComp> temp_goeComps = new List <GeoComp>();

            int temp_seen_mpc = 0;
            for (int ii = 0; ii < MPC3.Count; ii++)
            {
                if (i != ii)
                {
                    Vector3 temp_direction = (MPC3[ii].Coordinates - MPC3[i].Coordinates).normalized;
                    if (!Physics.Linecast(MPC3[i].Coordinates, MPC3[ii].Coordinates))
                    {
                        if (Vector3.Dot(temp_direction, MPC3[ii].Normal) < -angle_threshold3 && Vector3.Dot(temp_direction, MPC3[i].Normal) > angle_threshold3)
                        {
                            float dist = (MPC3[ii].Coordinates - MPC3[i].Coordinates).magnitude;
                            if (dist < MaxSeenDistanceMPC3)
                            {
                                tempV6list.Add(ii);
                                temp_seen_mpc += 1;

                                float   aod       = Mathf.Acos(Vector3.Dot(temp_direction, MPC3[i].Normal));
                                float   aoa       = Mathf.Acos(-Vector3.Dot(temp_direction, MPC3[ii].Normal));
                                GeoComp all_comps = new GeoComp(ii, dist, aod, aoa);
                                Linear_GC3.Add(all_comps);
                                temp_goeComps.Add(all_comps);

                                if (do_we_need_third_order == "y")
                                {
                                    if (i == 20)
                                    {
                                        Debug.DrawLine(MPC3[i].Coordinates, MPC3[ii].Coordinates, Color.yellow, 5.0f);

                                        Debug.Log("The normal of seen mpc " + MPC3[ii].Normal + "; the connecting line direction " + temp_direction);
                                        Debug.DrawLine(MPC3[ii].Coordinates, MPC3[ii].Coordinates + temp_direction * 3.0f, Color.green, 5.0f);
                                        Debug.DrawLine(MPC3[ii].Coordinates, MPC3[ii].Coordinates + MPC3[ii].Normal * 3.0f, Color.red, 5.0f);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            LUT3.Add(tempV6list);
            GC3.Add(temp_goeComps);

            Vector2Int layer_edges = new Vector2Int(level_start3, level_start3 + temp_seen_mpc - 1);
            Indexes_GC3.Add(layer_edges);
            level_start3 += temp_seen_mpc;
            if (MaxLengthOfSeenMPC3Lists < temp_seen_mpc)
            {
                MaxLengthOfSeenMPC3Lists = temp_seen_mpc;
            }
        }
    }