[Math] How to calculate width of Trapezoid at any point

geometry

I am working on a Guitar application and so have a trapezoid as the fretboard. I am currently writing code to display the frets along the fretboard, but am stuck trying to calculate what the width is for each fret – I have calculated each fret's distance from the nut (top of fretboard) but it's the width, as in the shorter side, that I now need. Obviously, calculating the median width is straightforward but I have 22 frets and the distance between each one decreases the higher up the fretboard you go.

Could someone please suggest a formula, given that I know the length of all 4 sides, and know the X position of each fret? There are spreadsheets available online for luthiers that have a formula I could use, but I would far rather understand the calculation.

Thanks!

Best Answer

If the trapezoid has height $h$ and corners: $$(a,0),\ (b,0),\ (c,h),\ (d,h)$$ Then at height $y$ the left side $x_1$ will be between $a$ and $c$, and due to triangle similarity: $$\frac{c - x_1}{c-a} = \frac{h - y}{h} \ \ \to\ \ x_1 = c - (c-1)\frac{h - y}{h}$$ The same holds for the point $x_2$ on the right: $$x_2 = d - (d-1)\frac{h - y}{h}$$