Fahim_7861

Bresenham's Line Drawing Algorithm

May 1st, 2021 (edited)
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4.  
  5. #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
  6.  
  7.  
  8. int main()
  9. {
  10.  
  11. fastread();
  12.  
  13. ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r,ans=0;
  14.  
  15. bool flag=false;
  16.  
  17. string str;
  18.  
  19. ll x1,x2,y1,y2;
  20.  
  21. cin>>x1>>y1>>x2>>y2;
  22.  
  23. ll delx= abs(x2-x1);
  24.  
  25. ll dely = abs(y2-y1);
  26.  
  27.  
  28.  
  29. ll Twodely = dely*2;
  30.  
  31. ll TwoDelyMinus2delx = Twodely - (2*delx);
  32.  
  33. p = Twodely - delx;
  34.  
  35. ll preP=p;
  36.  
  37. cout<<endl;
  38.  
  39. cout<<"K Pk (Xk+1 , Yk+1)"<<endl;
  40.  
  41. cout<<endl<<endl;
  42.  
  43. for(ll k=0; k<delx; k++)
  44. {
  45. if(p<0)
  46. {
  47. p = p+Twodely;
  48. x1++;
  49.  
  50.  
  51.  
  52. }
  53. else{
  54.  
  55. p= p+TwoDelyMinus2delx;
  56.  
  57. x1++;
  58. y1++;
  59. }
  60.  
  61. cout<<k<<" "<<preP<<" ("<<x1<<" "<<y1<<")"<<endl;
  62.  
  63. preP=p;
  64. }
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72. return 0;
  73.  
  74.  
  75. }
  76.  
  77.  
Add Comment
Please, Sign In to add comment