ParaView 计算器 atan2

nci*_*cim 5 atan2 paraview

我目前正在尝试使用 ParaView 计算器过滤器将给定的笛卡尔坐标 (x,y,z) 转换为球面坐标 (r, theta, phi),其中 theta 是极角,phi 是方位角。我想在四分之一球体的域上执行此操作:

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

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

r = sqrt(坐标X^2 + 坐标Y^2 + 坐标Z^2)

θ = acos(坐标Z/r)

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

phi = atan(y/x)。

这通常是使用 C 中的atan2等额外函数来实现的。计算器过滤器或 Python 计算器过滤器似乎没有提供这样的函数。

有没有简单的方法可以使用图形界面实现像atan2这样的东西?

非常感谢任何评论,谢谢!

更新:

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

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

Nei*_*ist 6

您可以在 ParaView 中使用 Python 计算器的 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]
Run Code Online (Sandbox Code Playgroud)

因此,要将 arctan 函数与 Y 和 X 坐标一起使用,您可以执行以下操作:

arctan2([point[1] for point in points], [point[0] for point in points])
Run Code Online (Sandbox Code Playgroud)

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

points[:,0]
points[:,1]
points[:,2]
Run Code Online (Sandbox Code Playgroud)

给予

arctan2(points[:,1], points[:,0])
Run Code Online (Sandbox Code Playgroud)

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