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

#include <GL/glut.h>

#include <iostream>

#include <GL/gl.h>

#include <GL/glu.h>

#include <GL/glext.h>

#include<map>

using namespace std;

int xxx[100],xxx1[100],e,e1,a;

float c,c1;

void point(void)
{
	
	glClear (GL_COLOR_BUFFER_BIT);
	
	glColor3f(1.0,0.0,0.0);
	
	glBegin(GL_LINES);
	
	glVertex2i(e,c);
	
	/*void rectangle(float a1, float b1, float a2, float b2)
{
	glColor3f(0.0,0.0,0.0);

	glBegin(GL_QUADS);
	
	glVertex3f(a2,b1,0.0);
	
	glVertex3f(a2,b2,0.0);
	
	glVertex3f(a1,b2,0.0);
	
	glVertex3f(a1,b1,0.0);
	
	glEnd();
}*/
	glVertex2i(e1,c1);
		
	glEnd();
	
	glColor3f(0.0,1.0,0.0);
	
	glPointSize(5.0);
	
	glBegin(GL_POINTS);
	
	for(int kk=0;kk<a;kk++){
		
		glVertex2i(xxx[kk],xxx1[kk]);
	}
	
	glEnd();
	
	glFlush();
}

void init(void)
{
	glClearColor (1.0,1.0,1.0,0.0);
	
	/*void rectangle(float a1, float b1, float a2, float b2)
{
	glColor3f(0.0,0.0,0.0);

	glBegin(GL_QUADS);
	
	glVertex3f(a2,b1,0.0);
	
	glVertex3f(a2,b2,0.0);
	
	glVertex3f(a1,b2,0.0);
	
	glVertex3f(a1,b1,0.0);
	
	glEnd();
}*/glMatrixMode(GL_PROJECTION);
	
	gluOrtho2D (0.0,200.0,0.0,150.0);
}

int  main(int argc,char **argv)
{
	
	int x,y,kk;
	
	float sx = 0, sy=0;
	float sx2=0, sxy=0;
	float m1, b;
	
	map<int,int> m;
	
	cout << "Enter points :" << endl;
	
	cin >> a;
	
	cout << "Points :" << endl;
	
	for(kk=0;kk<a;kk++){
		cin >> x;
		
		cin >> y;
		
		xxx[kk] = x;
		
		xxx1[kk] = y;
		
		m.insert(pair<int,int>(x,y));
		
		sx = sx + x;
		
		sy = sy + y;
		
		sx2 = sx2 + (x * x);
		
		sxy =  sxy + (x * y);
	}
    
	m1 = ((a * sxy) - (sx * sy)) / ((a * sx2) - (sx * sx));
	   
    b = (sy - (m1 * sx)) / a;
    
	/*void rectangle(float a1, float b1, float a2, float b2)
{
	glColor3f(0.0,0.0,0.0);

	glBegin(GL_QUADS);
	
	glVertex3f(a2,b1,0.0);
	
	glVertex3f(a2,b2,0.0);
	
	glVertex3f(a1,b2,0.0);
	
	glVertex3f(a1,b1,0.0);
	
	glEnd();
}*/
	e = (*(m.begin())).first;
    
	e1 = (*(--m.end())).first;	 	
    
	c = (m1 * e) + b;
    
	c1 = (m1 * e1) + b; 		
	
	/*void rectangle(float a1, float b1, float a2, float b2)
{
	glColor3f(0.0,0.0,0.0);

	glBegin(GL_QUADS);
	
	glVertex3f(a2,b1,0.0);
	
	glVertex3f(a2,b2,0.0);
	
	glVertex3f(a1,b2,0.0);
	
	glVertex3f(a1,b1,0.0);
	
	glEnd();
}*/
	glutInit(&argc,argv);
	
	glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
	
	glutInitWindowPosition(0,0);
	
	glutInitWindowSize(400,300);
	
	glutCreateWindow("Point Creation");
	
	init();
	
	glutDisplayFunc(point);
	
	glutMainLoop();
	
	return 0;
}