Advertisement

Some math for someone to solve

Started by November 09, 2000 01:36 PM
1 comment, last by psychic_treason 24 years, 2 months ago
Hi anyone that can solve this for me. I''m completely brain dead at this point in the day and I need to solve an issue that I have. I''m working on a game in flash that requires me to rotate some objects. Basically it''s 2D so not too big an issue, and I have the X and Y vectors already. What I need to do is work out the ANGLE that I need to rotate the object so it is pointing in the same direction as the vector it is following. So, simple thing yeah? Well I know that in standard trig all I''d have to do is say Tan Theta = Y / X All we then need to do is use an Inverse Tan function on the result.... Problem is, Flash doesn''t have inverse Tan, Sin or Cos functions so I need to get another way to do it. Any solutions would be SOOOOO appreciated in a speedy fashion. Thanks. Pyschic -- Guard your mind. You never know who is listening --
-- That's my $0.02 worth --
Hang on, where I come from, $0.02 is rounded down. Does that mean my opinion is worthless or priceless?
CHROM
An approximation to arctangent can be found with the following exapansion:

arctan(x) = x - ((x ^ 3) / 3) + ((x ^ 5) / 5) - ((x ^ 7) / 7) + ((x ^ 9) / 9)) - ...

This will only converge for x within a certain range, so outside that range you''ll have to use your trignometric identities in order to reduce it to a computation in that range.
Advertisement
Flash 5 has those functions. The best for general purposes is atan2(x,y). Otherwise, a common hack is to do a table lookup.

This topic is closed to new replies.

Advertisement