
I recently noticed a useful feature on a chartplotter, that is the closest point of approach information (hereafter CPA). The CPA gives the closest distance to ever occur between two moving boats. It also gives the time to the closest point of approach (hereafter TCPA), that is when the CPA will occur.
To give an example, see the Figure on top of this text. One sailboat (A) has a speed on ground of six knots and a course on ground of 45 degrees (true). Another sailboat (B) has also a speed on ground of six knots and a course on ground of 270 degrees (true). At the time of the CPA calculation, sailboat A is at the coordinate (1,1), each coordinate measured in nautical miles from the origin. Sailboat B is at the coordinate (9,8). Then, the CPA between the two boats is of roughly 4.7 nautical miles and should happen roughly 51 minutes after the time of calculation. The CPA is shown on the Figure, as well as where the two boats should be when it will happen.
The practical use of the CPA/TCPA pair is to evaluate the risk of collisions. If the CPA between two boats is zero (or close to zero), there is a collision risk and the skipper should alter the boat’s current course to increase the CPA. As the course and speed of boats have a tendency to change with conditions, the CPA and TCPA often change with new data and calculations. Thus, the information should be examined a few times – if time allows – prior to taking action.
It should further be noted that the CPA and TCPA are calculated from the AIS data received. Hence, it does not tell anything about boats that are not transmitting and thus, is no substitute for a human watch.
That being said, I recently crossed the entry of the Gibraltar straight from the Atlantic side. Although we were more than two hundred nautical miles off the coast, there was a substantial amount of tankers and other large commercial ships. The CPA and TCPA helped us prioritize in which order we should avoid tankers a few hours in advance. It also helped us organize our VHF calls to the tankers that were too going to be too close for our taste, somewhat guaranteeing they would watch us. It is not a substitute for an active watch, but it is a powerful tool to anticipate and prioritize.
How Is It Found?
I dug into the mathematics of the CPA and found it amounts to finding the minimum of a quadratic equation. Alas, some use for the dreadfull parabola most of us learned in high school! It turns out that the (square) of the distance between boats is expressed as a parabola:
D^2(t) = c + bt + at^2.
If you paid attention in class, you may recall that the minimum of such function happens at the value t_{cpa} given by:
t_{cpa}=-\frac{b}{2a}
This also turns out to be the minimum of the distance itself (the CPA). Thus, all that is required to find the CPA/TCPA pair is the values “a” and “b” of the parabola, which gives u the TCPA. One can then find the CPA by using the distance equation (cpa \equiv D(t_{cpa})). In the following section, I show that the CPA and TCPA satisfy the equations:
t_{cpa} = -\frac{\Delta V_x \Delta x + \Delta V_y\Delta y}{\Delta V_x^2 + \Delta V_y^2} ,
cpa = \frac{\left|\Delta V_y \Delta x - \Delta V_x \Delta y \right|}{\sqrt{\Delta V_x^2 + \Delta V_y^2}} ,
where \Delta V_x is the relative speed (in knots) of the two boats in the east-west dimension and \Delta x is the relative distance (in nautical miles) in the east-west dimension. \Delta V_y and \Delta y have a similar interpretation in the north-south dimension.
The next section – which may very well be skipped if mathematics are not your thing – details how these expressions are found.
Two Boats and One CPA
To ease the exposition, I will work on a planar (cartesian) surface where the horizontal axis is the east-west dimension and the vertical axis is the nort-south dimension. This is exactly as on a Mercator projection map, but I assume that the scale is large enough so that the north-south distortions induced by the projection are constant, as it is the case for most close encounters.
In such space, two boats A and B each have a given bearing (\theta_A, \theta_B) and speed (V_A, V_B). Furthermore, each boat have a position determined by a pair (y_A, x_A) and (y_B, x_B). This is all the information needed in order to compute the CPA and the TCPA. It would normally be provided by an AIS receiver. The calculations would be updated each time new data is received.
It is helpful to decompose the speed of each boat in terms of x,y dimensions. Thus, let V_{xA} \equiv V_A\cos(\theta_A) and V_{yA} \equiv V_A\sin(\theta_A) be respectively the east-west speed of boat A and the north-south speed of boat A. Similarly, let V_{xB} \equiv V_B\cos(\theta_B) and V_{yB} \equiv V_B\sin(\theta_B) be the speed of boat B in the same dimensions. It should be noted that those speeds are signed, meaning that a positive speed is in the east direction (for the east-west dimension) or is the north direction (for the north-south dimension). Negative speeds respectively designate movement in the west or in the south directions. This matters as relative speeds are additive: if two boats have opposite bearings, then the relative speed increases.
For a given amount of time elapsed t, the position of boat A in the east-west dimension is given by x_A + V_{xA}t. Likewise, the position of boat A in the [/katex], the position at the same time t is given by the pair (x_B + V_{xB}t, y_B + V_{yB}t). Thus, the euclidian distance between the two boats at time t is given by:
D(t) = \sqrt{(y_A + V_{yA}t - y_B - V_{yB}t)^2+(x_A + V_{xA}t - x_B + V_{xB}t)^2}.
Additional notation to express relative positions and speed can simplify this expression. Let \Delta V_x \equiv V_{xA} - V_{xB}, \Delta x \equiv x_A - x_B, \Delta V_y and \Delta y. The distance equation then amounts to:
D(t) = \sqrt{(\Delta y + \Delta V_{y}t)^2+(\Delta x + \Delta V_{x}t)^2}.
If one feels like using calculus, now would be the time to take the derivative of this expression and equate it to zero in order to find the TCPA. However, squaring the expression yields a quadratic form (a parabola) and the minimum of the distance will also be the minimum of the quadratic form. I use this trick to use high-school algebra rather than calculus:
\begin{align*}D^2(t) &= (\Delta y + \Delta V_{y}t)^2+(\Delta x + \Delta V_{x}t)^2\\ &= \underbrace{(\Delta y)^2+(\Delta x)^2}_{c} + \underbrace{2 (\Delta y\Delta V_y+\Delta x\Delta V_x)}_{b}t + \underbrace{((\Delta V_y)^2+(\Delta V_x)^2)}_{a}t^2. \end{align*}
As stated in the introduction, this is a quadratic expression whose minimum is found at t_{cpa}=-b/2a. Thus, the minimum is found at:
t_{cpa}=-\frac{\Delta y\Delta V_y+\Delta x\Delta V_x}{(\Delta V_y)^2+(\Delta Vx)^2}.
All that remains to be done is to plug this expression in the original distance formula to find D(t_{cpa}). Careful algebraic manipulations yield the expression in the introduction.
A Simple Script Does the Trick
Lets say we have just received the following data by our AIS receiver:
Boat name | COG (degrees true) | SOG (knots) | Position (x,y) |
---|---|---|---|
Us | 50 | 6 | (0, 0) |
A | 270 | 5 | (5, 5) |
B | 200 | 7 | (3, 2) |
C | 100 | 20 | (-3, -4) |
We can then easily write a python script that would compute the CPA and TCPA. I assume below that the data table is encoded in python lists.
from math import pi, cos, sin
boats = ["Us", "A", "B", "C"]
speed = {'Us' : 6, 'A': 5, 'B': 7, 'C':20}
bearing = {'Us' : 50, 'A': 270, 'B': 200, 'C':100}
position = {'Us' : (0,0), 'A': (5,5), 'B': (3,2), 'C':(-3,-4)}
for some_boat in boats[1:]:
DVx = speed[some_boat]*cos(bearing[some_boat]*2*pi/360) - speed["Us"]*cos(bearing['Us']*2*pi/360)
DVy = speed[some_boat]*sin(bearing[some_boat]*2*pi/360) - speed["Us"]*sin(bearing['Us']*2*pi/360)
Dx = position[some_boat][0] - position['Us'][0]
Dy = position[some_boat][1] - position['Us'][1]
tcpa = -(Dy*DVy+Dx*DVx)/(DVy**2 + DVx**2)
cpa = abs(Dx*DVy - Dy*DVx) / pow(DVy**2 + DVx**2, 0.5)
print("The closest point of boat "+ some_boat +" is : " +str(cpa) + " nautical miles.")
print("The time to the CPA is : " +str(tcpa) + " hours.")
Such program will then print:
The closest point of boat A is : 2.7747959776445734 nautical miles.
The time to the CPA is : 0.6288639179481108 hours.
The closest point of boat B is : 0.008127181074962114 nautical miles.
The time to the CPA is : 0.28707224836596984 hours.
The closest point of boat C is : 4.445583406151827 nautical miles.
The time to the CPA is : 0.13633746219194873 hours.
This would obviously need to be presented in a more attractive fashion, but the gist of the information is there. It is worth noting that boat B‘s CPA might be too close to our taste, with 0.008 nautical miles (14 meters or 49 feets) in 30 minutes. A course correction might be warranted.
Does This Matter?
In the pre-computer age, it was the task of the navigator to evaluate collision risks. Thanks to onboard computers, no one will ever have to compute those by hand. Maybe if I had to analyze some raw data, I could, at some point, program such functions in a statistical software, but this is the only case I can think of using these formulas myself.
That being said, I like to understand how the tools I use function. This is probably how a chartplotter computes a CPA and a TCPA with every AIS data update (there are suggestions for improvements). Having this information understood gives a sense of how the chartplotter behaves and what to expect of it.
Other than that, this text is hopefully a fun read. It definitely helped me kill the time in two (uneventful) night watches. You may have guessed that those were not near the Gibraltar straight.