Given a geodetic segment, e.g., from Brussels to Moscow, and a geodetic point, e.g., Berlin, which can be expressed in PostGIS as follows
select geography 'Linestring(4.35 50.85,37.617222 55.755833)', geography 'Point(13.405 52.52)';
I need to find the point on the segment that is exactly at the same meridian of the given point, i.e., their bearing is 0 degrees.
Any idea how to obtain this ?
For example, using PostGIS, I create a segment from Berlin to the North by taking Berlin's longitude with the maximum of the two latitudes of the initial segment and compute the intersection of the two segments as follows
select st_astext(st_intersection(geography 'Linestring(4.35 50.85,37.617222 55.755833)',
geography 'Linestring(13.405 52.52,13.405 55.755833)'))
st_astext
----------------------------------------------
POINT(13.407059592483968 53.163047143541235)
As can be seen the longitude is not exactly the same and the bearing would not be 0.
with test(inter) as (
select st_intersection(geography 'Linestring(4.35 50.85,37.617222 55.755833)',
geography 'Linestring(13.405 52.52,13.405 55.755833)') )
SELECT degrees(bearing(geography 'Point(13.405 52.52)', inter)) from test;
degrees
---------------------
0.11002408958628832
where bearing is computed using the traditional formula (e.g., https://gist.github.com/jeromer/2005586)
I find the postgis intersection result in you example surprising (and probably wrong). Doing the inverse of your query, it seems to me that there is a numerical precision issue: