Created
January 2, 2014 16:36
-
-
Save greim/8221971 to your computer and use it in GitHub Desktop.
I'm building a decorative wooden header for some shelves with arches cut out at the top. The board was 5" wide and I wanted the arch to be half that, so I wrote this program to calculate the radius.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
For an arch with a rise of X, what's the radius. | |
Start with this right triangle: | |
b | |
| | |
a----------------c | |
a = left edge of arch | |
b = top of arch | |
c = midpoint of arch | |
d = midpoint of ab | |
e = center of circle | |
*/ | |
var ac = 11.375; | |
var bc = 2.5; | |
var abc = Math.atan(ac / bc); | |
var ab = Math.sqrt(Math.pow(ac, 2) + Math.pow(bc, 2)); | |
var db = ab / 2; | |
var de = Math.tan(abc) * db; | |
var be = Math.sqrt(Math.pow(db, 2) + Math.pow(de, 2)); | |
console.log(be); |
Ha. Didn't see this until a year and a half later. Maybe that would be a useful micro-optimization, but in this case I was mainly interested in dialing in the formula so that I cut a piece of wood correctly with a jigsaw. (AKA using Chrome console as a calculator.) So the explicitness of the code trumped shaving off a few microseconds.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why do you use the
pow()
function? A better way is to use anx * x
expression, because there is no function call.