Alan Quatermain

The Tumblog of one Jim Dovey, iOS Software Chief Architect at Kobo in Toronto, Ontario.
He Twitters, he has an , and can occasionally be found on LinkedIn or Facebook.
If you have a query, you can ask it here.

This blog contains personal opinions, and is not endorsed by any company.

109089093
I love Wolfram Alpha. I was trying to concoct an algorithm for testing circle intersections using bounding rectangles (to reduce the number of sine/cosine/tangent/modulo operations in some code posted on StackOverflow) and wanted to know about any optimizations of Pythagoras’ Theorem for the case where a right-angled triangle had two sides of identical length (circles touching at a 45° angle). My idea was that knowing this value could provide the means to optimize the intersection calculations for like-sized circles.
So, I wanted to know if there was a reduction available for the function x = √(y² + y²). Simple, type it into Wolfram Alpha and you get the answer above, and more. But the main thing it showed was that I could introduce a constant — √2 — which can be either calculated once or simply hard-coded. It also included (but curiously didn’t reduce further) the √y², which is basically y as-is. So the whole thing in fact reduces to:
x = √2 × y
That makes for a very simple calculation, and can further be used as the basis for another simple calculation to scale/alter that value for different vectors between the two circles’ centres.
Edit: I’ve been reminded that since raising to a positive power always returns a positive result, I really need to use abs(y), not just y in the final result, so:
x = √2 × abs(y)

I love Wolfram Alpha. I was trying to concoct an algorithm for testing circle intersections using bounding rectangles (to reduce the number of sine/cosine/tangent/modulo operations in some code posted on StackOverflow) and wanted to know about any optimizations of Pythagoras’ Theorem for the case where a right-angled triangle had two sides of identical length (circles touching at a 45° angle). My idea was that knowing this value could provide the means to optimize the intersection calculations for like-sized circles.

So, I wanted to know if there was a reduction available for the function x = √(y² + y²). Simple, type it into Wolfram Alpha and you get the answer above, and more. But the main thing it showed was that I could introduce a constant — √2 — which can be either calculated once or simply hard-coded. It also included (but curiously didn’t reduce further) the √y², which is basically y as-is. So the whole thing in fact reduces to:

x = √2 × y

That makes for a very simple calculation, and can further be used as the basis for another simple calculation to scale/alter that value for different vectors between the two circles’ centres.

Edit: I’ve been reminded that since raising to a positive power always returns a positive result, I really need to use abs(y), not just y in the final result, so:

x = √2 × abs(y)

2 notes

  1. quatermain posted this