Scroll to navigation



IntersectTool -- perform rhumb line calculations


IntersectTool [ -c | -n | -i | -o | [ -R maxdist ] [ -e a f] [ -E ] [ -w ] [ -p prec ] [ --comment-delimiter commentdelim ] [ --version | -h | --help ] [ --input-file infile | --input-string instring ] [ --line-separator linesep ] [ --output-file outfile ]


IntersectTool finds the intersection of two geodesics X and Y. The geodesics may either be specified as a location and an azimuth, latX lonX aziX, or as the shortest geodesic segment between two locations, latX1 lonX1 and latX2 lonX2. 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:

With the -c option (the default), IntersectTool accepts lines on the standard input containing latX lonX aziX latY lonY aziY, specifying two geodesic lines X and Y, and prints the location of the closest intersection x y c on standard output.
With the -n option, IntersectTool accepts lines on the standard input containing latX lonX aziX aziY aziY, specifying a point where two geodesic lines X and Y intersect, and prints the location of the next closest intersection x y c on standard output.
With the -i option, IntersectTool accepts lines on the standard input containing latX1 lonX1 latX2 lonX2 latY1 lonY1 latY2 lonY2, specifying two geodesic segments X1-X2 and Y1-Y2, and prints x y c k 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.
With the -o option, IntersectTool accepts lines on the standard input containing latX lonX aziX latY lonY aziY x0 y0, specifying two geodesic lines X and Y and two offsets, and prints x y c on standard output where [x, y] is the intersection closest to [x0, y0].


find the closest intersection (see 1 above).
find the intersection closest to a given intersection (see 2 above).
find the intersection of two geodesic segments (see 3 above).
find the closest intersection with an offset.
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, x y c z 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.
check the intersections. For each computed intersection, print on standard error a line latX lonX latY lonY sXY 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.
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.
use "exact" algorithms (based on elliptic integrals) for the geodesic calculations. These are more accurate than the (default) series expansions for |f| > 0.02.
on input, longitude precedes latitude (except that on input this can be overridden by a hemisphere designator, N, S, E, W).
set the output precision to prec (default 3); prec is the precision relative to 1 m. See "PRECISION".
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).
print version and exit.
print usage and exit.
print full documentation and exit.
read input from the file infile instead of from standard input; a file name of "-" stands for standard input.
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.
set the line separator character to linesep. By default this is a semicolon.
write output to the file outfile instead of to standard output; a file name of "-" stands for standard output.


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).


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.


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.


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.


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.


GeoConvert(1), GeodSolve(1).

This solution for intersections is described in C. F. F. Karney, Geodesic intersections, Technical Report, SRI International (2023); URL: <>. It is based on the work of S. Baseldga and J. C. Martinez-Llario, Intersection and point-to-line solutions for geodesics on the ellipsoid, Stud. Geophys. Geod. 62, 353-363 (2018); DOI: <>;


IntersectTool was written by Charles Karney.


IntersectTool was added to GeographicLib, <>, in version 2.3.

2023-07-25 GeographicLib 2.3