# [postgis-users] drawing a line tangent to earth ?

didier peeters dpeeter1 at ulb.ac.be
Tue Feb 6 00:52:10 PST 2018

```Steve and Giuseppe,

thank you for these leads that seem both very interesting.  I will try them now.

Didier

> Le 5 févr. 2018 à 23:16, Giuseppe Broccolo <g.broccolo.7 at gmail.com> a écrit :
>
> Hi Didier,
>
> 2018-02-05 16:08 GMT+01:00 didier peeters <dpeeter1 at ulb.ac.be <mailto:dpeeter1 at ulb.ac.be>>:
> Hi,
>
> Here’s the problem that puzzles me:
> I would like to determine if an object (a building,  an antenna, …) can be seen from a specific point ‘somewhere'.  I have to deal with distances ranging from a few meters to about 200 km or so.  I have the coordinates of the viewing point XYZ and the XYZ coordinates of the object to check as well as its height, and I should find what part of the object is viewable above the horizon, i.e. how many meters of it can be seen (considering that the earth is not flat … ) .
> I thought of assimilating the earth to a trigonometric circle but I fear that the precision would not be good enough for evaluating the height of an antenna above the radius of the planet.
>
> PostGIS allow you to get the angular distance between two objects in the Earth ellipsoid:
> SELECT ST_Distance(ST_GeomFromText('objectA',4326), ST_GeomFromText('objectB', 4326));
> The height (h) of the object B over the ellipsoid is visible from the object A if
> SELECT R_A > (R_B + h) * cos(ST_Distance(ST_GeomFromText('objectA',4326), ST_GeomFromText('objectB',4326)));
> where R_A and R_B are the radius of the ellipsoid corresponding to objectA and objectB, respectively.
>
> You can obtain the ellipsoid radius as a function of position over the ellipsoid knowing the values of the axes
> as reported in liblwgeom.h:
> #define WGS84_MAJOR_AXIS 6378137.0
> #define WGS84_INVERSE_FLATTENING 298.257223563
> #define WGS84_MINOR_AXIS (WGS84_MAJOR_AXIS - WGS84_MAJOR_AXIS / WGS84_INVERSE_FLATTENING)
> #define WGS84_RADIUS ((2.0 * WGS84_MAJOR_AXIS + WGS84_MINOR_AXIS ) / 3.0)
> That is still an approximation, but more accurate than assimilating the Earth as a simple trigonometric circle.
>
> Giuseppe.
> _______________________________________________
> postgis-users mailing list
> postgis-users at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/postgis-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20180206/2291bdf3/attachment.html>
```