Your IP : 216.73.216.40


Current Path : /var/www/html/venkat/check3/file/cg2013/pawan/
Upload File :
Current File : /var/www/html/venkat/check3/file/cg2013/pawan/rit2013004_1.cpp

/*
 LAB-ASSIGNMENT
 BY : RIT2013004
*/

#include <bits/stdc++.h>
using namespace std;
#define angle (3.14159/2-atan(0.1))

double ptx[24]={-100,-100,100,100,-50,-50,-150,-500,-500,-100,-50,-400,-400,-100,50,50,150,500,500,100,50,400,400,100};      //x-coordinates of total 24 points (i.e. 5 lines + symmetric 5 lines = 20 points & a square = 4 points)
double pty[24]={700,500,700,500,0,500,0,400,400,700,0,400,400,600,0,500,0,400,400,700,0,400,400,600};          //y-coordinates of total 24 points
double ptz[24]={0};          //z-coordinates initially all set to 0. figure is in xy plane.
double translate_x[24],translate_y[24],translate_z[24];     //translation
double rotate_x[24],rotate_y[24],rotate_z[24];      //rotation
double pptx[24],ppty[24],pptz[24];      //perspective-projection

void rotate() 
{
	for(int i=0;i<24;i++) {
		rotate_x[i] = translate_x[i];
		rotate_y[i] = translate_y[i]*cos(angle) - translate_z[i]*sin(angle);
		rotate_z[i] = translate_y[i]*sin(angle) +translate_z[i]*cos(angle);
	}
}

void translate()
{
	int eye_coor[3]={0,100,-10};
	for(int i=0;i<24;i++) {
		translate_x[i]=ptx[i]+eye_coor[0];
		translate_y[i]=pty[i]+eye_coor[1];
		translate_z[i]=ptz[i]+eye_coor[2];
	}
}

void perspective_projection() 
{
	for(int i=0;i<24;i++) {
		double z = (rotate_z[i]/10);
		if(z!=0) {
			pptx[i]=rotate_x[i]/z;
			ppty[i]=rotate_y[i]/z; 
			pptz[i]=rotate_z[i]/z;
		} else {
			pptx[i]=rotate_x[i];
			ppty[i]=rotate_y[i];
			pptz[i]=rotate_z[i];
		}
	}
}

void print_order()             //print-in-order
{
	for(int i=0;i<24;i++) {
		if(pptx[i]<0) pptx[i]-=1;
		if(ppty[i]<0) ppty[i]-=1;
		if(pptz[i]<0) pptz[i]-=1;
		cout<<(int)(pptx[i]+0.5)<<","<<(int)(ppty[i]+0.5)<<","<<(int)(pptz[i]+0.5)<<"\n";
	}
}

int main()
{
	translate();
	//cout<<translate_x[0]<<" "<<translate_y[0]<<" "<<translate_z[0];
	rotate();
	//cout<<rotate_x[0]<<" "<<rotate_y[0]<<" "<<rotate_z[0];
	perspective_projection();	
	//cout<<pptx[0]<<" "<<ppty[0]<<" "<<pptz[0];
	print_order();
	return 0;
}