Posted By

alexaivars on 08/13/09


Tagged

triangle sin ellipse Sinus Cirlce


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

toxin20
davidino1978


Calculate Ellipse


 / Published in: ActionScript 3
 

  1. /*
  2. * This functions returns an array containing 36 points to draw an
  3. * ellipse.
  4. *
  5. * @param x {double} X coordinate
  6. * @param y {double} Y coordinate
  7. * @param a {double} Semimajor axis
  8. * @param b {double} Semiminor axis
  9. * @param angle {double} Angle of the ellipse
  10. */
  11.  
  12. private function calculateEllipse(x:Number, y:Number, a:Number, b:Number, angle:Number, steps:Number = 36 ):Array
  13. {
  14. var points:Array = [];
  15.  
  16. // Angle is given by Degree Value
  17. var beta:Number = -angle * (Math.PI / 180); //(Math.PI/180) converts Degree Value into Radians
  18. var sinbeta:Number = Math.sin(beta);
  19. var cosbeta:Number = Math.cos(beta);
  20.  
  21. for (var i:Number = 0; i < 360; i += 360 / steps)
  22. {
  23. var alpha:Number = i * (Math.PI / 180) ;
  24. var sinalpha:Number = Math.sin(alpha);
  25. var cosalpha:Number = Math.cos(alpha);
  26.  
  27. var X:Number = x + (a * cosalpha * cosbeta - b * sinalpha * sinbeta);
  28. var Y:Number = y + (a * cosalpha * sinbeta + b * sinalpha * cosbeta);
  29.  
  30. points.push(new Point(X, Y));
  31. }
  32.  
  33. return points;
  34. }

Report this snippet  

You need to login to post a comment.