# crossfix

Cross-fix positions from bearings and ranges

## Syntax

```[newlat,newlon] = crossfix(lat,lon,az) [newlat,newlon] = crossfix(lat,lon,az_range,case) [newlat,newlon] = crossfix(lat,lon,az_range,case,drlat,drlon) [newlat,newlon] = crossfix(lat,lon,az,units) [newlat,newlon] = crossfix(lat,lon,az_range,case,units) [newlat,newlon] = crossfix(lat,lon,az_range,drlat,drlon,units) [newlat,newlon] = crossfix(lat,lon,az_range,case,drlat,drlon,units) mat = crossfix(...) ```

## Description

`[newlat,newlon] = crossfix(lat,lon,az)` returns the intersection points of all pairs of great circles passing through the points given by the column vectors `lat` and `lon` that have azimuths `az` at those points. The outputs are two-column matrices `newlat` and `newlon` in which each row represents the two intersections of a possible pairing of the input great circles. If there are n input objects, there will be n choose 2 pairings.

`[newlat,newlon] = crossfix(lat,lon,az_range,case)` allows the input `az_range` to specify either azimuths or ranges. Where the vector `case` equals 1, the corresponding element of `az_range` is an azimuth; where `case` is 0, `az_range` is a range. The default value of `case` is a vector of ones (azimuths).

`[newlat,newlon] = crossfix(lat,lon,az_range,case,drlat,drlon)` resolves the ambiguities when there is more than one intersection between two objects. The scalar-valued `drlat` and `drlon` provide the location of an estimated (dead reckoned) position. The outputs `newlat` and `newlon` are column vectors in this case, returning only the intersection closest to the estimated point. When this option is employed, if any pair of objects fails to intersect, no output is returned and the warning ```No Fix``` is displayed.

`[newlat,newlon] = crossfix(lat,lon,az,units)`, ```[newlat,newlon] = crossfix(lat,lon,az_range,case,units)```, `[newlat,newlon] = crossfix(lat,lon,az_range,drlat,drlon,units)`, and `[newlat,newlon] = crossfix(lat,lon,az_range,case,drlat,drlon,units)` allow the specification of the angle units to be used for all angles and ranges, where `units` is any valid angle units value. The default value of `units` is `'degrees'`.

`mat = crossfix(...)` returns the output in a two- or four-column matrix `mat`.

This function calculates the points of intersection between a set of objects taken in pairs. Given great circle azimuths and/or ranges from input points, the locations of the possible intersections are returned. This is different from the navigational function `navfix` in that `crossfix` uses great circle measurement, while `navfix` uses rhumb line azimuths and nautical mile distances.

## Examples

collapse all

This example shows how to find the intersection of points on circles.

Create map axes.

```figure('color','w'); ha = axesm('mapproj','mercator', ... 'maplatlim',[-10 15],'maplonlim',[-10 20],... 'MLineLocation',5,'PLineLocation',5); axis off gridm on framem on mlabel on plabel on```

Define latitudes and longitudes of three arbitrary points, and then define three radii, all 8 degrees.

```latpts = [0;5;0]; lonpts = [0;5;10]; radii = [8;8;8];```

Obtain the intersections of imagined small circles around these points.

`[newlat,newlon] = crossfix(latpts,lonpts,radii,[0;0;0])`
```newlat = 3×2 7.5594 -2.5744 6.2529 -6.2529 7.5594 -2.5744 ```
```newlon = 3×2 -2.6260 7.5770 5.0000 5.0000 12.6260 2.4230 ```

Draw red circle markers at the given points.

```geoshow(latpts,lonpts,'DisplayType','point',... 'markeredgecolor','r','markerfacecolor','r','marker','o')```

Draw magenta diamond markers at the points of intersection.

```geoshow(reshape(newlat,6,1),reshape(newlon,6,1),'DisplayType','point',... 'markeredgecolor','m','markerfacecolor','m','marker','d')```

Generate a small circle 8 deg radius for each original point.

```[latc1,lonc1] = scircle1(latpts(1),lonpts(1),radii(1)); [latc2,lonc2] = scircle1(latpts(2),lonpts(2),radii(2)); [latc3,lonc3] = scircle1(latpts(3),lonpts(3),radii(3));```

Plot the small circles to show the intersections are as determined.

```geoshow(latc1,lonc1,'DisplayType','line',... 'color','b','linestyle','-') geoshow(latc2,lonc2,'DisplayType','line',... 'color','b','linestyle','-') geoshow(latc3,lonc3,'DisplayType','line',... 'color','b','linestyle','-')```

Find intersection when a dead reckoning position is provided, (0º,5ºE). `crossfix` returns one from each pair (the closest one).

```[newlat,newlon] = crossfix([0 5 0]',[0 5 10]',... [8 8 8]',[0 0 0]',0,5) ```
```newlat = -2.5744 6.2529 -2.5744 newlon = 7.5770 5.0000 2.4230```