« Building yet another Flash map Easier Animation through Trigonometry »

Why Geometry and I Don’t Get Along

October 14 2004

Here’s the demo that it took me way too long to put together:

I discovered an error in an arc calculations that I was working on. It caused my test object to always gravitate to a fixed arc path on the stage despite any initial values I’d insert. It turns out that the problem was in calculating the y-coordinate value. Going off the standard equation describing a circle (x-h)2 + (y-k)2 = r2 - I had calculated the formula to solve for y (given only a starting x-value (xFirst) and an ending x-value (xLast) as:

y = square root of (((xLast-xFirst)/2)2 - (x -(xFirst+((xLast-xFirst)/2)))2)

This is correct except that it neglects any initial y-value greater than 0. If the arc is to be displaced off the baseline you have to add the original y-displacement to the answer;

y = square root of (((xLast-xFirst)/2)2 - (x -(xFirst+((xLast-xFirst)/2)))2) + yFirst

It is also important to note that in Flash the grid isn’t a standard Cartesian numbered grid. The origin is in the top left and increases values both down and to the right. Which means you need to multiply by -1 to get things arcing in the “proper” orientation.

Comments ()