Breaseman Algorithm Draw Circle | Midpoint Algorithm Draw Circle _ program Fragment

Source: Internet
Author: User

Breaseman Algorithm Draw Circle | Midpoint Algorithm Draw Circle _ program Fragment

1. Breaseman algorithm to draw round program

Due to the particularity of the algorithm, the first quadrant is limited, and the other parts are drawn by rotation.

1 voidCcgprojectworkview::bresenham_1p4circle (intRadiumConst floatlinecolor[])2 {3     intPointx, Pointy, Deltd, DELTHD, DELTDV, direction;4Pointx =0;5Pointy =Radium;6Deltd =2*(1-radium);7 8glcolor3f (linecolor[0], linecolor[1], linecolor[2]);9 Glbegin (gl_points);Ten      while(Pointy >=0) One     { Aglvertex3f (Pointx, pointy,0); -         if(Deltd <0)//D point in the circle -         { theDELTHD =2* (Deltd+pointy)-1; -             if(Delthd <=0) -Direction =1;//H Point Distance nearest -             Else +Direction =2;//D Point Distance nearest -         } +         Else if(Deltd >0)//d points outside the circle A         { atDELTDV =2* (DELTD-POINTX)-1; -             if(Deltdv <=0)//It 's the worst in point D . -Direction =2; -             Else -Direction =3;//V-point distance nearest -         } in         Else -Direction =2;//D on the Circle to         Switch(direction) +         { -          Case 1: the             //H Point Position *pointx++; $Deltd + =2*pointx+1;Panax Notoginseng              Break; -          Case 2: the             //D-Point location +pointx++; Apointy--; theDeltd + =2* (pointx-pointy+1); +              Break; -          Case 3: $             //V-point position $pointy--; -Deltd + = (-2*pointy+1); -              Break; the         default : -              Break;Wuyi         } the     } - glend (); Wu  -}

2. Midpoint algorithm Draws a circle

Due to the particularity of the algorithm, the program restricts 1/8 parts of the first quadrant.

1 //1/8 Park on the left side of the first quadrant.2 voidCcgprojectworkview::midpoint_1p8circle (intRadiumConst floatlinecolor[])3 {4     intPointx, pointy, R;5     floatDistjugefactor;6R =Radium;7     intDeltx, delty;//recursive components of the components of X and Y in the judging factor8Deltx =3;9Delty =2-R-R;TenDistjugefactor =1-R; One  APointx =0; -Pointy =Radium; -glcolor3f (linecolor[0], linecolor[1], linecolor[2]); the Glbegin (gl_points); -glvertex3f (Pointx, pointy,0); -          while(Pointx <pointy) -         { +             if(Distjugefactor <0)//Midpoint in Circle -             { +Distjugefactor + =Deltx; ADeltx + =2; atpointx++; -             } -             Else -             { -Distjugefactor + = Deltx +delty; -Deltx + =2; inDelty + =2; -pointx++; topointy--; +             } -glvertex3f (Pointx, pointy,0); the         } * glend (); $ Panax Notoginseng}

Breaseman Algorithm Draw Circle | Midpoint Algorithm Draw Circle _ program Fragment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.