I am developing an AR application where a number of historical buildings are spawned around the player depending on his position when a target / QR Code is recognized.
I know the Lat/Lon of these buildings and I have the Lat/Lon of the player. I have already implemented the Harvesine algorithm and can calculate the relative bearing of the buildings:
public static double Harvesine(double lat1, double lon1, double lat2, double lon2)
{
double R = 6371000; // metres
double omega1 = ((lat1 / 180) * Mathf.PI);
double omega2 = ((lat2 / 180) * Mathf.PI);
double variacionomega1 = (((lat2 - lat1) / 180) * Mathf.PI);
double variacionomega2 = (((lon2 - lon1) / 180) * Mathf.PI);
double a = Math.Sin(variacionomega1 / 2) * Math.Sin(variacionomega1 / 2) +
Math.Cos(omega1) * Math.Cos(omega2) *
Math.Sin(variacionomega2 / 2) * Math.Sin(variacionomega2 / 2);
double c = 2 * Math.Asin(Math.Sqrt(a));
double d = R * c;
return d;
}
public static double Bearing(double lat1, double lon1, double lat2, double lon2)
{
double radians;
double x = Math.Cos(lat2*Mathf.Deg2Rad) * Math.Sin((lon2 - lon1) * Mathf.Deg2Rad);
double y = Math.Cos(lat1 * Math.PI / 180) * Math.Sin(lat2 * Math.PI / 180) - Math.Sin(lat1 * Math.PI / 180) * Math.Cos(lat2 * Math.PI / 180) * Math.Cos((lon2 - lon1) * Math.PI / 180);
radians = Math.Atan2(x, y) * 180 / Math.PI;
return radians;
}
From here, how can I spawn the building relative to the player position? I have the distance (Harvesine) and the angle (Bearing), how can I get the Vector3 location?