Ver Mensaje Individual
  #1 (permalink)  
Antiguo 05/12/2013, 02:43
xinxan22
 
Fecha de Ingreso: septiembre-2005
Mensajes: 522
Antigüedad: 18 años, 7 meses
Puntos: 0
Pasar código de C a PHP

Buenos días,

estoy intentando pasar a PHP la siguiente función sacada de esta página web:

http://jsbsan.blogspot.com.es/2011/0...o-o-fuera.html

Y no se como pasar

Código:
#define MIN(x,y) (x < y ? x : y)
#define MAX(x,y) (x > y ? x : y)
A php, no se si correspondría a min y max de php.


La función completa es:

Código:
#define MIN(x,y) (x < y ? x : y)
#define MAX(x,y) (x > y ? x : y)
#define INSIDE 0
#define OUTSIDE 1

typedef struct {
double x,y;
} Point;

int InsidePolygon(Point *polygon,int N,Point p)
{
int counter = 0;
int i;
double xinters;
Point p1,p2;

p1 = polygon[0];
for (i=1;i<=N;i++) {
   p2 = polygon[i % N];
   if (p.y > MIN(p1.y,p2.y)) {
   if (p.y <= MAX(p1.y,p2.y)) {
      if (p.x <= MAX(p1.x,p2.x)) {
          if (p1.y != p2.y) {
              xinters = (p.y-p1.y)*(p2.x-p1.x)/(p2.y-p1.y)+p1.x;
              if (p1.x == p2.x || p.x <= xinters)
                counter++;
              }
           }
       }  
    }
   p1 = p2;
}

if (counter % 2 == 0)
return(Fuera);
else
return(Dentro);
}