【发布时间】:2013-04-22 19:38:30
【问题描述】:
在我当前的程序中,我希望能够绘制“DNA 形状”。我写了一个“DrawPixel(x,y,r,g,b)”函数,它可以在屏幕上绘制一个像素。从这一点开始,我实现了Bresenham line algorithm 来绘制一条线:“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);
}
}
}
目前,此实现为我提供了一些我不想要的全新功能。
大致如下:
我很高兴听到你能给我的任何信息!
更新
预期结果:
但那样更像线条。
【问题讨论】:
-
你能举个例子来说明你想画什么吗? DNA 的双螺旋是 3D 形状,因此有很多方法可以在 2D 中绘制。
-
@DavidBrown 抱歉现在更新了 :)
标签: c++ algorithm winapi math directx