Return to Snippet

Revision: 16719
at August 13, 2009 08:03 by alexaivars


Updated Code
/*
		* This functions returns an array containing 36 points to draw an
		* ellipse.
		*
		* @param x {double} X coordinate
		* @param y {double} Y coordinate
		* @param a {double} Semimajor axis
		* @param b {double} Semiminor axis
		* @param angle {double} Angle of the ellipse
		*/

		private function calculateEllipse(x:Number, y:Number, a:Number, b:Number, angle:Number, steps:Number = 36 ):Array 
		{
			var points:Array = [];
			
			// Angle is given by Degree Value
			var beta:Number = -angle * (Math.PI / 180); //(Math.PI/180) converts Degree Value into Radians
			var sinbeta:Number = Math.sin(beta);
			var cosbeta:Number = Math.cos(beta);
		 
			for (var i:Number = 0; i < 360; i += 360 / steps) 
			{
				var alpha:Number = i * (Math.PI / 180) ;
				var sinalpha:Number = Math.sin(alpha);
				var cosalpha:Number = Math.cos(alpha);
				 
				var X:Number = x + (a * cosalpha * cosbeta - b * sinalpha * sinbeta);
				var Y:Number = y + (a * cosalpha * sinbeta + b * sinalpha * cosbeta);
				 
				points.push(new Point(X, Y));
			}
		 
			return points;
		}

Revision: 16718
at August 13, 2009 08:01 by alexaivars


Initial Code
/*
* This functions returns an array containing 36 points to draw an
* ellipse.
*
* @param x {double} X coordinate
* @param y {double} Y coordinate
* @param a {double} Semimajor axis
* @param b {double} Semiminor axis
* @param angle {double} Angle of the ellipse
*/
function calculateEllipse(x:Number, y:Number, a:Number, b:Number, angle:Number, steps:Number):Array 
{
  if (steps == null)
    steps:Number = 36;
  var points = [];
 
  // Angle is given by Degree Value
  var beta:Number = -angle * (Math.PI / 180); //(Math.PI/180) converts Degree Value into Radians
  var sinbeta:Number = Math.sin(beta);
  var cosbeta:Number = Math.cos(beta);
 
  for (var i:Number = 0; i < 360; i += 360 / steps) 
  {
    var alpha:Number = i * (Math.PI / 180) ;
    var sinalpha:Number = Math.sin(alpha);
    var cosalpha:Number = Math.cos(alpha);
 
    var X:Number = x + (a * cosalpha * cosbeta - b * sinalpha * sinbeta);
    var Y:Number = y + (a * cosalpha * sinbeta + b * sinalpha * cosbeta);
 
    points.push(new Point(X, Y));
   }
 
  return points;
}

Initial URL


Initial Description


Initial Title
Calculate Ellipse

Initial Tags


Initial Language
ActionScript 3