Throughout my life I have come across a variety of reasons to calculate the distance between points. Some have been basic linear distances, some as complex as finding a distance between two points on a geodesic ellipsoid.

Below are a list of formulas and tools to calculate the values of various distances, angles, and ratios required to calculate distances. This article will cover 2D linear lengths, 3D linear lengths and Arc segment lengths.

Linear Distances on a 2D plane

For linear distances on a 2D plane, the coordinate variables X and Y are used to represent values on the Xaxis and Yaxis. Each distance needs 2 points, each point having an X and Y coordinate value. For the first point, named pA, we can see that it has the coordinate value -2.75,+0.85 or X = -2.75 and Y = +0.85.the points pB and pC can be separated into individual coordinate values as well.

Parallel Line Segments

For line segment sA we need to know the distance between point pA and point pB. As this particular line is parallel to the X axis, we can ignore the Y coordinate value. The basic formula for this distance is

pB.Xcoordinate – pA.Xcoordinate => (+4.75) – (-2.75) => 4.75 + 2.75 = 7.50.

Non-Parallel Line Segments

For line segment sB we need to know the distance between point pA and point pC. Since this line segment is not parallel we need to incorporate the Y axis coordinates. The calculation is as follows: √(pC.X – pA.X)^2 + (pC.Y – pA.Y)^2

Working from the center out:

  • First the X axis; (pC.X – pA.X)^2 => (+4.75) – (-2.75) => Abs(4.75 + 2.75) = 7.50^2 = 56.25. (Xval = 56.25)
  • Next the Y axis; (pC.Y – pA.Y)^2 => (-0.85) – (+0.85) => Abs(-0.85 – 0.85) => 1.70^2 = 2.89. (Yval = 2.89)
  • Note: Absolute values are required, Abs() simply removes any negative sign and returns a positive.

First you take the 2nd points X axis value and subtract that from the 1st point’s X axis value. That value is then squared to give you a new value for the combined X axis values. Repeat the same process for the Y axis values.

With the 2 solutions above; √Xval + Yval => √56.25 + 2.89 => √59.14 = 7.69….

Finally you add the X and Y axis values together and find the square root of the number, which is the length between the two described points.

The length of line segment sB is 7.69 units in length where as the parallel line segment sA has a length of 7.50 units.

Linear Distances on a 3D plane

Following the concepts of finding a distance in 2 dimensions, we can also find a distance between two points in 3-dimensional space.

Let’s start by adding a Z axis value to the line segment sB that consists of points pA and pC. Let’s add a Z coordinate value to the ordered pair pA redefining the 2D point [x,y] as a 3D point [x,y,z] with the values; +4.75,-0.85,-1.25. Replicating the same process for point pC and assigning the values; -2.75,+0.85,+1.50.

Continuing from the above bullet points we can now process the new Zval in the same manner as the Xval and Yval were set.

  • Additionally, the Z axis; (pC.Z – pA.Z)^2 => (+1.50) – (-1.25) => Abs(1.50 + 1.25) = 2.75^2 = 7.56….(Zval = 7.56)
  • With all 3 solutions; √Xval + Yval + Zval => √56.25 + 2.89 + 7.56 => √66.7 = 8.167….

The length of line segment sB in 3D space is 8.17 units in length whereas the 2D line segment sB is 7.69 units in length.


Station Markers

These calculations can be used for station markers as well. Let’s look at a common station format: STA. 400+75 E 85′ R. This is a different way of formatting a coordinate system. We will assume that our alignment travels parallel to the X axis. As we are heading East we will look only at the right side of the X axis.

To get a X coordinate value; the first sets of numbers 400+75 are used. Simply add these 2 numbers to get a distance along the X axis (X = +475).

To get a Y coordinate value; we take the last number and direction of offset (85′ R) to get the Y distance along the Y axis. Heading East, an offset to the right would be on the negative side of the Y axis while conversely, an offset to the lrft would be a distance along the positive portion of the Y axis. (Y = -85)

Here you can see we have described point pC from above with station marker [x,y] = (+475,-85)/100 = +4.75,-0.85



Arc Distances

When the angle between points is known:

To find the distance between two points along an arc some values need to be known, let us define them; pA will be the beginning point along the curve, pB will be the end point, pC will be the center point of the arc.


  • First, the distance between point pC and pA. Let this value be assigned to the symbol R. (R = 420)
  • Second, the angle between line segments sA and sB. Let this value be assigned to the symbol C. (C = 114)
  • Thirdly, the value of pi (3.142…)
  • Using this information, the Arc Length can be found with the following formula: 2*pi*R(C/360) => 2*3.142*420(144/360) => 2,639.28(0.4) = 1055.71…

Note that increasing the accuracy of pi also increases the accuracy of the measurement. Where pi = 3.14159 the result would be 1055.57..

When the angle is unknown: Slope and Tan(y/x)

If the angle between line segment sA and sB is unknown a formula will be needed to calculate this value. This can be accomplished using slopes. A slope is also equal to TanΘ.

pA = 1,2 | pB = 4,3 | pC = 3,1

  • Firstly, the slope of line segment sA between points pC and pA can be calculated as such; pA.Y – pC.Y / pA.X – pC.X => Abs(2 – 1) / Abs(1 – 3) => 1/2 = 0.5 (S1 = 0.5)
  • Note: SinΘ => pA.Y – pC.Y | CosΘ => pA.X – pC.X
  1. TanΘ => SinΘ/CosΘ => Yval/Xval => 1/2 = 0.5
  • Second, the slope of line segment sB between points pC and pB can be calculated as such; pB.Y – pC.Y / pB.X – pC.X => Abs(3 – 1) / Abs(3 – 4) => 2/1 = 2 (S2 = 2.0)
  1. TanΘ => SinΘ/CosΘ => Yval/Xval => 2/1 = 2
  • Next. ArcTangents of the two values are needed. See the below section to calculate ArcTan without a calculator.
  • ArcTan(.5) = 26.565° + ArcTan(2) = 63.434°
  • 180° – 26.565° – 63.434° = 90.001°

ArcTan(Tan) / Tan-1(Tan)

You can grab a calculator OR we can create a function to calculate the value required. To calculate the ArcTan of a number we have to use an infinite number series. As the number of calculations increases, the accuracy of the output is increased. The following formula is used: ArcTan = Tan – Tan^3/3 + Tan^5/5 – Tan^7/7 + Tan^9/9 … …

  • Line segment sA:
  1. Set the value of the slope to symbol T [tangent value]
  2. Set the value of symbol T to symbol AT [arctan value]
  3. Set the number of calculations to symbol C [calculation count]
  4. Set a Boolean value of True to the symbol O [operator switch]
  5. Create a loop that sets a value of 3 to symbol I [iteration count]
  6. Set the loop to operate in steps of 2 between I and C * 2 + 3
for I = 3 to C*2+3 step 2

    If O then AT -= Tan^I/I; O = False

    ElseIf Not(O) then AT += Tan^I/I; O = True

Next

The pseudo code above will trigger the first If and set ArcTan value to Tan – Tan^3/3 and set the operator switch to False. The next loop, the ElseIf will trigger and the next portion of the formula is added to the total value; + Tan^5/5. The operator switch is toggled again to trigger the first If statement adding; – Tan^7/7.

ArcTan = Tan – Tan^3/3 + Tan^5/5 – Tan^7/7 + Tan^9/9 …..