logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

IntersectTool -- find the intersection of geodesics

Accuracy

       This tool will give nearly full double precision accuracy for |f| < 0.02.  If the  -E  option  is  given,
       full accuracy is achieved for -1/4 < f < 1/5.  The tool had not been tested outside this range.

Author

IntersectTool was written by Charles Karney.

Description

IntersectTool finds the intersection of two geodesics X and Y.  The geodesics may either be specified as
       a location and an azimuth, latXlonXaziX, or as the shortest geodesic segment between two locations,
       latX1lonX1 and latX2lonX2.  The intersection is then specified as the displacements, x and y, along the
       geodesics X and Y from the starting points to the intersection.  In the case of the intersection of
       geodesic segments, the starting point is first point specified for X or Y.

       Usually this tool returns the closest intersection defined as the one that minimizes the "L1" distance,
       |x| + |y|.  However, it is possible to specify an "origin" x0 and y0 when determining closeness so that
       the intersection which minimizes |x - x0| + |y - y0| is returned.

       In the case of intersecting segments the origin is taken to be the midpoints of the segments; x0 is half
       the distance from X1 to X2.  In addition a flag is returned specifying whether the intersection is
       "within" the segments.

       The tool also returns a "coincidence indicator" c.  This is typically 0.  However if the geodesics lie on
       top of one another at the point of intersection, then c is set to 1, if they are parallel, and -1, if
       they are antiparallel.

       IntersectTool operates in one of three modes:

       1.  With  the  -c option (the default), IntersectTool accepts lines on the standard input containing latXlonXaziXlatYlonYaziY, specifying two geodesic lines X and Y,  and  prints  the  location  of  the
           closest intersection xyc on standard output.

       2.  With  the -n option, IntersectTool accepts lines on the standard input containing latXlonXaziXaziYaziY, specifying a point where two geodesic lines X and Y intersect, and prints the location  of  the
           next closest intersection xyc on standard output.

       3.  With  the  -i  option, IntersectTool accepts lines on the standard input containing latX1lonX1latX2lonX2latY1lonY1latY2lonY2, specifying two geodesic segments X1-X2 and Y1-Y2, and prints xyck
           on  standard  output.   Here  k is a flag in [-4,4] specifying whether the intersection is within the
           segments (0) or not (non-zero).  x and y give the distances from X1 and Y1 respectively.  k is set to
           3 kx + ky where kx = -1 if x < 0, 0 if 0 <= x <= sx, 1 if sx < x, and similarly for  ky;  sx  is  the
           length of the segment X1-X2.

       4.  With  the -o option, IntersectTool accepts lines on the standard input containing latXlonXaziXlatYlonYaziYx0y0, specifying two geodesic lines X and Y and two offsets, and prints xyc on  standard
           output where [x, y] is the intersection closest to [x0, y0].

Errors

       An illegal line of input will print an error message to  standard  output  beginning  with  "ERROR:"  and
       causes  IntersectTool  to  return  an  exit code of 1.  However, an error does not cause IntersectTool to
       terminate; following lines will be converted.

Examples

       A vessel leaves Plymouth 50N 4W on a geodesic path with initial heading 147.7W.  When will it first cross
       the equator?

          echo 50N 4W 147.7W 0 0 90 | IntersectTool -c -p 0 -C

          6058049 -3311253 0
          0.00000 -29.74549 -0.00000 -29.74549 0

       Answer: after 6058km at longitude 29.7W.  When will it cross the date line, longitude 180E?  Here we need
       to use -R because there a closer intersection on the prime meridian:

          echo 50N 4W 147.7W 0 180 0 | IntersectTool -c -p 0 -C -R 2.6e7

          -494582 14052230 0 14546812
          53.69260 0.00000 53.69260 0.00000 0
          19529110 -5932344 0 25461454
          -53.51867 180.00000 -53.51867 180.00000 0
          nan nan 0 nan
          nan nan nan nan nan

       We want the second result: after 19529 km at latitude 53.5S.

History

IntersectTool was added to GeographicLib, <https://geographiclib.sourceforge.io>, in version 2.3.

GeographicLib 2.5                                  2024-12-28                                   INTERSECTTOOL(1)

Input

IntersectTool measures all angles in degrees and all lengths  in  meters.   On  input  angles  (latitude,
       longitude,  azimuth)  can  be  as  decimal  degrees  or degrees, minutes, seconds.  For example, "40d30",
       "40d30'", "40:30", "40.5d", and 40.5 are all equivalent.  By default,  latitude  precedes  longitude  for
       each  point  (the  -w  flag switches this convention); however either may be given first by appending (or
       prepending) N or S to the latitude and E or W to the longitude.  Azimuths  are  measured  clockwise  from
       north; however this may be overridden with E or W.

       For details on the allowed formats for angles, see the "GEOGRAPHIC COORDINATES" section of GeoConvert(1).

Name

       IntersectTool -- find the intersection of geodesics

Options

-c  find the closest intersection (see 1 above).

       -n  find the intersection closest to a given intersection (see 2 above).

       -i  find the intersection of two geodesic segments (see 3 above).

       -o  find the closest intersection with an offset.

       -Rmaxdist
           modifies  the  four  modes  to  return  all  the intersections within an L1 distance, maxdist, of the
           relevant origin: [0, 0] for -c and -n, the midpoints of the segments for -i, and  [x0,  y0]  for  -o.
           For  each  intersection,  xycz is printed on standard output.  Here z is the L1 distance of the
           intersection from the origin and the intersections are sorted by the distances.  A line  "nan  nan  0
           nan" is added after the intersections, so that the output can be associated with the correct lines of
           the input.  The number of intersections scales as (maxdist/(pi a))^2.

       -C  check  the  intersections.   For each computed intersection, print on standarderror a line latXlonXlatYlonYsXY giving the computed positions of the intersections points on X and Y and  the  distance
           between them.  If -w is specified, the longitude is given before the latitude.

       -eaf
           specify the ellipsoid via the equatorial radius, a and the flattening, f.  Setting f = 0 results in a
           sphere.   Specify  f  < 0 for a prolate ellipsoid.  A simple fraction, e.g., 1/297, is allowed for f.
           By default, the WGS84 ellipsoid is used, a = 6378137 m, f = 1/298.257223563.

       -E  use "exact" algorithms (based on elliptic integrals) for the geodesic calculations.  These  are  more
           accurate than the (default) series expansions for |f| > 0.02.

       -w  on  input,  longitude  precedes latitude (except that on input this can be overridden by a hemisphere
           designator, N, S, E, W).

       -pprec
           set the output precision to  prec  (default  3);  prec  is  the  precision  relative  to  1  m.   See
           "PRECISION".

       --comment-delimitercommentdelim
           set  the  comment  delimiter  to  commentdelim  (e.g., "#" or "//").  If set, the input lines will be
           scanned for this delimiter and, if found, the delimiter and the rest of  the  line  will  be  removed
           prior to processing and subsequently appended to the output line (separated by a space).

       --version
           print version and exit.

       -h  print usage and exit.

       --help
           print full documentation and exit.

       --input-fileinfile
           read  input  from  the  file  infile  instead  of  from standard input; a file name of "-" stands for
           standard input.

       --input-stringinstring
           read input from the string instring instead of from standard input.   All  occurrences  of  the  line
           separator character (default is a semicolon) in instring are converted to newlines before the reading
           begins.

       --line-separatorlinesep
           set the line separator character to linesep.  By default this is a semicolon.

       --output-fileoutfile
           write  output  to  the  file  outfile  instead  of  to standard output; a file name of "-" stands for
           standard output.

Precision

prec  gives  precision  of the output with prec = 0 giving 1 m precision, prec = 3 giving 1 mm precision,
       etc.  prec is the number of digits after the decimal point  for  lengths.   The  latitude  and  longitude
       printed  to standard error with the -C option are given in decimal degrees with prec + 5 digits after the
       decimal point.  The minimum value of prec is 0 and the maximum is 10.

See Also

GeoConvert(1), GeodSolve(1).

       This  solution  for  intersections  is described in C. F. F. Karney, Geodesicintersections, J. Surveying
       Eng.   150(3),   04024005:1-9   (2024),   DOI:   <https://doi.org/10.1061/JSUED2.SUENG-1483>;    preprint
       <https://arxiv.org/abs/2308.00495>.   It  is  based on the work of S. Baseldga and J. C. Martinez-Llario,
       Intersectionandpoint-to-linesolutionsforgeodesicsontheellipsoid, Stud. Geophys. Geod. 62, 353-363
       (2018); DOI: <https://doi.org/10.1007/s11200-017-1020-z>;

Synopsis

IntersectTool [ -c | -n | -i | -o | [ -Rmaxdist ] [ -eaf] [ -E ] [ -w ] [ -pprec ] [
       --comment-delimitercommentdelim ] [ --version | -h | --help ] [ --input-fileinfile | --input-stringinstring ] [ --line-separatorlinesep ] [ --output-fileoutfile ]

See Also