3

我目前正在尝试使用 ParaView Calculator-Filter 将给定的笛卡尔坐标 (x,y,z) 转换为球坐标 (r, theta, phi),其中 theta 是极角,phi 是方位角。我想在四分之一球的域上做这件事:

([r_inn, r_out] 中的 r,[0, pi] 中的 theta,[0, 2pi] 中的 phi。

到目前为止,我定义了以下结果变量,它们给出了预期的结果:

r = sqrt(coordsX^2 + coordsY^2 + coordsZ^2)

theta = acos(coordsZ/r)

对于方位角向量,我知道在使用时我必须注意 (x,y) 的象限

phi = atan(y/x)。

这通常是使用 C 中的atan2之类的额外函数来实现的。Calculator Filter 或 Python Calculator Filter 似乎没有提供这样的函数。

有没有什么简单的方法可以使用图形界面来实现类似 atan2 的东西?

任何意见都非常感谢,谢谢!

更新:

在 Neil Twist 指出之后,在 Python Calculator 中,反正切函数可以称为 arctan2(y, x),我现在面临的问题是我无法通过变量 coordsX/Y 访问单元格的坐标/Z,在简单的计算器过滤器中可用。

现在,问题是:如何访问 Python 计算器中的单元格坐标?

4

1 回答 1

5

您可以在 ParaView 中使用 Python Calculator 的 numpy 扩展,但 numpy 调用了函数 arctan2 而不是 atan2。

三角函数有 numpy 文档,但令人讨厌的是你不能直接使用所有函数,例如你可以做arctan2(x1, x2),但你不能做pi而且必须使用numpy.pi

对于上下文,也有PythonCalculator文档。

访问 coordsX 和 coordsY 有点棘手,但可以使用points变量来实现。这实际上是所有点的数组,每个点都是 x、y 和 z 坐标的数组。

要使用坐标,您需要像这样提取它们:

[point[0] for point in points]
[point[1] for point in points]
[point[2] for point in points]

因此,要使用带有 Y 和 X 坐标的 arctan 函数,您可以执行以下操作:

arctan2([point[1] for point in points], [point[0] for point in points])

更新: 经过更多调查,可能有更好的方法来获取 coordsX/Y/Z:

points[:,0]
points[:,1]
points[:,2]

给予

arctan2(points[:,1], points[:,0])

另一个有用的参考是 numpy_interface算法

于 2016-10-27T11:20:23.297 回答