Exemplo n.º 1
0
int main() {
  int n;
  while(scanf("%d", &n) != EOF) {
    int l, h;
    double min = FLT_MAX;
    scanf("%d %d", &l, &h);
    Line Old;
    for (int i = 1; i <= n; i++) {
      int yi, xf, yf;
      scanf("%d %d %d", &yi, &xf, &yf);
      Point P1, P2;
      if (i % 2 != 0) {
        P1.x = 0;
        P1.y = yi;
        P2.x = xf;
        P2.y = yf;
        if (l - xf < min) 
          min = l - xf;
      } else {
        P1.x = l;
        P1.y = yi;
        P2.x = xf;
        P2.y = yf;
        if (xf < min)
          min = xf;
      }
      Line N(P1, P2);
      if (i != 1) {
        double d = linePointDist(N, Old.Pb, true);
        if (d < min) 
          min = d;
      }
      Old = N;
    }
    printf("%.2lf\n", min);
  }
  return 0;
}
Exemplo n.º 2
0
//for segment segment intersection, check additionally
//min(x1,x2) <= x <= max(x1,x2)
//min(y1,y2) <= x <= max(y1,y2)
bool segmentsIntersect( point2d A, point2d B, point2d C, point2d E )
{
    point2d in = intersect( makeline(A,B), makeline(C,E) );
    return linePointDist(A,B,in,true) < eps && linePointDist(C,E,in,true) < eps;
}