Point (X,Y) is to be scaled by amount Sx and Sy to location (X',Y')
X' = Sx * X
Y' = Sy * Y
or P' = S * P whereY' = Sy * Y
P' = [X`,Y`] , P = [X,Y]
S = | Sx 0 |
| 0 Sy |
where Sx ,Sy are scaling factor in x and y directions
Scaling is performed about the origin (0,0) not about the center of the line/polygon/whatever
Case 1:Scale > 1 enlarges the object and moves it away from the origin.
Case 2:Scale = 1 leave the object alone
Case 3:Scale< 1 shrink the object and move it towards the origin.
Case 4: Uniform scaling: Sx = Sy
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
int gdriver=DETECT,gmode;
int midx=350,midy=300;
int x1,y1,x2,y2;
int x,y,i,sx,sy;
clrscr();
initgraph(&gdriver,&gmode,"c:/tc/bgi");
printf("\n Enter the 1st co-ordinate=");
scanf("%d%d",&x1,&y1);
printf("\n Enter the 2nd co-ordinate=");
scanf("%d%d",&x2,&y2);
clrscr();
line(midx,midy-150,midx,midy+150);
line(midx+150,midy,midx-150,midy);
outtextxy(midx,midy," origin");
//printf("\n Before refelction");
rectangle(midx+x1,midy+y1,midx+x2,midy+y2);
getch();
printf("\n Enter the scaling factor(sx,sy)=");
scanf("%d%d",&sx,&sy);
rectangle(midx+sx*x1,midy+sx*y1,midx+sx*x2,midy+sx*y2);
getch();
}
No comments:
Post a Comment