Jump to content
  • Advertisement

Archived

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

bschertz42

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.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
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!

..-=gLaDiAtOr=-..

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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!