int main() { Point p1, p2, p3; int i, j, ntrees; while(scanf("%lf%lf%lf%lf%lf%lf", &p1.x, &p1.y, &p2.x, &p2.y, &p3.x, &p3.y)) { if(p1.x == 0 && p1.y == 0 && p2.x == 0 && p2.y == 0 && p3.x == 0 && p3.y == 0) break; ntrees = 0; reorder_vertices(p1, p2, p3); int left = left_border(p1, p2, p3); if(left < 1) left = 1; int right = right_border(p1, p2, p3); if(right > 99) right = 99; int bottom = bottom_border(p1, p2, p3); if(bottom < 1) bottom = 1; int top = top_border(p1, p2, p3); if(top > 99) top = 99; for(i = left; i <= right; i++) { for(j = bottom; j <= top; j++) { Point tree = { (double)i, (double)j }; if(on_edge(p1, p2, tree) || on_edge(p2, p3, tree) || on_edge(p3, p1, tree) || ccw(p1, p2, tree) && ccw(p2, p3, tree) && ccw(p3, p1, tree)) { ntrees++; } } } printf("%4d\n", ntrees); } return 0; }
/** * Method to check if the point specified, is on the object / on a point of the * curve * * @param x x position of the point to be checked * @param y y position of the point to be checked * @param selected true if the object is selected * @return point 'under' x and y or NULL */ Point* CubicSpline::on_object(const unsigned int& x, const unsigned int& y, const bool& selected) const { if(selected) { // if selected only check if on control polygon return Polygon::on_object(x, y, selected); } else { std::vector<Point>* curve = new std::vector<Point>(); cubic_spline(*object_, LOW_SMOOTHNESS, curve); // calculate the curve with // low polygon count Point* ret = on_edge(x, y, *curve); delete curve; return ret; } return NULL; }
bool geo_util_inside_polygon__(const double * xlist , const double * ylist , int num_points , double x0 , double y0 , bool force_edge_inside) { bool inside = false; int point_num; double y = y0; double xc = 0; for (point_num = 0; point_num < num_points; point_num++) { int next_point = ((point_num + 1) % num_points); double x1 = xlist[point_num]; double y1 = ylist[point_num]; double x2 = xlist[next_point]; double y2 = ylist[next_point]; double ymin = util_double_min(y1,y2); double ymax = util_double_max(y1,y2); double xmax = util_double_max(x1,x2); if (force_edge_inside) { if (on_edge(x1,y1,x2,y2,x0,y0)) { inside = true; break; } } if ((x1 == x2) && (y1 == y2)) continue; if ((y0 > ymin) && (y <= ymax)) { if (x0 <= xmax) { if (y1 != y2) xc = (y0 - y1) * (x2 - x1) / (y2 - y1) + x1; if ((x1 == x2) || (x0 <= xc)) inside = !inside; } } } return inside; }