Archived

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

bschertz42

ellipse algorithm

Recommended Posts

ECKILLER    122
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 this post


Link to post
Share on other sites
Gladiator    127
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

Share this post


Link to post
Share on other sites