Warm tip: This article is reproduced from serverfault.com, please click

python-极坐标方程给出的阵列掩模边界

(python - Array mask boundary given by polar equation)

发布于 2020-12-14 23:32:42

我有以下的极坐标方程:r(theta) = R + a*Sin(n*theta)这使得这种情节(为我所用R=1a=0.1n=5):

在此处输入图片说明

我想结束0于此边界内的二维笛卡尔数组,并1超越它(红色笔标记)。

有谁知道“优雅”的简单方法吗?

到目前为止(正在进行中),我的尝试只是想将极性网格转换为笛卡尔网格。

Questioner
SuperCiocia
Viewed
0
Prune 2020-12-15 08:00:43

无论数组采用哪种形式,每个位置的值都只是对功能值的测试:

import math

def array_val(x, y):
    # Compute the function value for the proper angle;
    # Compare to the actual radius; return 0 or 1

    theta = math.atan(y/x)    # Adjust for proper quadrant
    r = math.sqrt(x*x + y*y)
    return int(r <= (R + a * math.sin(5 * theta)))