Okay – forgive the messy maths. It’s been a decade since I wrote any serious trigonometry, so this may be a little inefficient. All-in-all, though, I believe it is accurate.

I thought I would need a third image in order to measure Z, but figured it out eventually.

fig.1

Consider fig.1. In it, the blue rectangle is an object seen by the cameras (the black rectangles).

The red lines are the various viewing “walls” of the camera – the diagonals are the viewing angle, and the horizontal lines are the projected images of the real-life objects. We assume that the photographs are taken by the same camera, which is held parallel in the Z axis.

The green triangle portrays the distance between the camera view points, and the distance to the point we are determining. We cannot determine whether the final measurements will be in centimetres, metres, inches, etc, but we can safely assume that no matter what final measurement unit is used, it will be a simple multiple to correct all calculations arising from this.

The only numbers that we can be sure of are the camera angle *C*, the width in pixels of the view screen *c*, and the distance in pixals from the left of the view screens that the projections cross the line *c* – *h* and *j*. As the final measurement unit does not matter, we can safely assign *d* any number we want.

What we are looking for are the distance in *d*-type units for *x* and *z*. We can safely leave *y* out of this for now. It’s a simple matter to work that out.

Right… here goes… We’ll start with the obvious.

*G* = (180-*C*)/2

As there are two equal angles in each of the camera view triangles, the line *f* is one wall of a right-angled triangle. Therefore, using the trig. rule that Tan is the Opposite divided by the Adjacent,

`Tan(`

*G*) = *f*/(*c*/2)

Which, when re-ordered and neatened, gives us

*f*=(Tan(*G*)**c*)/2

We can then work out *B* using the same rule.

`Tan(`

*B*) = *f*/(*h*-(*c*/2))

Which neatens to

*B*=ATan(2*f*/(2*h*-*c*))

Using similar logic,

*A*=ATan(2*f*/(2*k*-*c*))

So, now that we have *A* and *B*, we can work out *D*

`D=180-`

*A*-*B*

An because of the rule that angle sines divided by their opposite sides are the same for any triangle,

*d*/Sin(*D*) = *a*/Sin(*A*)

Therefore

*a* = (*d**Sin(*A*))/Sin(*D*)

And via more simple trig,:

*z* = *a**Sin(*B*)

And

*x* = *a**Cos(*B*)

Tada!

So, to get *z* with one equation:

*z*=((*d**Sin(ATan(2*((Tan((180-*C*)/2)**c*)/2)/(2*k*-*c*))))/Sin(180-(ATan(2*((Tan((180-*C*)/2)**c*)/2)/(2*k*-*c*)))-ATan(2*((Tan((180-*C*)/2)**c*)/2)/(2*h*-*c*))))*Sin(ATan(2*((Tan((180-*C*)/2)**c*)/2)/(2*h*-*c*)))

Obviously, I’ll optimise that a little before writing it into my program…

## Comments are closed.