Professional Documents
Culture Documents
HODGEMAN ALGORITHM
#include <iostream.h>
#include <conio.h>
#include <graphics.h>
//#include "graph.h"
#define MAXVERTICES 11
int corArray[MAXCORDINATES],nVertices=0;
int corArray2[MAXCORDINATES],nVertices2=0;
int wx_min,wx_max,wy_min,wy_max;
void initialize()
initgraph(&gDriver,&gMode,"");
cleardevice();
void inputPolygon()
cin>>nVertices;
cin>>corArray[2*i]>>corArray[(2*i)+1];
corArray[2*(nVertices)] = corArray[0];
corArray[(2*(nVertices))+1] = corArray[1];
void samplePolygon()
midx-200,midy-50,
midx-75,midy-50,
midx-75,midy+200,
midx+75,midy+200,
midx+75,midy-50,
midx+200,midy-50,
midx,midy-125};
nVertices = 8;
for(int i = 0;i<nVertices*2;i++)
corArray[i] = polygon_vertices[i];
switch(b)
case left:
case right:
case bottom:
case top:
return 0;
float m = 0;
switch(b)
case left:
x = wx_min;
y = y1 + m * (x - x1);
break;
case right:
x = wx_max;
y = y1 + m * (x - x1);
break;
case bottom:
y = wy_min;
if(x1 != x2)
x = x1 + (float)(1/m) * (y - y1);
else
x = x1;
break;
case top:
y = wy_max;
if(x1 != x2)
x = x1 + (float)(1/m) * (y - y1);
else
x = x1;
break;
}
corArray2[(2 * nVertices2)] = x;
corArray2[(2 * nVertices2)+1] = y;
nVertices2++;
void clipPolygon()
int j,k;
boundry i;
for(i=left;i<=top;i++)
nVertices2 = 0;
for(j=0;j<nVertices-1;j++)
int x1 = corArray[(2*j)];
int y1 = corArray[(2*j)+1];
int x2 = corArray[(2*(j+1))];
int y2 = corArray[((2*(j+1))+1)];
int _x=0,_y=0;
switch(condition)
{
case 1:
solveIntersection(i,x1,y1,x2,y2,_x,_y);
addNewPoint(_x,_y);
addNewPoint(x2,y2);
break;
case 2:
addNewPoint(x2,y2);
break;
case 3:
solveIntersection(i,x1,y1,x2,y2,_x,_y);
addNewPoint(_x,_y);
break;
case 4:
break;
addNewPoint(corArray2[0],corArray2[1]);
nVertices = nVertices2;
for(j=0;j<nVertices*2;j++)
corArray[j] = corArray2[j];
void main()
{
clrscr();
initialize();
// inputPolygon();
samplePolygon();
// cin>>wx_min>>wx_min>>wy_min>>wy_max;
rectangle(wx_min,wy_max,wx_max,wy_min);
drawpoly(nVertices+1,corArray);
getch();
clipPolygon();
clrscr();
cleardevice();
rectangle(wx_min,wy_max,wx_max,wy_min);
drawpoly(nVertices+1,corArray);
getch();