在我目前的程序中,我希望能够绘制“DNA 形状”。我写了一个“DrawPixel(x,y,r,g,b)”函数,它可以在屏幕上绘制一个像素。从这一点开始,我实现了Bresenham 线算法来绘制一条线:“DrawLine(x1,y1,x2,y2,r,g,b)”。
现在我意识到将图像用于 DNA 形状将是一个非常糟糕的选择(在多个方面)。所以我尝试制作一个函数来绘制 DNA 形状(因为我找不到算法)。这是目前基于画圆算法(Midpoint Circle Algorithm)的:
void D3DGHandler::DrawDNAShape(int x1, int y1, int length, int curves, int dir
int off, int r, int g, int b){
int x2Pos = sin(dir)*length+x1;
int y2Pos = cos(dir)*length+y1;
for (int i = 0; i < curves; i++) {
int xIncrease = (x2Pos / curves) * i;
int yIncrease = (y2Pos / curves) * i;
int rSquared = off * off;
int xPivot = (int)(off * 0.707107 + 0.5f);
for (int x = 0; x <= xPivot; x++) {
int y = (int)(sqrt((float)(rSquared - x*x)) + 0.5f);
DrawPixel(x1+x+xIncrease,y1+y+yIncrease,r,g,b);
DrawPixel(x1-x+xIncrease,y1+y+yIncrease,r,g,b);
DrawPixel(x1+x+xIncrease,y1-y+yIncrease,r,g,b);
DrawPixel(x1-x+xIncrease,y1-y+yIncrease,r,g,b);
DrawPixel(x1+y+xIncrease,y1+x+yIncrease,r,g,b);
DrawPixel(x1-y+xIncrease,y1+x+yIncrease,r,g,b);
DrawPixel(x1+y+xIncrease,y1-x+yIncrease,r,g,b);
DrawPixel(x1-y+xIncrease,y1-x+yIncrease,r,g,b);
}
}
}
这个实现目前为我提供了一些我不想要的全新功能。
沿着:
我很高兴听到你能给我的任何信息!
更新
预期结果:
但那样更像线。