Forum     

Go Back   Digit Technology Discussion Forum > Portables, Peripherals and Electronics > QnA (read only)
Register FAQ Calendar Mark Forums Read

QnA (read only) Mods please help transfer the contents of this forum to proper sections. :)


 
 
LinkBack Thread Tools Search this Thread Display Modes
Old 22-02-2007, 03:09 AM   #1 (permalink)
 
MysticDews's Avatar
 
Join Date: Nov 2006
Location: Mumbai
Posts: 98
Red face Midpoint Ellipse


I need the source code in C (using Turbo C)to implement the Midpoint Ellipse Drawing Algorithm...

I tried writing it myself, but instead of ellipses, i m getting some wierd shapes...


Please help if possible...
Thnks in advance..
__________________
________________________________________________
In love with my Mac 
________________________________________________
MysticDews is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 22-02-2007, 03:25 AM   #2 (permalink)
String Phreak
 
mediator's Avatar
 
Join Date: Mar 2005
Location: In ur Evil Mind!
Posts: 2,457
Default Re: Midpoint Ellipse

Ur lucky! I had my practical saved.

Quote:
//Mid Point Ellipse Algorithm

#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
void ellipse_midpoint(int x1,int y1,int rx,int ry)
{
int x,y,p,px,py,rx2,ry2,tworx2,twory2;
rx2=rx*rx;
ry2=ry*ry;
tworx2=2*rx2;
twory2=2*ry2;
x=0;
y=ry;
p=abs(ry2-rx2*ry+(0.25*rx2));
px=0;
py=tworx2*y;
while(px<py)
{
x=x+1;
px=px+twory2;
if(p>=0)
{
y=y-1;
py=py-tworx2;
p=p+ry2+px-py;
}
else
{
p=p+ry2+px;
}
putpixel(x1+x,y1+y,1);
putpixel(x1-x,y1+y,1);
putpixel(x1+x,y1-y,1);
putpixel(x1-x,y1-y,1);
}
p=abs(ry2*(x+0.5)*(x+0.5)+rx2*(y-1)*(y-1)-rx2*ry2);
while(y>0)
{
y=y-1;
py=py-tworx2;
if(p<=0)
{
x=x+1;
px=px+twory2;
p=p+rx2-py+px;
}
else
{
p=p+rx2-py;
}
putpixel(x1+x,y1+y,1);
putpixel(x1-x,y1+y,1);
putpixel(x1+x,y1-y,1);
putpixel(x1-x,y1-y,1);
}
}
void main()
{
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "c:\\tc\\bgi");
int x1,y1,rx,ry;
cout<<"Enter the centre point of the Ellipse"<<endl;
cin>>x1>>y1;
cout<<"Enter the length of semiMajor & semiMinor axes"<<endl;
cin>>rx>>ry;
ellipse_midpoint(x1,y1,rx,ry);
getch();
}
__________________
Bad Bad server.....No candy for u!
mediator is offline  
Old 22-02-2007, 03:29 AM   #3 (permalink)
 
MysticDews's Avatar
 
Join Date: Nov 2006
Location: Mumbai
Posts: 98
Default Re: Midpoint Ellipse

^^
hey thanks a lllottt...
i was really fed up trying all possible PnC in those equations...

will try it out...

Thanks again...
__________________
________________________________________________
In love with my Mac 
________________________________________________
MysticDews is offline  
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by Piyush
- by icebags
- by clinton
- by Charan

Advertisement




All times are GMT +5.5. The time now is 12:03 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2