Esempio n. 1
0
    private float CalculateBearing(GameObject ref1, GameObject ref2, string unit = "D")
    {
        //TODO-Get lat long of reference objects at given time
        movement ref1script = ref1.GetComponent <movement>();
        movement ref2script = ref2.GetComponent <movement>();
        double   lat1       = ref1script.GetCurrentLatitue();   //38.582011;
        double   lon1       = ref1script.GetCurrentLongitude(); // 106.050793;
        double   lat2       = ref2script.GetCurrentLatitue();   // 39.582011;
        double   lon2       = ref2script.GetCurrentLongitude(); // 106.050793;

        double dLon = (lon2 - lon1);
        //double dLat = (lat2 - lat1);

        //float bearing = Mathf.Rad2Deg * Mathf.Tan((float)dLat/ (float)dLon);

        //if(lat1>lat2 && lon1 < lon2)
        //{
        //    bearing= bearing + 270;
        //}
        //else if (lat1 < lat2 && lon1 < lon2)
        //{
        //    bearing = bearing + 180;
        //}
        //else if (lat1 < lat2 && lon1 > lon2)
        //{
        //    bearing = bearing +90;
        //}
        //return bearing;
        double y       = Mathf.Sin((float)dLon) * Mathf.Cos((float)lat2);
        double x       = Mathf.Cos((float)lat1) * Mathf.Sin((float)lat2) - Mathf.Sin((float)lat1) * Mathf.Cos((float)lat2) * Mathf.Cos((float)dLon);
        float  bearing = Mathf.Rad2Deg * (Mathf.Atan2((float)y, (float)x));

        bearing = (((bearing + 360) % 360));

        if (unit == "R")
        {
            return(Mathf.Deg2Rad * bearing);
        }
        else if (unit == "D")
        {
            return(bearing);
        }
        else
        {
            return(-1);
        }
    }
Esempio n. 2
0
    private double CalculateDistance(GameObject ref1, GameObject ref2, string unit = "Nm", bool isBullEye = false)
    {
        //TODO- Get lat long of reference objects at given time
        movement ref1script = ref1.GetComponent <movement>();
        double   lat1       = ref1script.GetCurrentLatitue();   //38.582011;
        double   lon1       = ref1script.GetCurrentLongitude(); // 106.050793;
        double   lat2;
        double   lon2;

        if (isBullEye)
        {
            Vector2 ref2LatLong = ref2.GetComponent <PositionData>().GetLatLong();
            lat2 = ref2LatLong.x;
            lon2 = ref2LatLong.y;
        }
        else
        {
            movement ref2script = ref2.GetComponent <movement>();
            lat2 = ref2script.GetCurrentLatitue();   // 39.582011;
            lon2 = ref2script.GetCurrentLongitude(); // 106.050793;
        }

        if ((lat1 == lat2) && (lon1 == lon2))
        {
            return(0);
        }
        else
        {
            //Heavy maths calculations
            double theta = lon1 - lon2;
            double dist  = Mathf.Sin((float)(Mathf.Deg2Rad * lat1)) * Mathf.Sin((float)(Mathf.Deg2Rad * lat2)) + Mathf.Cos((float)(Mathf.Deg2Rad * lat1)) * Mathf.Cos((float)(Mathf.Deg2Rad * lat2)) * Mathf.Cos((float)(Mathf.Deg2Rad * theta));
            dist = Mathf.Acos((float)dist);
            dist = Mathf.Rad2Deg * dist;
            dist = dist * 60 * 1.1515;
            if (unit == "K")
            {
                dist = dist * 1.609344;
            }
            else if (unit == "Nm")
            {
                dist = dist * 0.8684;
            }
            return(dist);
        }
    }