Reflection And Shearing In Computer Graphics Program

  1. Reflection And Shearing In Computer Graphics Programming
GraphicsReflection And Shearing In Computer Graphics ProgramReflection and shearing in computer graphics c program

In this, we have performed a shearing transformation on a rectangle. Program for shearing a rectangle along the x-axis. Program: #include #includegraphics.h. 2D Reflection Computer Graphics. The Reflection is a mirror image of the original object. In the Reflection process, the size of the object does not change. We can represent Reflection by using four ways-Reflection along X-axis: In this kind of Reflection, the value of X is positive, and the value of Y is negative. This program is for the reflection and sharing of triangle. Here the lower first quadrant triangle is reflected to upper first quadrant, the resultant triangle is again reflected to upper second quadrant similarly the process is continue. In case of sharing two option are shown sharing on x-axis and y-axis. 2D transformation for reflection in C program (Computer Graphics). February 26, 2019 Program. 2D transforamation for shear in x axis in C progra. 3d shearing reflection program, Search on 3d shearing reflection program. Resource Type: Posted On: Program to show the 3D Shearing Transformation along x-axis.

Reflection And Shearing In Computer Graphics Programming

/* This program will reflect an object ( triangle ) about X- axis, Y- axis and Y=X axis */
#include<graphics.h>
#include<math.h>
#include<conio.h>
#include<stdio.h>
void main()
{
int gd=DETECT,gm;
int i,xmid,ymid,x1,y1,x2,y2,x3,y3,x,y,dy,dx,p,gap=50,temp,option;
int x1dash,x2dash,x3dash,y1dash,y2dash,y3dash;
double theta;
float m;
char str[5];
clrscr();
initgraph(&gd,&gm,'..bgi');
printf('Enter first co-ords of the trianglen');
scanf('%d %d',&x1,&y1);
printf('Enter second co-ords of the trianglen');
scanf('%d %d',&x2,&y2);
printf('Enter third co-ords of the trianglen');
scanf('%d %d',&x3,&y3);
xmid= getmaxx()/2;
ymid= getmaxy()/2;
line(5,ymid,getmaxx()-5,ymid);
line(xmid+3,5,xmid+3,getmaxy()-5);
for( i= xmid+gap;i<getmaxx()-5;i=i+gap)
{
outtextxy(i,ymid-3,'|');
itoa(i-xmid,str,10);
outtextxy(i,ymid+3,str);
}
for( i= ymid-gap;i>5;i=i-gap)
{
outtextxy(xmid,i,'-');
itoa(ymid-i,str,10);
outtextxy(xmid+5,i,str);
}
for( i= xmid-gap;i>5;i=i-gap)
{
outtextxy(i,ymid-3,'|');
itoa(-(xmid-i),str,10);
outtextxy(i-6,ymid+3,str);
}
for( i= ymid+gap;i<getmaxy()-5;i=i+gap)
{
outtextxy(xmid,i,'-');
itoa(-(i-ymid),str,10);
outtextxy(xmid+8,i,str);
}
line(x1+xmid,ymid-y1,x2+xmid,ymid-y2);
line(x2+xmid,ymid-y2,x3+xmid,ymid-y3);
line(x3+xmid,ymid-y3,x1+xmid,ymid-y1);
setcolor(255);
printf('Reflection about n');
printf('X axis : 1n');
printf('Y axis : 2n');
printf('X=Y axis : 3n');
printf(' Enter the option (1-3):');
scanf('%d',&option);
switch( option)
{
case 1: y1=-y1; y2=-y2;y3=-y3; break;
case 2: x1=-x1;x2=-x2;x3=-x3;break;
case 3: y1=-y1; y2=-y2;y3=-y3;
theta= ((double) 90 *3.14f )/(double)180;
x1dash=x1*cos(theta)-y1*sin(theta);
x2dash=x2*cos(theta)-y2*sin(theta);
x3dash=x3*cos(theta)-y3*sin(theta);
y1dash=x1*sin(theta)+y1*cos(theta);
y2dash=x2*sin(theta)+y2*cos(theta);
y3dash=x3*sin(theta)+y3*cos(theta);
x1=x1dash;x2=x2dash;x3=x3dash;
y1=y1dash;y2=y2dash;y3=y3dash;
}
line(x1+xmid,ymid-y1,x2+xmid,ymid-y2);
line(x2+xmid,ymid-y2,x3+xmid,ymid-y3);
line(x3+xmid,ymid-y3,x1+xmid,ymid-y1);
getch();
closegraph();
}
Sample Input :
x1 ,y1 : 50 50
x2, y2 : 100 100
x3 ,y3 :150 50