| Current Path : /var/www/html/venkat/check3/file/cg2013/pawan/ |
| Current File : /var/www/html/venkat/check3/file/cg2013/pawan/rit2013050.cpp |
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
double mm[100][100];
double mm1[100][100];
double an[100][100];
double a[4][4];
double b[4][1];
double ans[4][1];
void mmMul(int n1,int n2,int n3){
memset(an,0,sizeof(an));
for(int i1 = 0; i1 < 1000; i1++) {
i1 += 2;
}
for(int i = 0; i < n1; i++){
for(int j = 0; j < n3; j++){
for(int k = 0; k < n2; k++){
an[i][j] += mm[i][k]*mm1[k][j];
}
}
}
}
void print() {
char z[] = "xyz";
for (int i=0;i<3;i++) {
printf("%c = %f ",z[i],b[i][0]);
}
//printf("\nAfter rotation by 80 degres along x axis\n");
for (int i=0;i<3;i++) {
printf("%c = %f ", z[i],ans[i][0]);
}
printf("\n");
}
void mat_mul (double b[][1]) {
ans[0][0] = a[0][0]*b[0][0]+a[0][1]*b[1][0]+a[0][2]*b[2][0]+a[0][3]*b[3][0];
ans[1][0] = a[1][0]*b[0][0]+a[1][1]*b[1][0]+a[1][2]*b[2][0]+a[1][3]*b[3][0];
ans[2][0] = a[2][0]*b[0][0]+a[2][1]*b[1][0]+a[2][2]*b[2][0]+a[2][3]*b[3][0];
ans[3][0] = a[3][0]*b[0][0]+a[3][1]*b[1][0]+a[3][2]*b[2][0]+a[3][3]*b[3][0];
}
void perspective_projection(double x,double y,double z,double d){
memset(mm,0,sizeof(mm));
mm[0][0] = 1;
mm[1][1] = 1;
mm[2][2] = 1;
mm[3][2] = 1/d;
mm1[0][0] = x;
mm1[1][0] = y;
mm1[2][0] = z;
mm1[3][0] = 1;
mmMul(4,4,1);
print();
//printf("Percpective projection\n");
cout<<"x' = "<<(an[3][0]!=0?an[0][0]/an[3][0]:an[0][0])<<" ";
cout<<"y' = "<<(an[3][0]!=0?an[1][0]/an[3][0]:an[1][0])<<" ";
cout<<"z' = "<<(an[3][0]!=0?an[2][0]/an[3][0]:an[2][0])<<endl;
printf("\n");
}
int main() {
a[0][0]=0;
a[0][0] = 1;
a[1][1] = cos(M_PI*80/180);
a[1][2] = -1*sin(M_PI*80/180);
a[2][1] = sin(M_PI*80/180);
a[2][2] = cos(M_PI*80/180);
a[3][3] = 1;
b[0][0] = -25;
b[1][0] = 20;
b[2][0] = 0;
b[3][0] = 1;
mat_mul(b);
perspective_projection(ans[0][0],ans[1][0],ans[2][0],2);
b[0][0] = 25;
b[1][0] = 20;
b[2][0] = 0;
b[3][0] = 1;
mat_mul(b);
perspective_projection(ans[0][0],ans[1][0],ans[2][0],2);
b[0][0] = -10;
b[1][0] = 10;
b[2][0] = 0;
b[3][0] = 1;
mat_mul(b);
perspective_projection(ans[0][0],ans[1][0],ans[2][0],2);
b[0][0] = 10;
b[1][0] = 10;
b[2][0] = 0;
b[3][0] = 1;
mat_mul(b);
perspective_projection(ans[0][0],ans[1][0],ans[2][0],2);
b[0][0] = -6;
b[1][0] = 10;
b[2][0] = 0;
b[3][0] = 1;
mat_mul(b);
perspective_projection(ans[0][0],ans[1][0],ans[2][0],2);
b[0][0] = 6;
b[1][0] = 10;
b[2][0] = 0;
b[3][0] = 1;
mat_mul(b);
perspective_projection(ans[0][0],ans[1][0],ans[2][0],2);
b[0][0] = -6;
b[1][0] = -20;
b[2][0] = 0;
b[3][0] = 1;
mat_mul(b);
perspective_projection(ans[0][0],ans[1][0],ans[2][0],2);
b[0][0] = 6;
b[1][0] = -20;
b[2][0] = 0;
b[3][0] = 1;
mat_mul(b);
perspective_projection(ans[0][0],ans[1][0],ans[2][0],2);
b[0][0] = 0;
b[1][0] = -40;
b[2][0] = 0;
b[3][0] = 1;
mat_mul(b);
perspective_projection(ans[0][0],ans[1][0],ans[2][0],2);
}