PDA

View Full Version : Draw and detect the polygon type



30baz
11-07-2008, 08:14 PM
i take points as input from a .txt file and i draw with these points a polygon then here comes the problem .. i need an algorithm to detect the type of the polygon .. concave or convex .. and here is my code ..
------------------------------------------------------------------
#include<stdafx.h>
#include <iostream>
#include <iomanip>
#include <fstream>
#include<conio.h>
#include<stdio.h>
#include<glut.h>
#include<gl.h>
using namespace std;

int counter=0;
int xsave[100];
int ysave[100];
int i=0;
int c=0;
int x1=0;
int y1=0;
int calc1=0;
int calc2=0;
void detect_polygon_type()
{


}

void draw_polygon(int x,int y)
{
c++;
glBegin(GL_POINTS);
glVertex2i(x,y);
glEnd();
if(c>1)
{
glBegin(GL_LINE_STRIP);
glVertex2i(x1,y1);
glVertex2i(x,y);
glEnd();
glFlush();
}
else
{
glFlush();
} }



int main1() {
glClear(GL_COLOR_BUFFER_BIT); // clear the screen

int x;
int y;
ifstream inFile;
inFile.open("test.txt");
if (!inFile) {
printf("file cannot be opened !!");
getch();
exit(1); // terminate with error
}

while(inFile >> x >> y )
{
counter++;
draw_polygon(x,y);
x1=x;
y1=y;

}
inFile.close();

}
void myInit(void)
{
glClearColor(1.0,1.0,1.0,0.0); // set white background color
glColor3f(0.0f, 0.0f, 0.0f); // set the drawing color
glPointSize(4.0); // a ‘dot’ is 4 by 4 pixels
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 640.0, 0.0, 480.0);
}
//<<<<<<<<<<<<<<<<<<<<<<<< myDisplay >>>>>>>>>>>>>>>>>
void myDisplay(void)
{
//glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POINTS);
glEnd();
glFlush(); // send all output to display

}


//<<<<<<<<<<<<<<<<<<<<<<<< main >>>>>>>>>>>>>>>>>>>>>>
void main(int argc, char** argv)
{
glutInit(&argc, argv); // initialize the toolkit
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); // set display mode
glutInitWindowSize(640,480); // set window size
glutInitWindowPosition(100, 150); // set window position on
glutCreateWindow("Assignment 1 , Question # 2 "); // open the screen window
glutDisplayFunc(myDisplay); // register redraw function
myInit();
main1();
//detect_polygon_type();
glutMainLoop(); // go into a perpetual loop
getch();

}
--------------------------------------------------------------
thanks in advance

trinitrotoluene
11-07-2008, 10:48 PM
It seem that you double post your question, there is an answer here (http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=248456&Main=48420#Post248456).

30baz
11-08-2008, 08:34 PM
first of all thnks for ur suport .. i did what u just said but unfortunately it solves in a wrong why probably cuz i messed in code or somethin .. so please if u have the time can u add the algorithm to my code .. :) and thnks for ut time



Best Regards,
30baz

trinitrotoluene
11-09-2008, 08:31 AM
There is another answer here (http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Main=48420&Number=248487#Post248487).