#ifndef
COLLIDE
#define
COLLIDE
#include
<stdio.h>
#include
"iostream.h"
#include
<stdlib.h>
#include
<math.h>
#define
free 1
#define
collide 0
struct
Polygon {
int npoints;
float x[10], y[10];
};
Polygon
obs[20];
struct
Vehicle{
float x[4],y[4];
};
Vehicle
car;
int
numObstacles;
class
Collision{
public:
void collision(){}
int collision(float,float);
int c;
coll(float, float);
objcoll();
polygon();
private:
float x,y;
};
Collision::collision(float
x1,float y1){
x=x1;
y=y1;
}
Collision::polygon(){
//------------Parking
---------------//
//numObstacles=7;
//World Geometry
/* case
4
numObstacles=8;
obs[0].npoints=4;
obs[0].x[0]=0, obs[0].y[0]=0;
obs[0].x[1]=100, obs[0].y[1]=0;
obs[0].x[2]=100, obs[0].y[2]=280;
obs[0].x[3]=0, obs[0].y[3]=280;
obs[1].npoints=4;
obs[1].x[0]=0, obs[1].y[0]=280;
obs[1].x[1]=60, obs[1].y[1]=280;
obs[1].x[2]=60, obs[1].y[2]=320;
obs[1].x[3]=0, obs[1].y[3]=320;
obs[2].npoints=4;
obs[2].x[0]=0, obs[2].y[0]=320;
obs[2].x[1]=100, obs[2].y[1]=320;
obs[2].x[2]=100, obs[2].y[2]=500;
obs[2].x[3]=0, obs[2].y[3]=500;
obs[3].npoints=4;
obs[3].x[0]=150, obs[3].y[0]=0;
obs[3].x[1]=350, obs[3].y[1]=0;
obs[3].x[2]=350, obs[3].y[2]=100;
obs[3].x[3]=150, obs[3].y[3]=100;
obs[4].npoints=4;
obs[4].x[0]=400, obs[4].y[0]=0;
obs[4].x[1]=450, obs[4].y[1]=0;
obs[4].x[2]=450, obs[4].y[2]=100;
obs[4].x[3]=400, obs[4].y[3]=100;
obs[5].npoints=4;
obs[5].x[0]=220, obs[5].y[0]=350;
obs[5].x[1]=250, obs[5].y[1]=350;
obs[5].x[2]=250, obs[5].y[2]=500;
obs[5].x[3]=220, obs[5].y[3]=500;
obs[6].npoints=4;
obs[6].x[0]=300, obs[6].y[0]=350;
obs[6].x[1]=370, obs[6].y[1]=350;
obs[6].x[2]=370, obs[6].y[2]=500;
obs[6].x[3]=300, obs[6].y[3]=500;
obs[7].npoints=4;
obs[7].x[0]=350, obs[7].y[0]=0;
obs[7].x[1]=400, obs[7].y[1]=0;
obs[7].x[2]=400, obs[7].y[2]=75;
obs[7].x[3]=350, obs[7].y[3]=75;
*/
//case 3 Geometry
numObstacles=7;
obs[0].npoints=4;
obs[0].x[0]=0, obs[0].y[0]=100;
obs[0].x[1]=100, obs[0].y[1]=100;
obs[0].x[2]=100, obs[0].y[2]=350;
obs[0].x[3]=0, obs[0].y[3]=350;
obs[1].npoints=4;
obs[1].x[0]=200, obs[1].y[0]=0;
obs[1].x[1]=250, obs[1].y[1]=0;
obs[1].x[2]=250, obs[1].y[2]=250;
obs[1].x[3]=200, obs[1].y[3]=250;
obs[2].npoints=4;
obs[2].x[0]=200, obs[2].y[0]=300;
obs[2].x[1]=250, obs[2].y[1]=300;
obs[2].x[2]=250, obs[2].y[2]=570;
obs[2].x[3]=200, obs[2].y[3]=570;
obs[3].npoints=4;
obs[3].x[0]=300, obs[3].y[0]=100;
obs[3].x[1]=400, obs[3].y[1]=100;
obs[3].x[2]=400, obs[3].y[2]=400;
obs[3].x[3]=300, obs[3].y[3]=400;
obs[4].npoints=4;
obs[4].x[0]=410, obs[4].y[0]=440;
obs[4].x[1]=450, obs[4].y[1]=440;
obs[4].x[2]=450, obs[4].y[2]=480;
obs[4].x[3]=410, obs[4].y[3]=480;
obs[5].npoints=4;
obs[5].x[0]=430, obs[5].y[0]=480;
obs[5].x[1]=450, obs[5].y[1]=480;
obs[5].x[2]=450, obs[5].y[2]=530;
obs[5].x[3]=430, obs[5].y[3]=530;
obs[6].npoints=4;
obs[6].x[0]=410, obs[6].y[0]=530;
obs[6].x[1]=450, obs[6].y[1]=530;
obs[6].x[2]=450, obs[6].y[2]=560;
obs[6].x[3]=410, obs[6].y[3]=560;
/*
case1
numObstacles=4;
obs[0].npoints=4;
obs[0].x[0]=50, obs[0].y[0]=0;
obs[0].x[1]=150, obs[0].y[1]=0;
obs[0].x[2]=150, obs[0].y[2]=200;
obs[0].x[3]=50, obs[0].y[3]=200;
obs[1].npoints=4;
obs[1].x[0]=250, obs[1].y[0]=0;
obs[1].x[1]=350, obs[1].y[1]=0;
obs[1].x[2]=350, obs[1].y[2]=250;
obs[1].x[3]=250, obs[1].y[3]=250;
obs[2].npoints=4;
obs[2].x[0]=50, obs[2].y[0]=570;
obs[2].x[1]=150, obs[2].y[1]=570;
obs[2].x[2]=150, obs[2].y[2]=350;
obs[2].x[3]=50, obs[2].y[3]=350;
obs[3].npoints=4;
obs[3].x[0]=250, obs[3].y[0]=570;
obs[3].x[1]=350, obs[3].y[1]=570;
obs[3].x[2]=350, obs[3].y[2]=400;
obs[3].x[3]=250, obs[3].y[3]=400;
*/
/* case
4
numObstacles=4;
obs[0].npoints=4;
obs[0].x[0]=440, obs[0].y[0]=0;
obs[0].x[1]=470, obs[0].y[1]=0;
obs[0].x[2]=470, obs[0].y[2]=415;
obs[0].x[3]=440, obs[0].y[3]=415;
obs[1].npoints=4;
obs[1].x[0]=300, obs[1].y[0]=0;
obs[1].x[1]=440, obs[1].y[1]=0;
obs[1].x[2]=440, obs[1].y[2]=450;
obs[1].x[3]=300, obs[1].y[3]=450;
obs[2].npoints=4;
obs[2].x[0]=270, obs[2].y[0]=350;
obs[2].x[1]=300, obs[2].y[1]=350;
obs[2].x[2]=300, obs[2].y[2]=450;
obs[2].x[3]=270, obs[2].y[3]=450;
obs[3].npoints=4;
obs[3].x[0]=270, obs[3].y[0]=300;
obs[3].x[1]=100, obs[3].y[1]=300;
obs[3].x[2]=100, obs[3].y[2]=450;
obs[3].x[3]=270, obs[3].y[3]=450;
*/
}
Collision::coll(float
x, float y) { // collision detection
function
int i, j,k;
c = free;
for(k=0;k<numObstacles;k++){
for (i=0,
j=obs[k].npoints-1; i<obs[k].npoints; j=i++) {
if (((
(obs[k].y[i]<=y) && (y<obs[k].y[j])) ||
( (obs[k].y[j]<=y) &&
(y<obs[k].y[i]))) &&
(x<(obs[k].x[j]-obs[k].x[i]) *
(y -
obs[k].y[i]) / (obs[k].y[j] - obs[k].y[i])
+ obs[k].x[i])){
if(c==free) c=collide;
else c=free;
}
}
}
return c;
}
#endif