Skip to content

Instantly share code, notes, and snippets.

@greim
Created January 2, 2014 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greim/8221971 to your computer and use it in GitHub Desktop.
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.
/*
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);
@4e1e0603
Copy link

Why do you use the pow() function? A better way is to use an x * x expression, because there is no function call.

@greim
Copy link
Author

greim commented Jun 10, 2015

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