ellipse algorithm

Started by
1 comment, last by bschertz42 23 years, 8 months ago
Can anyone point me to an algorithm that draws an ellipse?
Advertisement
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
ECKILLER
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!

..-=gLaDiAtOr=-..

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

This topic is closed to new replies.

Advertisement