Given a latitude, longitude and altitude - calculate pitch/yaw to face object from the ground at given latitude/longitude

571 Views Asked by At

I have two locations.

Object in sky: latitude, longitude, altitude

Object on the ground: latitude, longitude, compass heading

I would like to make something that will point my object on the ground to face the object in the sky (i.e move it clockwise/anticlockwise on a circular axis and then tilt it up and down)

I have looked at different astronomy libraries available which can provide the direction to face to see the moon and so on, but none seem to provide any option for a given location

Ideally I'd like to do this calculation in either NodeJS or PHP but can also work with Java.

1

There are 1 best solutions below

1
James W On

Python solution from

cRadiusOfEarth = 6371;
cFeetToKm = 0.0003048
cHomeLat1=-33.123
cHomeLon1=151.456
 
f1 = math.radians(cHomeLat1);
f2 = math.radians(lat2);
delta_f = math.radians(lat2-cHomeLat1);
delta_g = math.radians(lon2-cHomeLon1);
a = math.sin(delta_f/2) * math.sin(delta_f/2) + math.cos(f1) * math.cos(f2) * math.sin(delta_g/2) * math.sin(delta_g/2);
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a));
dist_km = cRadiusOfEarth * c;
brng_r=math.atan2(
math.sin(lon2-cHomeLon1) * math.cos(lat2)
, math.cos(cHomeLat1)*math.sin(lat2)-math.sin(cHomeLat1)*math.cos(lat2)*math.cos(lon2-cHomeLon1)
)
 
brng_d=(360.0 - math.degrees(brng_r))%360.0
azmth=math.degrees(math.atan(pFeet*cFeetToKm / dist_km))