Ejemplo n.º 1
0
    public void Calc(float xc, float yc, float xp, float yp, float r)
    {
        float distance = 0f, x = 0f, y = 0f, r1, r2, r3, c;
        float R = 6378.137f;

        r1            = xc * Mathf.Deg2Rad;
        r2            = xp * Mathf.Deg2Rad;
        x             = (xp - xc) * Mathf.Deg2Rad;
        y             = (yp - yc) * Mathf.Deg2Rad;
        r3            = Mathf.Sin(x / 2) * Mathf.Sin(x / 2) + Mathf.Cos(r1) * Mathf.Cos(r2) * Mathf.Sin(y / 2) * Mathf.Sin(y / 2);
        c             = 2 * Mathf.Atan2(Mathf.Sqrt(r3), Mathf.Sqrt(1 - r3));
        distance      = Mathf.RoundToInt(R * c * 1000f);
        Distance.text = " Distance: " + distance + " m";
        if (distance <= r)
        {
            range.text = "In range";
            Model.SetActive(true);
            Model2.SetActive(true);
        }
        else
        {
            range.text = "Not In range";
            Model.SetActive(false);
            Model2.SetActive(false);
        }
    }