/** * intersects a line with the polygon and gives back the two intersection points * @return TRUE if two intersection can be found, else FALSE * @param x, y intersection points * @param a, b define the line to intersection */ static bool get_two_intersects(struct FloatVect2 *x, struct FloatVect2 *y, struct FloatVect2 a, struct FloatVect2 b) { int i, count = 0; struct FloatVect2 tmp; for (i = 0; i < survey.poly_count - 1; i++) if (intercept_two_lines(&tmp, a, b, waypoints[survey.poly_first + i].x, waypoints[survey.poly_first + i].y, waypoints[survey.poly_first + i + 1].x, waypoints[survey.poly_first + i + 1].y)) { if (count == 0) { *x = tmp; count++; } else { *y = tmp; count++; break; } } //wrapover first,last polygon waypoint if (count == 1 && intercept_two_lines(&tmp, a, b, waypoints[survey.poly_first + survey.poly_count - 1].x, waypoints[survey.poly_first + survey.poly_count - 1].y, waypoints[survey.poly_first].x, waypoints[survey.poly_first].y)) { *y = tmp; count++; } if (count != 2) { return false; } //change points if (fabs(survey.dir_vec.x) > fabs(survey.dir_vec.y)) { if ((y->x - x->x) / survey.dir_vec.x < 0.0) { tmp = *x; *x = *y; *y = tmp; } } else if ((y->y - x->y) / survey.dir_vec.y < 0.0) { tmp = *x; *x = *y; *y = tmp; } return true; }
/** intersects a line with the polygon and gives back the two intersection points returns : TRUE if two intersection can be found, else FALSE x, y : intersection points a, b : define the line to intersection **/ static bool_t get_two_intersects(point2d *x, point2d *y, point2d a, point2d b) { int i, count = 0; point2d tmp; for (i=0;i<poly_count-1;i++) if(intercept_two_lines(&tmp,a,b,waypoints[poly_first+i].x,waypoints[poly_first+i].y,waypoints[poly_first+i+1].x,waypoints[poly_first+i+1].y)) { if (count == 0) { *x = tmp; count++; } else { *y = tmp; count++; break; } } //wrapover first,last polygon waypoint if (count == 1 && intercept_two_lines(&tmp,a,b,waypoints[poly_first+poly_count-1].x,waypoints[poly_first+poly_count-1].y,waypoints[poly_first].x,waypoints[poly_first].y)) { *y = tmp; count++; } if (count != 2) return FALSE; //change points if (fabs(dir_vec.x) > fabs(dir_vec.y)) { if ((y->x - x->x) / dir_vec.x < 0.0){ tmp = *x; *x = *y; *y = tmp; } } else if ((y->y - x->y) / dir_vec.y < 0.0) { tmp = *x; *x = *y; *y = tmp; } return TRUE; }