# Coastal Navigation: The Math Behind It

Currently we’re working on a cool project with SimRad to create a training simulator for a gps device. But to do that and to write the code and the statement of work for the programmer we had to be very clear about the math behind it all. At least to me, it’s all pretty interesting and so I thought I’d share it here. Kinda like “the making of…” in movie talk.

With traditional **coastal navigation** you are plotting positions on a chart then measuring the angles and distances. That’s all pretty easy and well described in the NauticEd Coastal navigation course. But once you start to do it electronically, you’ve got to have the mathematics of it all well understood in order to write the code. Turns out it’s again pretty easy but you’ve got to reach deep into some brain cells to drag out the trigonometry you’ve so desperately tried to forget from high school days and thought/hoped you’d never use again.

But this is a worthwhile read because you’ll exit out understanding the principles, which is really the point of the sailing blog entry.

So here’s one snippet of what we did:

We simulated a vessel moving at 20 knots that can be controlled using the autopilot. We input a static current to the east at 2 knots. For this scenario and for any direction the vessel is moving, we want to present the following variables in real time as they changed:

- Bearing to Destination – BTD
- Distance to Destination – DTD
- Course to Steer to reach destination – CTS
- Speed Over Ground – SOG
- Time to Destination – TTD
- Position of the vessel

The difficulty comes in with the current. You can’t just head towards your destination because the current will drag you off. So you’ve got to solve for a triangle where you have limited information and the triangle is not a right angle triangle.

We decided early on in the simulation to work in meters and meters per second because it makes the math a lot simpler. Also just by universal convenience meters per sec is ½ speed in knots. Thus 20 knots = 10m/s.

In a first example, the destination is at a point 500m to the north and 1000 m to the east of the vessel. Since we know the instantaneous position of the vessel and the position of the waypoint, we know the instantaneous distance to the waypoint. I say instantaneous because the vessel is moving.

That’s a good start however the vessel is not moving at 20 knots towards the target. Due to the current the resultant vessel speed over ground is slightly different. To visualize what’s happening we drew this triangle. We added the current vector to the bearing vector to create a Course To Steer vector.

There is a further complication however, since the whole process of getting to the destination doesn’t necessarily take 1 hour. We can’t say that the current vector is 2 nautical miles long. Thus in the distance triangle above we only know two variables, the angle (a) and the distance to destination – that’s not enough information. Instead we have to draw a velocity triangle whereby the current is 2 and the vessel speed is 20. Fortunately this triangle is exactly the same shape as the distance triangle. In that triangle we know three variables, vessel velocity, current velocity and the angle (a). Thus we can proceed to solve for the entire situation.

Here’s the painful part from the ol days

A/sin(a) = B/sin(b) = C/sin(c) it’s called the sin rule.

The lower case letters are the angles and the upper case letters are the triangle side lengths opposite the same lower case letter. IE length A is opposite the angle a.

Just bare with us if that scares you. Actually it’s pretty simple from here you just have to plug and play. What it means is that if you know 3 pieces of information about any triangle you can find the others.

The first thing well solve for is the angle b. To do this, use the velocity triangle. The three pieces of information that we know are the current speed vector length, the vessel speed vector length and the angle to destination (a).

In this quadrant ie angle to destination is less than 90 deg, the Bearing to Destination is 90 minus the angle to the target ie BTD = 90-(a)

Solving the sin rule for angle (b) then

(b)= arcsin ( current x sin (a)/(vessel speed)) = arcsin (B x sin (a)/A)

= 2.6 deg

Since all angles in a triangle add to 180 the angle c must = 150.9 deg. This is the course that you would steer to arrive at the target due to the current.

The luck of it is that this is the same angle to plug back into the distance triangle

IE (c)= (c*).

Now we can return to the distance triangle because we know enough variables. If we plug the two known angles (a) and (c) in to distance triangle we can solve for the distance A*. We need to know A* because the vessel attempts to travel along this path at 10m/s but ends up at the destination. Solving for the time it would take the vessel to attempt A* is the same time it takes for the vessel to actually travel to the destination. IE the vessel is helped by the current.

From the sin rule:

A* = C* x sin(a)/sin(c) = 1027.2 meters

and at 10 m/s the time elapsed is 102.72 sec = ~ 103 seconds

The vessel actually travelled 1128 meters in 103 seconds thus the

SOG = 1128/103 = 10.9 m/s = 21.8 knots

The distance that the vessel was pushed to the east by the current = Set =B*

Set= current speed(drift) x time = 1 *103 = 103 meters.

So for this tiny moment point in time:

- BTD= 63.4 degT
- CTS=60.9 deg T
- DTD = 1128 m
- TTD = 103 sec
- SOG = 10.9 m/s

In coding all this up and since the vessel is moving we have to solve all these at each instant in time using location information from the last moment in time. Again not too difficult it just takes a bit of thought in laying it all out.

If you know the velocity of the vessel over ground (solved from above) and the increment in time, you can calculate the change in position. This is done in Cartesian coordinates Ie x and y directions

- Change in X = velocity in x direction times the time increment = Vx x dt
- Change in Y= velocity in y direction times the time increment = Vy x dt

Where Vx and Vy are solved from the angles calculated from above and SOG

So the position at this instant is now the position at the last instant plus the distance travelled in the increment in time.

We have to solve all this for each instant in time because the vessel is also changing direction from input from the autopilot. In a real situation the position information is being gathered from the actual gps not the last instant. Altho some smarter systems will use this for predictive situations.

Another level of complexity is added in when you consider other quadrants. For example in the below drawing, the current works against the vessel. Note the SOG has slowed, the angle b reduces the CTS, and the triangle is quite different. Thus in the code we have to add a lot of if/then statements to determine what quadrant were working in to determine which formula to use.

**OK ADMITTEDLY THAT MIGHT HAVE BEEN A BIT HEAVY GOING **

Hopefully this gave you some insight into:

- Some principles behind
*coastal navigation* - Help in understanding
*electronic coastal navigation* - Some insight into what we do at our sailing school to provide great sailing education

We can’t wait to deliver the SimRad Electronic Navigation simulator and training tool to you.

If you’re interested in properly understanding how to navigate a vessel using charts then take the NauticEd Coastal Navigation Course. Once we finish the electronic navigation simulator we’ll embed it into the Navigation sailing course.

- Learn Lateral Marks in Virtual Reality - January 27, 2023
- Who Gives Way Port versus Starboard? - December 1, 2022
- How do Polar Plots Work on a Sailboat? - November 23, 2022