矩阵中的实心圆(二维数组) [英] Filled circle in matrix(2D array)

查看:172
本文介绍了矩阵中的实心圆(二维数组)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用哪种算法获取实心圆点?

Which algorithm to use to get points of filled circle?

int start_X = 30; // center point
int start_Y = 30;

int r = 5;

// current point
int x; 
int y;

if(?==true)
{
map2D[x][y] = 1; // for filled circle points
}

推荐答案

您将得到一个圆的方程:

You get the equation of a circle:

其中& b是中心点坐标.所有x&满足该方程的y点是圆的一部分.要查看某个点(x1,y1)是否为

where a & b are the center point coordinates. All x & y points that satisfy this equation are part of the circle. To see if a certain point (x1, y1) is, check if

((x1 - start_X) * (x1 - start_X) + (y1 - start_Y) * (y1 - start_Y)) <= r * r

< =符号也将包括位于圆内的点.您可以安全地将点范围限制在间隔[start_X-r; startX + r]和[start_Y-r; startY + r].

The <= sign is to include the points that lie inside the circle, too. You can safely limit the point ranges in the intervals [start_X - r; startX + r] and [start_Y - r; startY + r].

这篇关于矩阵中的实心圆(二维数组)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆