作者:蔡麟松_800 | 来源:互联网 | 2023-05-18 16:19
Ihaveanarraythatwillbe100*100,Icanaccessanypointlike我有一个100*100的数组,我可以访问任何点,如map
I have an array that will be 100 * 100, I can access any point like
我有一个100 * 100的数组,我可以访问任何点,如
map[x][y]
It kinda will look like this:
有点像这样:
for i in map:
for ii in i:
print ii,
print '\n',
output:
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
I want to make a circle in it like:
我想在其中制作一个圆圈,如:
. . . . . # . . . . .
. . . # # . # # . . .
. . # . . . . . # . .
. # . . . . . . . # .
. # . . . . . . . # .
# . . . . . . . . . #
. # . . . . . . . # .
. # . . . . . . . # .
. . # . . . . . # . .
. . . # # . # # . . .
. . . . . # . . . . .
How can i do this?
我怎样才能做到这一点?
I want to try and make a triangulation system where i will find the point that 3 circles will overlap. Is there any other way I can achieve this.
我想尝试建立一个三角测量系统,我将找到3个圆圈重叠的点。有没有其他方法可以实现这一目标。
I just want to get the distance (dots from center) and the direction.
我只想得到距离(中心点)和方向。
2 个解决方案
8
The basic formula for a circle is
圆的基本公式是
(x - a)**2 + (y - b)**2 = r**2
Where (x, y) is a point, (a, b) is the center of the circle and r is the radius.
其中(x,y)是一个点,(a,b)是圆的中心,r是半径。
width, height = 11, 11
a, b = 5, 5
r = 5
EPSILON = 2.2
map_ = [['.' for x in range(width)] for y in range(height)]
# draw the circle
for y in range(height):
for x in range(width):
# see if we're close to (x-a)**2 + (y-b)**2 == r**2
if abs((x-a)**2 + (y-b)**2 - r**2)
This results in
这导致了
. . . # # # # # . . .
. . # . . . . . # . .
. # . . . . . . . # .
# . . . . . . . . . #
# . . . . . . . . . #
# . . . . . . . . . #
# . . . . . . . . . #
# . . . . . . . . . #
. # . . . . . . . # .
. . # . . . . . # . .
. . . # # # # # . . .
You'll have to fiddle with the value for EPSILON
with this method.
你必须使用这种方法来控制EPSILON的值。
Alternatively, iterate by angle and calculate the (x,y) coordinate as you go
或者,按角度迭代并随时计算(x,y)坐标
import math
# draw the circle
for angle in range(0, 360, 5):
x = r * math.sin(math.radians(angle)) + a
y = r * math.cos(math.radians(angle)) + b
map_[int(round(y))][int(round(x))] = '#'
Gives:
. . . # # # # # . . .
. # # . . . . . # # .
. # . . . . . . . # .
# . . . . . . . . # #
# . . . . . . . . . #
# . . . . . . . . . #
# . . . . . . . . . #
# . . . . . . . . . #
. # . . . . . . . # .
. # # . . . . . # # .
. . . # # # # # . . .