Advertisement
Guest User

Point Clipping

a guest
Oct 23rd, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. /*
  2.       Point Clipping Algorithm:
  3.  
  4.       1. Get the minimum and maximum coordinates of both viewing pane.
  5.       2. Get the coordinates for a point.
  6.       3. Check whether given input lies between minimum and maximum coordinate
  7.          of viewing pane.
  8.       4. If yes display the point which lies inside the region otherwise discard it.
  9. */
  10.  
  11.  
  12. #include "bits/stdc++.h"
  13. #include "graphics.h"
  14.  
  15. using namespace std;
  16.  
  17. struct Point
  18. {
  19.       int x;
  20.       int y;
  21.       Point(int x = 0, int y = 0)
  22.             : x(x)
  23.             , y(y) {}
  24. };
  25.  
  26. void point_clipping(vector <Point> all_points, Point p1, Point p2)
  27. {
  28.       for (Point p : all_points)
  29.       {
  30.             if (p.x >= p1.x and p.x <= p2.x and p.y >= p1.y and p.y <= p2.y)
  31.             {
  32.                   putpixel(p.x, p.y, GREEN);
  33.             }
  34.       }
  35. }
  36.  
  37. signed main()
  38. {
  39.       freopen("point_clipping_input.txt", "r", stdin);
  40.  
  41.       int num_points;
  42.       cin >> num_points;
  43.       vector <Point> all_points(num_points);
  44.       for (Point &p : all_points) cin >> p.x >> p.y;
  45.       Point p1, p2;
  46.       cin >> p1.x >> p1.y >> p2.x >> p2.y;
  47.  
  48.       int gd = DETECT;
  49.       int gm;
  50.       detectgraph(&gd, &gm);
  51.       initgraph(&gd, &gm, "");
  52.  
  53.       point_clipping(all_points, p1, p2);
  54.  
  55.       getch();
  56.       closegraph();
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement