/* Enter n for polygon 5 Enter points of polygon in clockwise/anticlockwise order\n -20 50 50 200 120 50 50 -200 -20 50 Enter rectangle 0 -100 100 150 */ int main() { int gdriver = DETECT, gmode; initgraph(&gdriver, &gmode, ""); setbkcolor(WHITE); cleardevice(); drawAxis(BLACK); int n; Poly *head = NULL; printf("Enter n for polygon"); scanf("%d", &n); printf("Enter points of polygon in clockwise/anticlockwise order\n"); for(int i = 0; i<n; i++) { Point p; scanf("%lf%lf",&p.x,&p.y); Poly *x = (Poly *) malloc (sizeof(Poly)); *x = {p, head}; head = x; } head->plotPoly(MAGENTA,0); Rect r; printf("Enter rectangle\n"); scanf("%lf%lf%lf%lf",&r.min.x, &r.min.y, &r.max.x, &r.max.y); r.plotRect(BLUE); Poly *op = sutherlandHodgeman(head, &r); op->plotPoly(YELLOW,0); getch(); return 0; }
/* -30 70 60 100 80 -10 20 -20 -80 0 -30 70 Enter line -150 100 150 20 -30 70 60 100 80 -10 20 -20 -80 0 -30 70 Enter line */ int main() { int gdriver = DETECT, gmode; initgraph(&gdriver, &gmode, ""); setbkcolor(WHITE); cleardevice(); drawAxis(BLACK); int n; Poly *poly = NULL; printf("Enter n for convex polygon\n"); scanf("%d", &n); printf("Enter points in clockwise/anticlockwise order\n"); for(int i = 0; i<n; i++) { int x,y; scanf("%d%d",&x,&y); Point p = Point{x,y}; Poly *newPoly = (Poly *)malloc(sizeof(Poly)); *newPoly = Poly{p, poly}; poly = newPoly; } poly->plotPoly(BLACK, 0); printf("Enter line\n"); Line l; scanf("%lf%lf%lf%lf", &l.p1.x, &l.p1.y, &l.p2.x, &l.p2.y); l.plotLineDDA(BLUE); cyrusBeck(poly, &l, YELLOW); getch(); closegraph(); return 0; }
int main() { initwindow(700, 700); drawAxis(WHITE); Point p[] = {Point{-20,50}, Point{50,200}, Point{120,50}, Point{50, -200}, Point{-20, 50} }; int n = sizeof(p)/ sizeof(Point); Poly *head = NULL; // i was doing this - http://stackoverflow.com/questions/5136393/for-loop-local-variables-in-c for(int i = 0; i<n; i++) { Poly *x = (Poly *) malloc (sizeof(Poly)); *x = {p[i], head}; head = x; } head->plotPoly(YELLOW,0); Rect r = {Point{0,0}, Point{100, 150} }; r.plotRect(BLUE); Poly *op = sutherlandHodgeman(head, &r); op->plotPoly(RED,1); delay(2000); return 0; }