在我目前的程序中,我希望能夠繪製「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