Page 167 - DCAP313_LAB_ON_COMPUTER_GRAPHICS
P. 167
Unit 10: Shearing
10.3.1 2D Transformations Such As Reflection Algorithms Notes
1. Start
2. Initialize the graphics mode.
3. Construct a 2D object (use Drawpoly()) e.g. (x, y)
a. About X axis
i. x’= x, y’ = –y
ii. Plot (x’, y’)
b. About Y axis
i. x’= –x, y’=y
ii. Plot (x’, y’)
Source Code for Reflection Algorithm C Programming
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
int x 1 ,y 1 ,x 2 ,y 2 ;
void reflection()
{
int xn 1 ,yn 1 ,xn 2 ,yn 2 ;
cleardevice();
outtextxy(300,100, “REFLECTION”);
if((x 1 <y 1 )^(x 2 <y 2 ))
{
xn 1 =x 1 +50;
xn 2 =x 2 +50;
yn 1 =y 1 ;
yn 2 =y 2 ;
}
else
{
xn 1 =x 1 ;
xn 2 =x 2 ;
yn 1 =y 1 +50;
yn 2 =y 2 +50;
}
line(x 1 ,y 1 ,x 2 ,y 2 );
line(xn 1 ,yn 1 ,xn 2 ,yn 2 );
getch();
}
LOVELY PROFESSIONAL UNIVERSITY 161