5.2.8. nvector.core.intersect

intersect(path_a, path_b)[source]

Returns the intersection(s) between the great circles of the two paths

Parameters
path_a, path_b: tuple of 2 n-vectors

defining path A and path B, respectively. Path A and B has shape 2 x 3 x n and 2 x 3 x m, respectively.

Returns
n_EC_Earray of shape 3 x max(n, m)

n-vector(s) [no unit] of position C decomposed in E. point(s) of intersection between paths.

Notes

The result for spherical Earth is returned.

Examples

Example 9: “Intersection of two paths”

https://raw.githubusercontent.com/pbrod/Nvector/master/docs/tutorials/images/ex9img.png

Define a path from two given positions (at the surface of a spherical Earth), as the great circle that goes through the two points.

Path A is given by A1 and A2, while path B is given by B1 and B2.

Find the position C where the two great circles intersect.

Solution:
>>> import numpy as np
>>> import nvector as nv
>>> from nvector import rad, deg
>>> n_EA1_E = nv.lat_lon2n_E(rad(10), rad(20))
>>> n_EA2_E = nv.lat_lon2n_E(rad(30), rad(40))
>>> n_EB1_E = nv.lat_lon2n_E(rad(50), rad(60))
>>> n_EB2_E = nv.lat_lon2n_E(rad(70), rad(80))
>>> n_EC_E = nv.unit(np.cross(np.cross(n_EA1_E, n_EA2_E, axis=0),
...                           np.cross(n_EB1_E, n_EB2_E, axis=0),
...                           axis=0))
>>> n_EC_E *= np.sign(np.dot(n_EC_E.T, n_EA1_E))
or alternatively
>>> path_a, path_b = (n_EA1_E, n_EA2_E), (n_EB1_E, n_EB2_E)
>>> n_EC_E = nv.intersect(path_a, path_b)
>>> lat_EC, lon_EC = nv.n_E2lat_lon(n_EC_E)
>>> lat, lon = deg(lat_EC), deg(lon_EC)
>>> msg = 'Ex9, Intersection: lat, lon = {:4.4f}, {:4.4f} deg'
>>> msg.format(lat[0], lon[0])
'Ex9, Intersection: lat, lon = 40.3186, 55.9019 deg'
Check that PointC is not between A1 and A2 or B1 and B2:
>>> np.allclose([nv.on_great_circle_path(path_a, n_EC_E),
...             nv.on_great_circle_path(path_b, n_EC_E)], False)
True
Check that PointC is on the great circle going through path A and path B:
>>> np.allclose([nv.on_great_circle(path_a, n_EC_E), nv.on_great_circle(path_b, n_EC_E)], True)
True