Skip to content

Useful Trig Methods

by Colin on November 9th, 2009

I've recently been working on a physics/trigonometry project at home using Processing and memo's amazing MSARemote. In short, I realized I haven't posted anything on Tomorrow Evening in ages, I have a lot of cool things up my sleeve right now, just trying to find time to get all these ideas out. I'll be taking all of Thanksgiving week off to take a break from work and do some fun experiments. If I weren't a web developer I'd turn my internet off for a few weeks, I keep finding such great developers/art online that I start something new every other day and never finish what I was working on the day before! That needs to end soon :P. I know I said I was doing a Processing experiment and this code is in AS3 but I have a good reason why! My wordpress doesn't know how to format processing code and since it's only a few lines, I converted it to AS3.

  1. function findDistance(x1:Number, y1:Number, x2:Number, y2:Number) : Number{
  2. var xd:Number = x1 - x2;
  3. var yd:Number = y1 - y2;
  4. var td:Number = Math.sqrt(xd * xd + yd * yd);
  5. return td;
  6. }
  8. function findAngle(x1:Number, y1:Number, x2:Number, y2:Number) : Number{
  9. var xd:Number = x1 - x2;
  10. var yd:Number = y1 - y2;
  12. var t:Number = Math.atan2(yd,xd);
  13. var a:Number = 180 + (-(180 * t) / Math.PI);
  14. return a;
  15. }

From → Flash

No comments yet

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS