#### Archived

This topic is now archived and is closed to further replies.

# ellipse algorithm

This topic is 6547 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Can anyone point me to an algorithm that draws an ellipse?

##### Share on other sites
You could probably use the equation of an ellipse. I don''t have it memorized but it should be covered in any trig/geo book. Look under the conics section. There might be a faster method than the ellipse equation though.

ECKILLER

##### Share on other sites
You could do this...

for ( int i = 0; i < 360; i++ )
{
PutPixel(CenterX + HorizontalRadius*cos(i*(PI/180)), CenterY + VerticalRadius*sin(i*(PI/180)), ColorChoice);
}

This will draw an ellipse!

As you probably know, the GDI uses a rectangle to identify where the ellipse should be drawn. Well, here's what I would do if I wanted to code the same function.

  struct RECTANGLE{ long left; long top; long right; long bottom;};void DrawEllipse(RECTANGLE &rect, byte color){ int i; int HorizontalRadius; int VerticalRadius; HorizontalRadius = ( rect.right - rect.left ) / 2; VerticalRadius = ( rect.bottom - rect.top ) / 2; for ( i = 0; i < 360; i++ ) { SetPixel( hDC, rect.left + HorizontalRadius + HorizontalRadius * (float) cos( i * ( 3.14159 / 180 ) ), rect.top + VerticalRadius + VerticalRadius * (float) sin( i * ( 3.14159 / 180 ) ), color ); }}

Hope this helps!

----------------------------------------------
That's just my 200 bucks' worth!

Edited by - Gladiator on July 21, 2000 1:08:56 PM

1. 1
2. 2
3. 3
4. 4
5. 5
Rutin
17

• 10
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631420
• Total Posts
2999987
×