Advertisement
Fahim_7861

Bresenham's Circle Drawing Algorithm

May 1st, 2021
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. typedef pair<ll,ll>pll;
  5. #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
  6. #define eb emplace_back
  7. #define F first
  8. #define S second
  9. int main()
  10. {
  11.  
  12. fastread();
  13.  
  14. ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r,ans=0;
  15.  
  16. bool flag=false;
  17.  
  18.  
  19. ll xc,yc,x,y;
  20.  
  21.  
  22. string str;
  23.  
  24. cout<<"Input the radius r and center x,y"<<endl;
  25.  
  26. cin>>r>>xc>>yc;
  27.  
  28. x=0,y=r;
  29.  
  30. d=(3-(2*r));
  31.  
  32. cout<<"\nIteration No(i) : (Xi,Yi) di (Xi+1,Yi+1)"<<endl;
  33.  
  34. i=1;
  35.  
  36. vector<pll>v;
  37.  
  38. v.eb(x,y);
  39.  
  40. while(x<y)
  41. {
  42.  
  43.  
  44. cout<<i<<" ("<<x<<","<<y<<") "<<d<<" (";
  45.  
  46. if(d<0)
  47. {
  48. d=d+(4*x)+6;
  49. x++;
  50.  
  51. }
  52. else{
  53.  
  54. d=d+4*(x-y)+10;
  55.  
  56.  
  57. x++;
  58. y--;
  59. }
  60.  
  61. cout<<x<<","<<y<<") "<<endl;
  62.  
  63. v.eb(x,y);
  64.  
  65. i++;
  66.  
  67.  
  68. }
  69.  
  70. cout<<"\nXc : "<<xc<<",Yc:"<<yc<<endl;
  71.  
  72. cout<<"( x, y) ";
  73.  
  74. for(auto x : v)
  75. {
  76. cout<<"( "<<x.F<<","<<x.S<<") ";
  77. }
  78.  
  79. cout<<endl<<endl;
  80.  
  81. cout<<"( x+"<<xc<<",y+"<<yc<<") ";
  82.  
  83. for(auto x : v)
  84. {
  85. cout<<"( "<<x.F+xc<<","<<x.S+yc<<") ";
  86. }
  87.  
  88. cout<<endl<<endl;
  89.  
  90.  
  91.  
  92. cout<<"( -x+"<<xc<<",y+"<<yc<<") ";
  93.  
  94. for(auto x : v)
  95. {
  96. cout<<"( "<<-x.F+xc<<","<<x.S+yc<<") ";
  97. }
  98.  
  99. cout<<endl<<endl;
  100.  
  101.  
  102. cout<<"( x+"<<xc<<",-y+"<<yc<<") ";
  103.  
  104. for(auto x : v)
  105. {
  106. cout<<"( "<<x.F+xc<<","<<-x.S+yc<<") ";
  107. }
  108.  
  109. cout<<endl<<endl;
  110.  
  111. cout<<"( -x+"<<xc<<",-y+"<<yc<<") ";
  112.  
  113. for(auto x : v)
  114. {
  115. cout<<"( "<<-x.F+xc<<","<<-x.S+yc<<") ";
  116. }
  117.  
  118. cout<<endl<<endl;
  119.  
  120. cout<<"( y+"<<xc<<",x+"<<yc<<") ";
  121.  
  122. for(auto x : v)
  123. {
  124. cout<<"( "<<x.S+xc<<","<<x.F+yc<<") ";
  125. }
  126.  
  127. cout<<endl<<endl;
  128.  
  129.  
  130. cout<<"( y+"<<xc<<",-x+"<<yc<<") ";
  131.  
  132. for(auto x : v)
  133. {
  134. cout<<"( "<<x.S+xc<<","<<-x.F+yc<<") ";
  135. }
  136.  
  137. cout<<endl<<endl;
  138.  
  139.  
  140. cout<<"( -y+"<<xc<<",x+"<<yc<<") ";
  141.  
  142. for(auto x : v)
  143. {
  144. cout<<"( "<<-x.S+xc<<","<<x.F+yc<<") ";
  145. }
  146.  
  147. cout<<endl<<endl;
  148.  
  149. cout<<"( -y+"<<xc<<",-x+"<<yc<<") ";
  150.  
  151. for(auto x : v)
  152. {
  153. cout<<"( "<<-x.S+xc<<","<<-x.F+yc<<") ";
  154. }
  155.  
  156. cout<<endl;
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169. return 0;
  170.  
  171.  
  172. }
  173.  
  174.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement