Skip to content

Instantly share code, notes, and snippets.

@sibelius
Created July 22, 2020 20:51
Show Gist options
  • Save sibelius/59ca7d9af7388a2e92870c3bb1035992 to your computer and use it in GitHub Desktop.
Save sibelius/59ca7d9af7388a2e92870c3bb1035992 to your computer and use it in GitHub Desktop.
Thales theorem function and inverted
/*
a = minProgress
b = minResult
c = maxProgress
d = maxResult
x = result
y = progress
y = (-ad + ax + bc - cx) / (b - d)
x = (ad - bc + by - dy) / (a - c)
https://www.wolframalpha.com/input/?i=(x-a)%2F(y-b)+%3D+(c-x)%2F(d-y),+solve+to+y
*/
export const thalesTheorem = (
minProgress: number,
maxProgress: number,
minResult: number,
maxResult: number,
result: number,
) => (
(-minProgress * maxResult + minProgress * result + minResult * maxProgress - maxProgress * result)
/ (minResult - maxResult)
);
export const thalesTheoremInverted = (
minProgress: number,
maxProgress: number,
minResult: number,
maxResult: number,
progress: number,
) => (
(minProgress * maxResult - minResult * maxProgress + minResult * progress - maxResult * progress)
/ (minProgress - maxProgress)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment