Custom class dependencies: None
Working with vectors – Part 1, Part 2, Part 3
What is a ‘vector’? Well, it is just 2 numbers used for one thing. It is a direction and a distance. You can also call these two things properties, and these properties can also be called the angle and the magnitude.
If you started walking north at one step per second, your vector has an angle of zero degrees, with a magnitude of one step per second. Then you decide to turn east and walk somewhere else at twice the speed, you just changed your vector to an angle of 90 degrees, and a magnitude of two steps per second.
This is the simplest way to calculate motion, but it is also based on the simple principles of trigonometry, which are based on the even more basic principles of geometry.
My first task was to create a utility to do all those useful functions we see all over the internet by Actionscript developers over and over again. These are things that are yet to be built into Actionscript, so we will make our very useful Trig (for trigonometry) class now.
One of the functions implemented in this class is the correctDegree() method. The reason for this is the get around the maximum numeric value. Understand it better by taking a quick look at the example:
[swfobj src=”https://jidd.jimisaacs.com/files/2008/06/example-Trig.swf” width=”550″ height=”300″ align=”center” required_player_version=”10.0.0″]
AS3 Trig Example
Here is the class, please be sure to download this before trying the example, or continuing in the series.
com.jimisaacs.utils.Trig
Comment if you have any questions, or suggestions.
Leave a Reply