2-D Transformations for an Object (C++)

Problem Definition: Write a program to implement 2-D Transformations viz., (a) Translation (b) Rotation (c) Scaling for an Object. #include <conio.h> #include <iostream.h> #include <graphics.h> #include <math.h> void main(){ int x1=200,y1=200,x2=250,y2=250,x3=180,y3=270,option; int gdriver = DETECT,gmode; initgraph(&gdriver,&gmode,”C:\TC\BGI”); do{ cleardevice(); gotoxy(1,1); line(x1,y1,x2,y2); line(x2,y2,x3,y3); line(x3,y3,x1,y1); cout<<“\n1.Translation 2.Scaling 3.Rotation 4.Exit\nEnter your choice: “; cin>>option; switch(option){ case 1: float tx,ty; cout<<“Enter tx & ty: “; cin>>tx>>ty; x1+=tx;x2+=tx;x3+=tx; y1+=ty;y2+=ty;y3+=ty; break; case 2: float sx,sy; … Continue reading 2-D Transformations for an Object (C++)

Digital Differential Analyzer (DDA) Line Drawing Algorithm (C++)

Problem Definition: Write a program to implement Digital Differential Analyzer (DDA) Line drawing algorithm. #include <conio.h> #include <iostream.h> #include <graphics.h> #include <math.h> void main(){ float x,y,dx,dy; int x1,y1,x2,y2,i,length; int gdriver = DETECT, gmode; initgraph(&gdriver,&gmode,”C:\TC\BGI”); cout<<“Enter co-ordinates of point 1: “; cin>>x1>>y1; cout<<“Enter co-ordinates of point 2: “; cin>>x2>>y2; dx = abs(x2-x1); dy = abs(y2-y1); if(dx>=dy) length = dx; else length = dy; dx = dx/length; dy = … Continue reading Digital Differential Analyzer (DDA) Line Drawing Algorithm (C++)