-->
Program to draw a polygon by accepting vertex coordinates and perform shear and reflections about x and y axes based on user’s choice. -MASTER GUIDE

Program to draw a polygon by accepting vertex coordinates and perform shear and reflections about x and y axes based on user’s choice. -MASTER GUIDE

Program to draw a polygon by accepting vertex coordinates and perform shear and reflections about x and y axes based on user’s choice. 

 #include<stdio.h>

#include<conio.h>

#include<graphics.h>


void input();

void drawobj();

void shearing();

void reflection();


float x[10],y[10],rf,sh;

int axis,ch,n,i;

int maxx=640,maxy=480,midx=320,midy=240;


void input()

{

printf("Enter the number of vertices:" );

scanf("%d",&n);

for(i=0;i<n;i++)

{

printf("Enter the x and y coordinates:");

  scanf("%f%f",&x[i],&y[i]);

}

printf("Original Objects\n");

setcolor(WHITE);

line(midx,0,midx,maxy);

line(0,midy,maxx,midy);

outtextxy(midx-2,midy+2,"0,0");

drawobj();

getch();

}

void drawobj()

{

for(i=0;i<n-1;i++)

line(midx+x[i],midy-y[i],midx+x[i+1],midy-y[i+1]);

line(midx+x[i],midy-y[i],midx+x[0],midy-y[0]);

}

void shearing()

{

printf("Enter the shear value:");

scanf("%f",&sh);

printf("Enter the axis for shearing \n[ x-axis --> 0 ] or [ y-axis --> 1 ]:");

scanf("%d",&axis);

printf("Enter the reference line value:");

scanf("%f",&rf);

for(i=0;i<n;i++)

{

if(axis==0)

x[i]=x[i]+ sh*(y[i]-rf);

else

y[i]=y[i]+ sh*(x[i]-rf);

}

setcolor(RED);

drawobj();

getch();

}

void reflection()

{

printf("enter the reflection about \n[ x-axis --> 0 ] or [ y-axis --> 1 ]:");

scanf("%d",&axis);

for(i=0;i<n;i++)

{

if(axis==0)

y[i]=(-1)*y[i];

  else

  x[i]=(-1)*x[i];

}

setcolor(RED);

drawobj();

getch();

}

void main()

{

int gd=DETECT,gm;

initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");

while(1)

{

clrscr();

cleardevice();

printf("Menu\n");

printf("1.Shearing\n");

printf("2.Reflection\n");

printf("3.exit\n");

printf("enter the choice:");

scanf("%d",&ch);

switch(ch)

{

case 1:

input();

shearing();

break;

case 2:

input();

reflection();

break;

case 3:

closegraph();

exit();

}

}

}


OUTPUT:


Baca Juga



Related Posts

0 Response to "Program to draw a polygon by accepting vertex coordinates and perform shear and reflections about x and y axes based on user’s choice. -MASTER GUIDE"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel