日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

c语言画实心坐标点,c-绘制实心圆的快速算法?

發布時間:2023/12/16 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c语言画实心坐标点,c-绘制实心圆的快速算法? 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這是我的做法:

我正在使用具有兩位精度的定點值(我們必須管理半點和半點的平方值)

如上一個答案所述,我也使用平方值而不是平方根。

首先,我在圓的1/8部分中檢測到圓的邊界限制。 我正在使用這些點的對稱性繪制圓的4個“邊界”。 然后,我在圓圈內繪制正方形。

與中點圓算法不同,該算法將在直徑均勻的情況下工作(并且在實數直徑情況下也有一些變化)。

如果我的解釋不清楚,請原諒我,我是法國人;)

void DrawFilledCircle(int circleDiameter, int circlePosX, int circlePosY)

{

const int FULL = (1 << 2);

const int HALF = (FULL >> 1);

int size = (circleDiameter << 2);// fixed point value for size

int ray = (size >> 1);

int dY2;

int ray2 = ray * ray;

int posmin,posmax;

int Y,X;

int x = ((circleDiameter&1)==1) ? ray : ray - HALF;

int y = HALF;

circlePosX -= (circleDiameter>>1);

circlePosY -= (circleDiameter>>1);

for (;; y+=FULL)

{

dY2 = (ray - y) * (ray - y);

for (;; x-=FULL)

{

if (dY2 + (ray - x) * (ray - x) <= ray2) continue;

if (x < y)

{

Y = (y >> 2);

posmin = Y;

posmax = circleDiameter - Y;

// Draw inside square and leave

while (Y < posmax)

{

for (X = posmin; X < posmax; X++)

setPixel(circlePosX+X, circlePosY+Y);

Y++;

}

// Just for a better understanding, the while loop does the same thing as:

// DrawSquare(circlePosX+Y, circlePosY+Y, circleDiameter - 2*Y);

return;

}

// Draw the 4 borders

X = (x >> 2) + 1;

Y = y >> 2;

posmax = circleDiameter - X;

int mirrorY = circleDiameter - Y - 1;

while (X < posmax)

{

setPixel(circlePosX+X, circlePosY+Y);

setPixel(circlePosX+X, circlePosY+mirrorY);

setPixel(circlePosX+Y, circlePosY+X);

setPixel(circlePosX+mirrorY, circlePosY+X);

X++;

}

// Just for a better understanding, the while loop does the same thing as:

// int lineSize = circleDiameter - X*2;

// Upper border:

// DrawHorizontalLine(circlePosX+X, circlePosY+Y, lineSize);

// Lower border:

// DrawHorizontalLine(circlePosX+X, circlePosY+mirrorY, lineSize);

// Left border:

// DrawVerticalLine(circlePosX+Y, circlePosY+X, lineSize);

// Right border:

// DrawVerticalLine(circlePosX+mirrorY, circlePosY+X, lineSize);

break;

}

}

}

void DrawSquare(int x, int y, int size)

{

for( int i=0 ; i

DrawHorizontalLine(x, y+i, size);

}

void DrawHorizontalLine(int x, int y, int width)

{

for(int i=0 ; i

SetPixel(x+i, y);

}

void DrawVerticalLine(int x, int y, int height)

{

for(int i=0 ; i

SetPixel(x, y+i);

}

要使用非整數直徑,可以提高定點精度或使用雙精度值。根據dY2 +(ray-x)*(ray-x)和ray2(dx2+dy2和r2)之間的差異,甚至應該可以進行某種抗鋸齒處理

總結

以上是生活随笔為你收集整理的c语言画实心坐标点,c-绘制实心圆的快速算法?的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。