# Triangulation

Theory

Triangulation is a common method for finding a coordinate based on the direction the point in question is in relative to two other points and the distance between these two other points. Triangulation is commonly used in surveying, navigation, wireless communications, astronomy, and just about anywhere it is necessary to calculate the location of an object from a distance.

Take for example two points A and B, each having a heading pointing towards some distant point C. Using triangulation we can calculate the coordinate of C. As you can see in the following figure this creates a triangle.

Figure 1 Triangulation

Using the law of sines we can make the following connection between the three points.

Using the formulas that have already been derived in this article we can calculate the distance between point A and B, we can also calculate the bearing from A to B. Once we know this we can calculate the angles and. Once we have these two angles we can calculate the angle using the following formula:

From here we can calculate the distances AC and BC using the following formulas:

We only need to calculate one of the distances. Once we have that we can use the distance, and the point is based at either A of B, and the associated heading to calculate the coordinate of C.

Application

This function for calculating the coordinate of a point using triangulation will take in two VELatLong objects and two bearings that are between 0 and 180 degrees. This function will return a VELatLong object for the point in which the provided information triangulates to. When calculating the angle between two headings we are only interested in the inner angle because we are working with a triangle all the angles will be under 180˚.

`function triangulate(latlongA,latlongB,bearingAC,bearingBC){    var AB = haversineDistance(latlongA,latlongB);    var bearingAB = calculateBearing(latlongA,latlongB);    var angleBAC = angleBetweenHeadings(bearingAB,bearingAC,"inner");    var angleABC = angleBetweenHeadings(180-bearingAB,bearingBC,"inner");    var angleBCA = 180 - angleBAC - angleABC;        var AC = AB*Math.sin(DegToRad(angleABC))/Math.sin(DegToRad(angleBCA));        return calculateCoord(latlongA, bearingAC, AC);}`

Listing 1 Triangulation Function Information on the calculateBearing method can be found here: http://rbrundritt.spaces.live.com/blog/cns!E7DBA9A4BFD458C5!393.entry
Information on the haversineDistance method can be found here: http://rbrundritt.spaces.live.com/blog/cns!E7DBA9A4BFD458C5!317.entry
Information on the calculateCoord method can be found here: http://rbrundritt.spaces.live.com/blog/cns!E7DBA9A4BFD458C5!400.entry