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/RIT2013085_1.cpp

#include <bits/stdc++.h>
using namespace std;
#define pi 3.14159265358979323846

double matrix[100][100]={};
double matrix1[100][100]={};
double ans[100][100]={};
double answer[100][3],answer1[100][3];
int len = 0;
void MatrixMul(int n1,int n2,int n3){

	memset(ans,0,sizeof(ans));
	for(int i = 0; i < n1; i++){
		for(int j = 0; j < n3; j++){
			for(int k = 0; k < n2; k++){
				ans[i][j] += matrix[i][k]*matrix1[k][j];
			}
		}
	}

}
void perspective(double x,double y,double z,double d){
	memset(matrix,0,sizeof(matrix));
	matrix[0][0] = 1;
	matrix[1][1] = 1;
	matrix[2][2] = 1;
	matrix[3][2] = 1/d;

	matrix1[0][0] = x;
	matrix1[1][0] = y;
	matrix1[2][0] = z;
	matrix1[3][0] = 1;
	MatrixMul(4,4,1);
	double a1 = ans[0][0];
	double a2 = ans[1][0];
	double a3 = ans[2][0]; 
	if(ans[3][0]!=0)
	{
	//	ans[0][0] = ans[0][0]/ans[3][0];

	 a1 =  ans[3][0]!=0?ans[0][0]/ ans[3][0]:ans[0][0];
	//      ans[1][0] = ans[1][0]/ans[3][0];
	//	ans[2][0] = ans[2][0]/ans[3][0];
	
	 a2 = ans[3][0]!=0?ans[1][0]/ans[3][0]:ans[1][0];
	 a3 = ans[3][0]!=0?ans[2][0]/ans[3][0]:ans[2][0];
}
	printf("%d %d %d\n",(int)(a1 + 0.5),(int)(a2+0.5),(int)(a3+0.5));
}

void rotation_x3D(double x,double y,double z,double thita){
	double cosine = cos(thita);
	double sine = sin(thita);
	memset(matrix,0,sizeof(matrix));
	matrix[0][0] = 1;
	matrix[1][1] = cosine;
	matrix[1][2] = (-1)*sine;
	matrix[2][1] = sine;
	matrix[2][2] = cosine;
	matrix[3][3] = 1;

	matrix1[0][0] = x;
	matrix1[1][0] = y;
	matrix1[2][0] = z;
	matrix1[3][0] = 1;

	MatrixMul(4,4,1);
	answer[len][0] = ans[0][0];
	answer[len][1] = ans[1][0];
	answer[len][2] = ans[2][0];
	len++;

	//	cout<<endl;
	//printf("x = %d ",x);
	//	cout<<"x' = "<<ans[0][0]<<endl;
	//printf("")
	//	cout<<"y' = "<<ans[1][0]<<endl;
	//	cout<<"z' = "<<ans[2][0]<<endl;
	//	cout<<endl;
}

int main()
{
	double x[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};
	double y[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};
	double z[24] = {0.0};
	for(int i = 0 ; i < 24; i++)
	{
		y[i] =  y[i] + 100;
		z[i] = z[i] -10;
	}
	for(int i = 0; i < 24; i++)
	{
		rotation_x3D(x[i],y[i],z[i],(3.14159/2)-atan(0.1));
		perspective(answer[i][0],answer[i][1],answer[i][2],10);

	}
/*	for(int i = 0; i < 10; i++)
	{
		printf("%lf %lf %lf ",answer[i][0],answer[i][1],answer[i][2]);
		            printf("%lf %lf %lf ",ans[i][0],ans[i][1],ans[i][2]);

		printf("\n");
	}*/
}