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

#include <iostream>
#include <bits/stdc++.h>
#include <bits/stdc++.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <math.h>

using namespace std;

double x, y, xx1, yy1, xx2, yy2, xx3, yy3, xcent, ycent;
double _x, _y, _xx1, _yy1, _xx2, _yy2, _xx3, _yy3;
double array_x[20] = {-50, -50, -150, -500, -500, -100, -50, -400, -400, -100, 50, 50, 150, 500, 500, 100, 50, 400, 400, 100};
double array_y[20] = {0, 500, 0, 400, 400, 700, 0, 400, 400, 600, 0, 500, 0, 400, 400, 700, 0, 400, 400, 600};
double _array_x[20], _array_y[20];
double angle = (90 - tanh(0.1));

double _d = 10.0;

void dda(double a1, double b1, double a2, double b2)
{
    double step,dx,dy,xinc,yinc;

    if (a2 < a1) {
        swap(a2, a1);
        swap(b2, b1);
    }

    dx = a2-a1;
    dy = b2-b1;

    step = max(abs(dx), abs(dy));

    xinc = dx/step;
    yinc = dy/step;

    glVertex3f(a1/100, b1/100,0);

    for (int i = 0 ;i < step; ++i) {
        a1 += xinc;
        b1 += yinc;
        glVertex3f(a1/100, b1/100, 0);
    }
}

void rotat(double x, double y, double xx1, double yy1, double &xdest, double &ydest)
{
    xdest = ((x - xx1) * cos(angle) - (y - yy1) * sin(angle)) + xx1;
    ydest = ((x - xx1)) * sin(angle) + (y - yy1) * cos(angle) + yy1;


}


pair <double, double> formula(double x, double y, double z, double prp_x, double prp_y, double prp_z, double zvp)
{
	pair <double, double> pp;
	double temp = x;	
    	//ROTATING ABOUT (90 - ARCTAN(0.1))
	y = y * cos(angle) - z * sin(angle);
	temp = y;    	
	x = temp * sin(angle) + x * cos(angle);
    	
	//SCALING BY 10 UNITS
	x = x * zvp + (1 - zvp) * x;
    	y = y * zvp + (1 - zvp) * y;
	
	pp.first = x;
	pp.second = y;

	return pp;
}

void draw()
{
    double a, b, c;
	glClearColor(0.0, 0.0, 0.0, 0.0);
	glClear(GL_COLOR_BUFFER_BIT);
	glColor3f(1.0, 1.0, 0.0);
	glOrtho(-5.0, 5.0, -5.0, 5.0, -5.0, 5.0);
	glPointSize(3.0f);
	glBegin(GL_POINTS);

    	dda(x, y, xx1, yy1);
    	dda(xx1, yy1, xx2, yy2);
    	dda(xx2, yy2, xx3, yy3);
    	dda(xx3, yy3, x, y);


	pair <double, double> ans1, ans2, ans3, ans4, ans5, ans6;
	ans1 = formula(x,y,0,0,-100,10,_d);
	ans2 = formula(xx1,yy1,0,0,-100,10,_d);
	ans3 = formula(xx2,yy2,0,0,-100,10,_d);
	ans4 = formula(xx3,yy3,0,0,-100,10,_d);

	_x = ans1.first;
	_y = ans1.second;
		cout << _x << " ";		
		cout << _y << endl;		
	_xx1 = ans2.first;
	_yy1 = ans2.second;
		cout << _xx1 << " ";		
		cout << _yy1 << endl;		
	_xx2 = ans3.first;
	_yy2 = ans3.second;
		cout << _xx2 << " ";		
		cout << _yy2 << endl;		
	_xx3 = ans4.first;
	_yy3 = ans4.second;
		cout << _xx3 << " ";		
		cout << _yy3 << endl;		

	for (int i = 0; i < 20; i=i+2) {
		dda(array_x[i], array_y[i], array_x[i+1], array_y[i+1]);
		
		ans5 = formula(array_x[i],array_y[i],0,0,-100,10,_d);
		_array_x[i] = ans5.first;
		_array_y[i] = ans5.second;
		cout <<  _array_x[i] << " ";		
		cout << _array_y[i] << endl;		

		ans6 = formula(array_x[i+1],array_y[i+1],0,0,-100,10,_d);
		_array_x[i+1] = ans6.first;
		_array_y[i+1] = ans6.second;
		cout << _array_x[i+1] << " ";		
		cout <<  _array_y[i+1] << endl;		
	}
    	
	dda(_x, _y, _xx1, _yy1);
    	dda(_xx1, _yy1, _xx2, _yy2);
    	dda(_xx2, _yy2, _xx3, _yy3);
    	dda(_xx3, _yy3, _x, _y);

	for (int i = 0; i < 20; i=i+2) {
		dda(_array_x[i], _array_y[i], _array_x[i+1], _array_y[i+1]);
	}

    	double p,q,r,s,t,u;

	glEnd();
	glFlush();
}

int main(int argc, char** argv)
{
    x = -100;
    y = 700;
    xx1 = -100;
    yy1 = 500;
    xx2 = 100;
    yy2 = 500;
    xx3 = 100;
    yy3 = 700;
    
    xcent = (x + xx1 + xx2) / 3;
    ycent = (y + yy1 + yy2) / 3;

	//draw_point();
    glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_SINGLE);
	glutInitWindowSize(800, 800);
	glutInitWindowPosition(10, 10);
	glutCreateWindow("IIT2013090");
	glutDisplayFunc(draw);
	glutMainLoop();
}