You are on page 1of 9

Preface

We perform translations, rotations, and scaling to fit the picture components into their proper
positions in the previous Practical No. 5. Here we consider how the matrix representations and
Homogenous coordinates can be reformulated so that such transformation sequences can be
efficiently processed.
Matrix Representation’s and Homogeneous coordinates
We have seen in the previous practical that each of the basic transformations can be ex- pressed in
the general matrix form:
𝑃′ = 𝑀1 . 𝑃 + 𝑀2 1.
with coordinate positions P and P' represented as column vectors. Matrix M1 is a 2 by 2 array
containing multiplicative factors, and M2 is a two-element column matrix containing translational
terms. For translation, M1 is the identity matrix. For rotation or scaling, M2 contains the translational
terms associated with the pivot point or scaling fixed point. To produce a sequence of
transformations with these equations, such as scaling followed by rotation then translation, we
must calculate the transformed coordinates one step at a time. First, coordinate positions are
scaled, then these scaled coordinates are rotated, and finally the rotated coordinates are
translated. A more efficient approach would be to combine the transformations so that the final
coordinate position are obtained directly from the initial coordinates, thereby eliminating the
calculation of intermediate coordinate values. To be able to do this, we need to reformulate Eq. 1 to
eliminate the matrix addition associated with the translation terms in M2.

To express any two-dimensional transformation as a matrix multiplication, we represent each


Cartesian coordinate position (𝑥, 𝑦) with the homogeneous coordinate triple (𝒙, 𝒚𝒉 , 𝒉),

Where
𝑥ℎ 𝑦ℎ
𝑥= , 𝑦= 2.
ℎ ℎ

Thus, a general homogeneous coordinate representation can also be written as (𝒉. 𝒙, 𝒉. 𝒚, 𝒉) For
two-dimensional geometric transformations, we can choose the homogeneous parameter h to be any
nonzero value. Thus, there is an infinite number of equivalent homogeneous representations for each
coordinate point (x, y). A convenient choice is simply to set h = 1. Each two dimensional position is
then represented with homogeneous coordinates (x, y, 1). Other values for parameter h are needed,
for example, in matrix formulations of three dimensional viewing transformations.
Program
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
#include<math.h>
void drawt(int,int,int,int,int,int);
int xc,yc;
int main(){
clrscr();
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
int x1,x2,x3,y1,y2,y3,i,j,r;
double t[3],o;
int xx1,xx2,xx3,xy1,xy2,xy3;
int a[3][3]={x1,x2,x3,y1,y2,y3,1,1,1};
int p[3][3]={1,0,xc,0,1,yc,0,0,1};
int p1[3][3]={1,0,xc,0,1,yc,0,0,1};
double cossin[3][3]={0};
printf("enter the pivot point-\n");
scanf("%d%d",&xc,&yc);
printf("enter the first coordiant of the triangle\n");
scanf("%d%d",&x1,&y1);
printf("enter the second co-ordinate of the triangle\n");
scanf("%d%d",&x2,&y2);
printf("enter the third co-ordinate of the triangle\n");
scanf("%d%d",&x3,&y3);
a[0][0]=x1;
a[0][1]=x2;
a[0][2]=x3;
a[1][0]=y1;
a[1][1]=y2;
a[1][2]=y3;
p[0][2]=xc;
p[1][2]=yc;
p1[0][2]=-xc;
p1[1][2]=-yc;
drawt(x1,y1,x2,y2,x3,y3);
printf("enter the angles of rotation");
for(i=0;i<3;i++) {
scanf("%lf",&t[i]);
t[i]=(t[i]*3.14)/180;
}
//general equation of rotation at arbitirary point.
for(i=0;i<3;i++){
xx1=abs(xc+(x1-xc)*cos(t[i])-(y1-yc)*sin(t[i]));
xy1=abs(yc+(x1-xc)*sin(t[i])+(y1-yc)*cos(t[i]));
xx2=abs(xc+(x2-xc)*cos(t[i])-(y2-yc)*sin(t[i]));
xy2=abs(xc+(x2-xc)*sin(t[i])+(y2-yc)*cos(t[i]));
xx3=abs(xc+(x3-xc)*cos(t[i])-(y3-yc)*sin(t[i]));
xy3=abs(xc+(x3-xc)*sin(t[i])+(y3-yc)*cos(t[i]));
drawt(xx1,xy1,xx2,xy2,xx3,xy3);

}
getch();
return 0;
}
void drawt(int xn1,int yn1,int xn2,int yn2,int xn3,int yn3){
line(xn1,yn1,xn2,yn2);
line(xn2,yn2,xn3,yn3);
line(xn3,yn3,xn1,yn1);
putpixel(xc,yc,YELLOW);
getch();
cleardevice();
}
//OUTPUT
Test Cases:

1)
2)

You might also like