Graphics-Linear algorithms

Source: Internet
Author: User

Graphical algorithms: DDA (Digital differential Analyzer)

voidLineDDA (intX0,intY0,intXEnd,intyend) {    floatDX = xend-x0, dy = yend-y0, steps, K; floatXinerement, yinerement, x = x0, y =y0; if(fabs (DX) >fabs (DY)) {Steps=fabs (DX); }    Else{Steps=fabs (DY); } xinerement=float(DX)/float(steps); Yinerement=float(DY)/float(steps);    SetPixel (Round (x), round (y));  for(k =0; K < steps; k++) {x+=xinerement; Y+=yinerement;    SetPixel (Round (x), round (y)); }}


The effect is very poor, the segment part is discontinuous.

2. Bresenham ' s line algorithm

"We need to decide which of the possible pixel positions are closer to the line path at each sample step.
"Testing the sign of an integer parameter whose value was proportional to the difference between the vertical
Vertical separations of the pixel positions from the actual line path.

voidLinebres (intX0,intY0,intXEnd,intyend) {    intDX = ABS (xend-x0), DY = ABS (Yend-y0); intp =2* DY-DX; intTwody =2* dy, TWODYMINUSDX =2* (DY-DX); intx, y; if(X0 >xEnd) {x=xEnd; Y=yend; XEnd=x0; }    Else{x=x0; Y=y0;        } setpixel (x, y);  while(X <xEnd) {x++; if(P <0) P+=Twody; Else{y++; P+=TWODYMINUSDX;    } setpixel (x, y); }}

Graphics-Linear algorithms

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.