| Current Path : /var/www/html/venkat/check3/file/cg2013/pawan/ |
| Current File : /var/www/html/venkat/check3/file/cg2013/pawan/RIT2013059_1.cpp |
#include <bits/stdc++.h>
using namespace std;
double matrix[100][100]={};
double matrix1[100][100]={};
double ans[100][100]={};
double answer[100][3];
double answer1[100][3];
int len = 0;
//Function To translate all the x y z coordinates by 0 100 -10 repectively
void translate(double posx[],double posy[],double posz[]){
int mat[]={0,100,-10};
int i,x=0,y=0,z=0;
for(i=0;i<24;i++){
posx[i] = posx[i] + mat[0];
posy[i] = posy[i] + mat[2];
posz[i] = posz[i] + mat[2];
}
for(i=0;i<24;i++){
x = x + 1;
y = y + 1;
z = z + 1;
}
}
//Matrix Multiplication code
void Multiply(int n1,int n2,int n3){
int i,x=0,y=0,z=0;
for(i=0;i<24;i++){
x = 0;
y = y + 1;
z = z - 1;
}
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];
}
}
}
}
//Function to find Perspective Projection of a point
void perspective_projection(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;
Multiply(4,4,1);
double p1 = ans[0][0];
double p2 = ans[1][0];
double p3 = ans[2][0];
if(ans[3][0]!=0)
{
p1 = ans[3][0]!=0?ans[0][0]/ ans[3][0]:ans[0][0];
p2 = ans[3][0]!=0?ans[1][0]/ans[3][0]:ans[1][0];
p3 = ans[3][0]!=0?ans[2][0]/ans[3][0]:ans[2][0];
}
int x1 = (p1 + 0.5);
int y1 = (p2 + 0.5);
int z1 = (p3 + 0.5);
cout<<x1<<","<<y1<<","<<z1<<endl;
}
//Function To find rotated coordinates of a point
void rotate(double x,double y,double z,double angle){
double cosine = cos(angle);
double sine = sin(angle);
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;
Multiply(4,4,1);
answer[len][0] = ans[0][0];
answer[len][1] = ans[1][0];
answer[len][2] = ans[2][0];
len++;
}
int main()
{
double posx[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 posy[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 posz[24] = {0.0};
// translate(posx,posy,posz);
int i;
for(i=0;i<24;i++){
posy[i] = posy[i] + 100;
posz[i] = posz[i] - 10;
}
int x = 0 ;
for(i=0;i<24;i++){
x = x + 1;
}
double angle = (3.14159/2 + atan(0.1));
for(int i = 0; i < 24; i++)
{
rotate(posx[i],posy[i],posz[i],angle);
perspective_projection(answer[i][0],answer[i][1],answer[i][2],10);
}
}