在我目前的程序中,我希望能够绘制“DNA形状”。我写了一个“DrawPixel(x,y,r,g,b)”函数,它可以在屏幕上绘制一个像素。从这一点开始,我实现了Bresenham line algorithm来画一条线:“DrawLine(x1,y1,x2,y2,r,g,b)”。Directx C++ - 绘制DNA形状
现在我意识到使用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);
}
}
}
此实现目前让我一些全新的功能,我不是在寻找。
线沿线的:
我会很高兴听到你能不能给我任何信息!
更新
预期结果:
但后来方式更加线等。
你可以举一个你想画的东西的例子吗? DNA的双螺旋结构是3D形状,因此在2D中有很多方法可以绘制。 – 2013-04-22 20:07:31
@DavidBrown @DavidBrown对不起现在更新:) – 2013-04-22 20:14:44