10

I am looking for the most accurate way of calculating the view angle (Azimuth, Elevation) from a reference point (my location) A to another point B. I have the Lat, Lon, and Altitude for each point.

Currently I am converting to local ENU coordinates using the Wikipedia formulas for ECEF to ENU and using that to calculate the angles.

Az = atan2(E,N)
El = atan(U / sqrt(E^2 + N^2)

Is there a more accurate way of calculating these Angles?

Maybe a different coordinate system I should be projecting to?

Is this the correct type of Angle, should a rhumb line azimuth or something else be used instead?

I have also looked at using Vincenty's formula for calculating the azimuth but it does not take into account the altitude of each point. A change in Altitude using ENU seems to slightly change the Azimuth which seems correct(?). When comparing Vincenty Azimuth with the ENU Azimuth on the surface (Altitude 0), the answers are extremely close but start to differ if the points are not on the surface.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
user66332
  • 111
  • 1
  • 1
  • 6

1 Answers1

14

For accurate calculations, convert (lat, lon, elevation) directly to earth-centered (x,y,z). (If you don't do this, you need to retain additional information about the local normal ["up"] directions in order to compute angles accurately at nonzero elevations.)

Elevation

Given two points (x,y,z) and (x',y',z') in an earth-centered coordinate system, the vector from the first to the second is (dx,dy,dz) = (x'-x, y'-y, z'-z), whence the cosine of the angle made to the normal at (x,y,z) is the inner product of the unit length versions of those vectors:

Cos(elevation) = (x*dx + y*dy + z*dz) / Sqrt((x^2+y^2+z^2)*(dx^2+dy^2+dz^2))

Obtain its principal inverse cosine. Subtract this from 90 degrees if you want the angle of view relative to a nominal horizon. This is the "elevation."

Azimuth

A similar calculation obtains the local direction of view ("azimuth"). We need a level vector (u,v,w) that points due north. One such vector at the location (x,y,z) is (-zx, -zy, x^2+y^2). (The inner product of these two vectors is zero, proving it is level. Its projection onto the Equatorial plane is proportional to (-x,-y) which points directly inward, making it the projection of a north-pointing vector. These two calculations confirm that this is indeed the desired vector). Therefore

Cos(azimuth) = (-z*x*dx - z*y*dy + (x^2+y^2)*dz) / Sqrt((x^2+y^2)(x^2+y^2+z^2)(dx^2+dy^2+dz^2))

We also need the sine of the azimuth, which is similarly obtained once we know a vector pointing due East (locally). Such a vector is (-y, x, 0), because it clearly is perpendicular to (x,y,z) (the up direction) and the northern direction. Therefore

Sin(azimuth) = (-y*dx + x*dy) / Sqrt((x^2+y^2)(dx^2+dy^2+dz^2))

These values enable us to recover the azimuth as the inverse tangent of the cosine and sine.


Example

A pilot in an airplane flying west at 4000 meters, located at (lat, lon) = (39, -75), sees a jet far ahead located at (39, -76) and flying at 12000 meters. What is are the angles of view (relative to the level direction at the pilot's location)?

The XYZ coordinates of the airplanes are (x,y,z) = (1285410, -4797210, 3994830) and (x',y',z') = (1202990, -4824940, 3999870), respectively (in the ITRF00 datum, which uses the GRS80 ellipsoid). The pilot's view vector therefore is (dx,dy,dz) = (-82404.5, -27735.3, 5034.56). Applying the formula gives the cosine of the view angle as 0.0850706. Its inverse cosine is 85.1199 degrees, whence the elevation is 4.88009 degrees: the pilot is looking up by that much.

A north-pointing level vector is (-5.13499, 19.1641, 24.6655) (times 10^12) and an east-pointing level vector is (4.79721, 1.28541, 0) (times 10^6). Therefore, applying the last two formulas, the cosine of the azimuth equals 0.00575112 and its sine equals -0.996358. The ArcTangent function tells us the angle for the direction (0.00575112, -0.996358) is 270.331 degrees: almost due west. (It's not exactly west because the two planes lie on the same circle of latitude, which is curving toward the North pole: see Why is the 'straight line' path across continent so curved? for an extended explanation.)

By the way, this example confirms we got the orientation correct for the azimuth calculation: although it was clear the east-pointing vector was orthogonal to the other two vectors, until now it was not plain that it truly points east and not west.

whuber
  • 69,783
  • 15
  • 186
  • 281
  • Forgive me if I am missing something but I am looking for the Azimuth Angle and Elevation Angle from A to B where the Azimuth Angle is 0 when pointing directly North and positive when pointing East, and the Elevation Angle is negative when pointing down and positive when pointing up.

    It seems like this provides Elevation angle but how do I calculate the Azimuth?

    – user66332 Apr 23 '13 at 17:24
  • Also, in your example, xyz and x'y'z' are the same. – user66332 Apr 23 '13 at 17:33
  • Re the first comment: I have added the azimuth calculation. Re the second comment: thank you for catching that! (It was a manual copying error.) I have fixed it. – whuber Apr 23 '13 at 17:53
  • Are you sure the North vector is calculated correctly? When I compare your East vector to the East vector calculated from the Wiki page, the vectors are the same. They are not the same for the North vector.
    Wiki north unit vector = -0.16288010267506386, 0.6078768187253738, 0.7771459614569709
    Your north unit vector = 0.16221935131335216, 0.6054108610722955, 0.779206372763453
    – user66332 Apr 24 '13 at 19:22
  • From the wiki page the vectors are calculated using the following:

    E = (-sinLon, cosLon, 0) N = (-cosLon * sinLat, -sinLon * sinLat, cosLat) U = (cosLon * cosLat, sinLon * cosLat, sinLat)

    – user66332 Apr 24 '13 at 19:31
  • The Wikipedia page clearly is using spherical coordinates (those are just the usual formulas for conversion from spherical to Cartesian coordinates). They will be incorrect for ellipsoidal datums, which is why there is a discrepancy. – whuber Apr 24 '13 at 20:00
  • Last question, if your example is reworked with the points on the surface (39, -75, 0) and (39, -76, 0), how come the answer does not align with Vincenty's formula? With your formula I get 270.313 and with Vincenty's which is based on an ellipsoid I get 270.315 – user66332 Apr 24 '13 at 21:03
  • I agree that my formula gives 270.313, but exactly what Vincenty formula are you using? – whuber Apr 24 '13 at 21:09
  • 2
    I am using an implementation in the Java WorldWind SDK for Vincenty's Formula for Forward Azimuth. An online version at http://geographiclib.sourceforge.net/cgi-bin/GeodSolve gives the same results. – user66332 Apr 24 '13 at 21:21
  • Here is a link to the formula: http://en.wikipedia.org/wiki/Vincenty's_formulae#Inverse_problem – user66332 Apr 24 '13 at 21:25
  • I thought so: that's a different sense of "azimuth." Vincenty's formula gives the bearing of a geodesic on the ellipsoid from one point to another. You have asked for an "angle of view," which is a three-dimensional direction between the points (and pays no attention to the ellipsoid). The two often will differ slightly. This is more evident when the points are far apart. For instance, if Superman were to use his x-ray vision to see London from New York, he would not jump up in the air and fly exactly in that direction; instead, he would start at a very slight angle from it. – whuber Apr 24 '13 at 21:34
  • I am looking for the view angle so I will use your formula. Thanks again. – user66332 Apr 24 '13 at 21:45
  • Sorry to bring this up again but I am running into an issue with this formula. Some lat/lon coordinates at the same altitude are producing positive elevation angles when I believe they should be negative due to the earth curvature. An example is origin at lat/lon/alt(39.2, -75, 0) and destination at lat/lon/alt(39.1, -75, 0) which is producing an elevation angle of 0.138365988. In your response you mentioned using GRS80 and I am using WGS84 but Im not sure that would make a difference. – user66332 Jun 20 '13 at 22:13
  • The difference between GRS80 and WGS84 is negligible. If you are getting such incorrect answers, it is likely a miscalculation. – whuber Jun 21 '13 at 02:30
  • Can you help me find the miscalculation? (x,y,z) = (1280979.350171092, -4780680.01828508, 4009547.9432281763) (x',y',z') = (1282793.457732861, -4787450.359875997, 4000938.5189371384) (dx,dy,dz) = (1814.107561768964, -6770.341590916738, -8609.424291037954) Cos El = 0.0024149397184416266 El = 89.86163401186435 (0.1383659881356465) – user66332 Jun 25 '13 at 00:03
  • Your calculations are correct. But you might have mixed up the roles of x and x'; if you did, the cosine of the elevation should be negated and you will obtain an elevation of 90.1384 degrees. – whuber Jun 25 '13 at 00:38
  • Im not sure what you mean by mixed up x and x'. I have Cos El = (1280979.350171092 * 1814.107561768964 + -4780680.01828508 * -6770.341590916738 + 4009547.9432281763 * -8609.424291037954) / sqrt((1280979.350171092 * 1280979.350171092 + -4780680.01828508 * -4780680.01828508 + 4009547.9432281763 * 4009547.9432281763) * (1814.107561768964 * 1814.107561768964 + -6770.341590916738 * -6770.341590916738 + -8609.424291037954 * -8609.424291037954) – user66332 Jun 25 '13 at 15:51
  • these are exactly the equations that I'm looking for. what I have are lat/lon decimal values. how do I convert those to ITRF00? – mga Aug 01 '14 at 23:38
  • ok after googling like crazy i found that this is a geodetic to cartesian conversion: http://www.apsalin.com/convert-geodetic-to-cartesian.aspx do you know the parameters for proj to do this? i am using ProjAPI: https://trac.osgeo.org/proj/wiki/ProjAPI – mga Aug 05 '14 at 03:00
  • @mga No projections are involved in such calculations. Please see http://gis.stackexchange.com/questions/30448/local-coordinate-to-geocentric, inter alia. – whuber Aug 05 '14 at 12:07
  • @whuber thanks for the reply. the link seems to mention a GeoTrans package that makes these calculations (could not download, site is down). is there another GDAL/OSGEO/C++ library available to do these calculations? – mga Aug 05 '14 at 13:21
  • @whuber looking at http://trac.osgeo.org/proj/wiki/man_cs2cs it seems to me that the cs2cs should allow this? – mga Aug 05 '14 at 13:33
  • 1
    ok i got the answer for whoever wants to do this (convert lat/lon to cartesian) in the future. uses http://trac.osgeo.org/proj/wiki/man_cs2cs : cs2cs +proj=latlong +datum=WGS84 +units=m +to +proj=geocent +datum=WGS84… not knowing the GIS vocabulary is painful – mga Aug 05 '14 at 16:30
  • @whuber how do these equations affect the superman x-ray example you give? i need exactly that. i tested, with zero altitude, NYC→PIT and i get az=88.4873… el=-2.2919… while NYC→LAX gives az=-86.3087… el=-17.7246… (inputting your examples gives correct values). any ideas? – mga Aug 06 '14 at 03:32
  • @mga I don't understand what you are asking: I don't know which are "these equations" nor do I understand the distinction you are trying to make. This thread explains how to find a direction in space. Other threads explain how to find the geodesic bearing between two points on an ellipsoid (the "inverse problem" in geodesy). That would seem to cover the possibilities. – whuber Aug 06 '14 at 14:01
  • @whuber "these equations": Cos(elevation) = (x*dx… | I will Google for 'geodesic bearing between two points on an ellipsoid' then. thanks – mga Aug 06 '14 at 16:03
  • @whuber seems "bearing" refers to "direction tangent to great circle". i'd like the vector that looks "through" earth (for two very far away points). eg: if points are antipodes it would be straight down from observer position towards earth – mga Aug 06 '14 at 16:21
  • That's what I have provided in this answer. – whuber Aug 06 '14 at 16:23
  • @whuber for two points: NYC=(1334003.56795396, -4654044.58312403, 4138298.89186196) and same longitude as NYC but on equator=(1757417.07871627, -6131241.04910298, 0), both at 0m altitude, I get azimuth~=0 and elevation~=-20. Is this correct? It sounds to me like the azimuth should be ~180 since observer in NYC needs to orient herself south? Elevation seems correct since she needs to look somewhat down at the floor? – mga Aug 08 '14 at 01:57
  • 1
    @whuber The vector from the center of the Earth to the reference point does not point exactly in the "up" direction with the ellipsoid. That difference amounts to about 0.2° at most. – FSimardGIS Mar 02 '19 at 23:45