Wednesday, June 20, 2012

The Math and ActionScript of Curves: Gradients and Normals

This entry is part 3 of 3 in the series The Math and ActionScript of Curves
We’ve tackled drawing curves, and finding their quadratic and cubic roots, as well as handy applications for using quadratic roots within games. Now, as promised, we’ll look at applications for finding cubic roots, as well as curves’ gradients and normals, like making objects bounce off curved surfaces. Let’s go!


Example

Let’s take a look one practical use of this math:
In this demo, the “ship” bounces off the edges of the SWF and the curve. The yellow dot represents the closest point to the ship that lies on the curve. You can adjust the shape of the curve by dragging the red dots, and adjust the movement of the ship using the arrow keys.

Step 1: Shortest Distance to a Curve

Let’s consider the scenario where a point is located near a quadratic curve. How do you calculate the shortest distance between the point and the curve?
point to quadratic distance
Well, let’s start with Pythagoras’s Theorem.
Read more: The Math and ActionScript of Curves: Gradients and Normals

No comments:

Post a Comment