Advertisement
Guest User

MidPOintAlgorithm

a guest
Feb 19th, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5. void midPoint(int X1, int Y1, int X2, int Y2)
  6. {
  7.  
  8. int dx = X2 - X1;
  9. int dy = Y2 - Y1;
  10. int a = dy;
  11. int b = -dx;
  12.  
  13. int d = 2*a + b;
  14. int i = X1, j = Y1;
  15.  
  16. cout <<"The Value of (x,y) = "<<"(" << i << "," << j <<")"<< "\n";
  17. while (i < X2)
  18. {
  19. i++;
  20. if (d <= 0)
  21. d = d + 2*a ;
  22. else
  23. {
  24. d += 2*(a + b);
  25. j++;
  26. }
  27. cout <<"The Value of (x,y) = "<<"("<< i << "," << j <<")" << "\n";
  28. }
  29. }
  30. int main()
  31. {
  32. int X1, Y1, X2, Y2;
  33.  
  34. cout<<"Enter the Value of X1: ";
  35. cin>>X1;
  36. cout<<"Enter the Value of Y1: ";
  37. cin>>Y1;
  38. cout<<"Enter the Value of X2: ";
  39. cin>>X2;
  40. cout<<"Enter the Value of Y2: ";
  41. cin>>Y2;
  42.  
  43. midPoint(X1, Y1, X2, Y2);
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement