import numpy as np
import matplotlib.pyplot as plt
def arr_circle_max(arr, r):
'''
arr: 输入矩阵
r: 半径
'''
# 需要加一步坐标移位到矩阵原点
row, col = arr.shape
for i in range(0, r):
j = int(np.sqrt(r ** 2 - i ** 2))
j_start = r - j
j_stop = r + j
i_start = r - i - 1
i_stop = r + i
if i_start > row - 1:
i_start = row - 1
if i_stop > row - 1:
i_stop = i_start
if j_stop > col - 1:
j_stop = col
if j_stop < j_start-1:
j_stop = j_start
arr[i_start, j_start:j_stop] = 1
arr[i_stop, j_start:j_stop] = 1
return arr
a = np.zeros([80, 100])
b = arr_circle_max(a, 50)
plt.imshow(b)
plt.show()
任意给一个矩阵,给定半径画圆
最新推荐文章于 2023-01-31 15:33:55 发布