DDA算法、逐点比较法、Bresenham算法
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
CClientDC dc(this);
int x0=20, y0=40, x1=200, y1=100;
int dx = x1 - x0, dy = y1 -y0;
dc.SetPixel(x0, y0,RGB(255,0,0)); // Start at (x0, y0).
if (abs(dx) > abs(dy)) { // Absolute slope is less than 1?
double m = (double)dy / (double)dx, // Compute the slope.
y = y0 + 0.5; // Initialize rounded y value.
dx = (x1 > x0) ? 1 : -1; // Set x increment.
m *= dx; // Set y increment.
while (x0 != x1) { // Loop:
x0 += dx; // Increment x.
y += m; // Compute y incrementally.
dc.SetPixel(x0, (int)y, RGB(255,0,0)); // Draw point (truncating y).
}
}
CClientDC dc(this);
int x0=1, y0=2, x1=500, y1=115;
int dx = x1 - x0;
int dy = y1 - y0;
int d = 2 * dy - dx; // d = F(m) = F(x0, y0+1/2)
int Einc = 2 * dy ;
int NEinc = 2 * (dy -dx);
int x = x0, y = y0;
while(x < x1) {
if (d <= 0){
d = d + Einc;
x = x + 1;
}
else{
d = d + NEinc;
x = x + 1;
y = y + 1;
}
dc.SetPixel(x,y,RGB(255,0,0));
}
CClientDC dc(this);
int xa=200,ya=500,xb=400,yb=300;
{
int dx=abs(xa-xb), dy=abs(ya-yb);
int p=2*dy-dx;
int twoDy=2*dy, twoDyDx=2*(dy-dx);
int x,y,xEnd;
/*Determine which point to use as start, which as end*/
if (xa>xb)
{
x=xb;
y=yb;
xEnd=xa;
}
else{
x=xa;
y=ya;
xEnd=xb;
}
dc.SetPixel(x,y,RGB(255,0,255));
while(x
if (p<0)
p+=twoDy;
else{
y++;
p+=twoDyDx;
}
dc.SetPixel(x,y,RGB(255,0,255));
}
}