CS2405 Two Dimensional transformations - Translation, Rotation, Scaling, Reflection, Shear. - Code

Latest

programs

Monday, June 20, 2011

CS2405 Two Dimensional transformations - Translation, Rotation, Scaling, Reflection, Shear.

CS2405 Two Dimensional transformations - Translation, Rotation, Scaling, Reflection, Shear.


ELLIPSE DRAWING

AIM:
               To write a program to draw a ellipse using Bresenham’s ellipse drawing Algorithm.

FUNCTIONS USED:

initgraph().

       This function takes thee arguments and they are
         i).the video driver to be used (gd).
         ii).the graphics mode (gm).
         iii).the path name.
Syntax:

       Initgraph(gd,gm,path)

Putpixel ()

      The function putpixel() is used to place a pixel at particular coordinate

Syntax:

         Putpixel(x,y,color)


ALGORITHM:

Step 1: Start
Step 2: Get the center point as(x1, y1)
Step 3: Get the length of semi-major, semi-minor axes as r1 & r2
Step 4: Calculate t=pi/180
Step 5: Initialise i=0;
Step 6: Compute d=i*t
Step 7: Compute x=x1+y1*sin(d), y=y1+r2*cos(d).
Step 8: Put a pixel on(x,y)
Step 9: Increment I by 1
Step 10: Repeat steps(6) to (9) until i<360
Step 11: Stop
PROGRAM:

#include<iostream.h>
#include<graphics.h>
#include<conio.h>
#include<math.h>
void main()
{
int gd=DETECT,gm,x1=0,y1=0,r1=0,r2=0;
float x=0,y=0,t,d,i;
initgraph(&gd,&gm,"");
cout<<"enter the center co-or:";
cin>>x1>>y1;
cout<<"enter  the radius1:";
cin>>r1;
cout<<"enter radius2:";
cin>>r2;
for(i=0;i<360;i++)
{
t=3.14/180;
d=i*t;
x=x1+ceil(r1*sin(d));
y=y1+ceil(r2*cos(d));
putpixel(x,y,15);
}
getch();
closegraph();
}

INPUT:

Enter the center co-or:100 150
Enter the radius1:40
Enter radius2:20

OUTPUT:








RESULT:
             Thus the program is executed and verified.

No comments:

Post a Comment