ELLIPSE GENERATING ALGORITHM
#1

ELLIPSE GENERATING ALGORITHM
EX.NO:3(a)
DATE:

AIM:

To write a C program to draw an ellipse using the mid point ellipse algorithm.

ALGORITHM:


1. Get the radius (rx,ry) and the center of the ellipse (xc,yc).
2. Obtain the first point on the ellipse centered on the origin as (x0,y0)=(0,ry)
3. Calculate the initial value of the decision parameter in region 1 as p10=ry2-rx2ry+rx2/4
4. At each xk position in region 1,starting at k=0,perform the following test:
a. If p1k<0,the next point along the ellipse centered on (0,0) is(xk+1,yk) and the decision parameter is p1k+1=p1k+2ry2xk+1+ry2
b. Else the other point is (xk+1,yk-1) and the decision parameter is p1k+1=p1k+2ry2xk+1-2rx2yk+1+ry2¬,where 2ry2xk+1=2ry2xk+2ry2 and
2rx2yk+1=2rx2yk-2rx2
5. Calculate the initial value of the decision parameter in region 2 as p20=ry2(x0+1/2)2+rx2(y0-1)2-rx2ry2
6. At each yk position in region 2,starting at k=0 perform the following test:
a. If p2k>0 ,the next point along the ellipse centered on (0,0) is (xk,yk-1) and the decision parameter is p2k+1=p2k-2rx2yk+1+ rx2
b. Else the next point is (xk+1, yk-1) and the decision parameter is
p2k+1= p2k+2ry2xk+1-2rx2yk+1+ rx2 where 2ry2xk+1=2ry2xk+2ry2 and
2rx2yk+1=2rx2yk-2rx2
7. Determine the symmetry points in other three quadrants
8. Move the calculated pixel position (x,y) onto the circular path centered on (xc,yc) and plot the co-ordinate values
a. x=x+xc
b. y=y+yc
9. Repeat steps for region 1 until 2ry2xk>=2rx2y then goto region 2
10. Stop.


Code:
PROGRAM CODE:

#include<stdio.h>
#include<graphics.h>
#include<math.h>
#include<conio.h>
void main()
{
         float x,y,rx2,ry2,p1,p2;
         int xc,yc,gm,gd=DETECT,rx,ry;
              printf("ENTER RX AND RY:");
         scanf("%d %d",&rx,&ry);
        printf("ENTER THE CO-ORDINATES OF THE CENTER:");
       scanf("%d %d",&xc,&yc);
         initgraph(&gd,&gm,"  ");
          putpixel(xc,yc,15);
          x=0;
         y=ry;
         rx2=pow(rx,2);
         ry2=pow(ry,2);
          p1=ry2-(rx2*ry)+(0.25*rx2);
         while((ry2*x)<(rx2*y))
         {
        if(p1<0)
        {    x++;
            p1=p1+(2*ry2*x)+ry2;
        }
        else
        {
            x++;            y--;
            p1=p1+(2*ry2*x)-(2*rx2*y)+ry2;
        }
        putpixel(xc+x,yc+y,15);
        putpixel(xc-x,yc+y,15);
        putpixel(xc+x,yc-y,15);
        putpixel(xc-x,yc-y,15);
         }
         p2=(ry2)*pow((x+0.5),2)+(rx2)*pow((y-1),2)-(rx2*ry2);
         while(y>0)
         {
        if (p2>0)
        {
            y--;
            p2=p2-(2*rx2*y) +rx2;
        }
        else
        {
            x++;            y--;
            p2=p2+ (2*ry2*x)-(2*rx2*y)+rx2;
        }
        putpixel(xc+x,yc+y,15);
        putpixel(xc-x,yc+y,15);
        putpixel(xc+x,yc-y,15);
        putpixel(xc-x,yc-y,15);
         }
         getch();
       closegraph();
}

OUTPUT:




RESULT:

Thus a C program to draw an ellipse using mid point ellipse algorithm has been executed successfully.
Reply
#2
Thanks frnd... its very useful to me....
lots of thanks again...

hey do u ve a small and sample projects in c...
bcus i need some proj for my final year project... and also how do design a proj in 'C' looks more smart and cute....
so if u have any C proj plz send to me..

its my humble request to u..

MY ID: prasanaa87[at]gmail.comBig GrinSmile
Reply
#3

i will add it soon ....

Reply

Important Note..!

If you are not satisfied with above reply ,..Please

ASK HERE

So that we will collect data for you and will made reply to the request....OR try below "QUICK REPLY" box to add a reply to this page
Tagged Pages: ellipse generating algorithm with example,
Popular Searches: peppara generating station, power generating suspension system report, abstract on midpoint ellipse algorithm in java, example of ellipse algorithm in computer graphics, proj playlist, ellipse algorithm in computer graphics ppt, midpoint algorithm for ellipse ppt,

[-]
Quick Reply
Message
Type your reply to this message here.

Image Verification
Please enter the text contained within the image into the text box below it. This process is used to prevent automated spam bots.
Image Verification
(case insensitive)

Possibly Related Threads...
Thread Author Replies Views Last Post
  An Efficient Algorithm for Mining Frequent Patterns full report project topics 3 4,806 01-10-2016, 10:02 AM
Last Post: Guest
  watermarking algorithm seminar class 3 2,690 27-04-2016, 11:17 AM
Last Post: dhanabhagya
  DYNAMIC SEARCH ALGORITHM IN UNSTRUCTURED PEER-TO-PEER NETWORKS--PARALLEL AND DISTRIBU electronics seminars 9 7,400 14-07-2015, 02:25 PM
Last Post: seminar report asees
  TEA ENCRYPTION (ALGORITHM) computer science technology 1 2,673 11-11-2014, 10:45 AM
Last Post: Guest
  A TABU SEARCH ALGORITHM FOR CLUSTER BUILDING IN WIRELESS SENSOR NETWORKS- MOBILE COMP electronics seminars 1 2,083 01-12-2012, 12:06 PM
Last Post: seminar details
  A Tabu Search Algorithm for Cluster Building in Wireless Sensor Networks Electrical Fan 13 8,746 01-12-2012, 12:05 PM
Last Post: seminar details
  A ROBUST DIGITAL IMAGE WATERMARKING ALGORITHM USING DNA SEQUENCES smart paper boy 1 1,954 29-11-2012, 01:42 PM
Last Post: seminar details
  Medical image segmentation using clustering algorithm computer science technology 2 6,018 08-11-2012, 01:00 PM
Last Post: seminar details
  Design and Analysis of the Gateway Relocation and Admission Control Algorithm in Mobi Projects9 1 1,721 10-10-2012, 12:22 PM
Last Post: seminar details
  RED BLACK TREE ALGORITHM FULL REPORT seminar class 1 2,130 08-10-2012, 12:59 PM
Last Post: seminar details

Forum Jump: