void CLineColor::BresenhamLine(CDC* pDC) { int dx = abs(P1.x - P0.x); int dy = abs(P1.y - P0.y); bool bInterCharge = TRUE; int e, signX, signY, temp; signX = (P1.x > P0.x) ? 1 : ((P1.x < P0.x) ? -1 : 0); signY = (P1.y > P0.y) ? 1 : ((P1.y < P0.y) ? -1 : 0); if (dy > dx) { temp = dx; dx = dy; dy = temp; bInterCharge = FALSE; } e = -dx; CPoint p = P0; for (int i = 1; i <= dx; i++) { pDC->SetPixelV(p.x, p.y, RGB(0, 0, 255)); if (bInterCharge) p.x += signX; else p.y += signY; e += 2 * dy; if (e >= 0) { if (bInterCharge) p.y += signY; else p.x += signX; e -= 2 * dx; } } }以以上代码为模板写一个DDA算法
时间: 2023-03-27 17:00:43 浏览: 222
谈谈Android的三种网络通信方式
void CLineColor::DDALine(CDC* pDC) {
float dx = P1.x - P.x;
float dy = P1.y - P.y;
float xIncrement, yIncrement, x = P.x, y = P.y;
int steps;
if (abs(dx) > abs(dy)) {
steps = abs(dx);
xIncrement = (dx > ) ? 1 : -1;
yIncrement = dy / dx;
}
else {
steps = abs(dy);
yIncrement = (dy > ) ? 1 : -1;
xIncrement = dx / dy;
}
pDC->SetPixelV(round(x), round(y), RGB(, , 255));
for (int i = 1; i <= steps; i++) {
x += xIncrement;
y += yIncrement;
pDC->SetPixelV(round(x), round(y), RGB(, , 255));
}
}
阅读全文