Page 133 - DCAP313_LAB_ON_COMPUTER_GRAPHICS
P. 133
Unit 8: Implementing of Scaling in 2D Transformation
Scaling in 2D, matrix notation Notes
• Scaling is a matrix multiplication:
È x¢˘ S È x 0 ˘ x È ˘
Í ˙ = Í 0 S ˙ Í ˙
y¢
y
Î ˚ Î y ˚ Î ˚
P’ = SP
8.2.5 Write a C Program to Implement 2D Transformations
Step By Step Procedural Algorithm
1. Enter the choice for transformation.
2. Perform the translation, rotation, scaling, reflection and shearing of 2D object.
3. Get the needed parameters for the transformation from the user.
4. In case of rotation, object can be rotated about x or y axis.
5. Display the transmitted object in the screen.
Source Code Programming 2D Transformations
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
int ch,x,y,az,i,w,ch1,ch2,xa,ya,ra,a[10],b[10],da,db;
float x1,y1,az1,w1,dx,dy,theta,x1s,y1s,sx,sy,a1[10],b1[10];
void main()
{
int gm ,gr;
clrscr();
detectgraph(&gm,&gr);
initgraph(&gm,&gr,"d:tcBGI");
printf("Enter the upper left corner of the rectangle:n");
scanf("%d%d",&x,&y);
printf("Enter the lower right corner of the rectangle:n");
scanf("%d%d",&az,&w);
rectangle(x,y,az,w);
da=az–x;
db=w–y;
a[0]=x;
b[0]=y;
a[1]=x+da;
b[1]=y;
a[2]=x+da;
b[2]=y+db;
a[3]=x;b[3]=y+db;
LOVELY PROFESSIONAL UNIVERSITY 127