| Current Path : /var/www/html/venkat/check3/file/cg2013/pawan/ |
| Current File : /var/www/html/venkat/check3/file/cg2013/pawan/rit2013066_1.cpp |
/* [theMighty] Deathsurgeon (Rupesh Maity)
* 3rd year, B.Tech in IT
* IIIT Allahabad
*/
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <math.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <utility>
#include <climits>
#include <ctime>
#define LL long long
#define pii pair<int, int>
#define MOD 1000000007
#define MAX 100001
#define sd(x) scanf("%d", &x)
#define PI 3.14159
#define PIby2 1.570795
using namespace std;
class Point {
public:
double x, y, z;
void set(double a, double b, double c = 0) {
x = a;
y = b;
z = c;
}
};
int ll = 0;
double a[100][100] = { {} };
double mat[100][3];
double m[100][100] = { {} };
double m1[100][100] = { {} };
void matMulti(int n1, int n2, int n3){
for (int j = 0; j < 100; j++)
for (int k = 0; k < 100; k++)
a[j][k] = 0;
int pp = 1000000;
while (pp--);
for (int i = 0; i < n1; i++) {
for (int j = 0; j < n3; j++) {
for (int k = 0; k < n2; k++) {
a[i][j] += m[i][k] * m1[k][j];
}
}
}
}
void perspectiveProjection(double x, double y, double z, double d){
for (int j = 0; j < 100; j++)
for (int k = 0; k < 100; k++)
m[j][k] = 0;
m[0][0] = 1, m[1][1] = 1, m[2][2] = 1, m[3][2] = 1 / d, m1[0][0] = x, m1[1][0] = y, m1[2][0] = z, m1[3][0] = 1;
matMulti(4, 4, 1);
double a11 = a[0][0];
double a22 = a[1][0];
double a33 = a[2][0];
int pp = 1000000;
while (pp--);
if (a[3][0] != 0)
{
a11 = a[3][0] != 0 ? a[0][0] / a[3][0] : a[0][0];
a22 = a[3][0] != 0 ? a[1][0] / a[3][0] : a[1][0];
a33 = a[3][0] != 0 ? a[2][0] / a[3][0] : a[2][0];
}
printf("%d,%d,%d\n", (int)(a11 + 0.5), (int)(a22 + 0.5), (int)(a33 + 0.5));
}
void rotate(double x, double y, double z, double t){
double c = cos(t);
double s = sin(t);
for (int j = 0; j < 100; j++)
for (int k = 0; k < 100; k++)
m[j][k] = 0;
int pp = 1000000;
while (pp--);
m[0][0] = 1;
m[1][1] = c;
m[1][2] = (-1)*s;
m[2][1] = s;
m[2][2] = c;
m[3][3] = 1;
m1[0][0] = x;
m1[1][0] = y;
m1[2][0] = z;
m1[3][0] = 1;
matMulti(4, 4, 1);
mat[ll][0] = a[0][0];
mat[ll][1] = a[1][0];
mat[ll][2] = a[2][0];
ll++;
}
int main()
{
class Point pts[24];
// square points
pts[0].set(-100, 700, 0);
pts[1].set(-100, 500, 0);
pts[2].set(100, 700, 0);
pts[3].set(100, 500, 0);
// other points
pts[4].set(-50, 0, 0);
pts[5].set(-50, 500);
pts[6].set(-150, 0);
pts[7].set(-500, 400);
pts[8].set(-500, 400);
pts[9].set(-100, 700);
pts[10].set(-50, 0);
pts[11].set(-400, 400);
pts[12].set(-400, 400);
pts[13].set(-100, 600);
// other lines symmetric
pts[14].set(-50, 0, 0);
pts[15].set(-50, 500);
pts[16].set(-150, 0);
pts[17].set(-500, 400);
pts[18].set(-500, 400);
pts[19].set(-100, 700);
pts[20].set(-50, 0);
pts[21].set(-400, 400);
pts[22].set(-400, 400);
pts[23].set(-100, 600);
// translation
for (int i = 0; i < 24; i++) {
pts[i].x += 100;
pts[i].z -= 10;
}
// rotation
for (int i = 0; i < 24; i++) {
rotate(pts[i].x, pts[i].y, pts[i].z, PIby2 - atan(0.1));
}
// perspective projection
for (int i = 0; i < 24; i++) {
perspectiveProjection(mat[i][0], mat[i][1], mat[i][2], 10);
}
return 0;
}