直角坐标与极坐标,球坐标之间的转换 您所在的位置:网站首页 球体的极坐标公式 直角坐标与极坐标,球坐标之间的转换

直角坐标与极坐标,球坐标之间的转换

2024-07-15 01:57| 来源: 网络整理| 查看: 265

问题: 求直角坐标与极坐标,球坐标的转换关系

直角坐标与极坐标关系示意图 直角坐标与球坐标关系示意图

问题分析: 坐标之间的关系上图已经表示的非常清楚了,通过简单的三角函数就能够推导,\color{red}{球坐标也只是两个极坐标的叠加}。这里只是记录一下,方便需要的时候直接套用。

直角坐标转极坐标: p=\sqrt{x^2+y^2} \\ \theta=arctan(\frac{y}{x}) 极坐标转直角坐标: x=p*cos(\theta)\\ y=p*sin(\theta) 直角坐标转球坐标: r=\sqrt{x^2+y^2+z^2}\\ \theta=arctan(\frac{\sqrt{x^2+y^2}}{z})\\ \varphi=arctan(y/x) 球坐标转直角坐标: x=r*sin(\theta)*cos(\varphi)\\ y=r*sin(\theta)*sin(\varphi)\\ z=r*cos(\theta)

注意点: arctan的取值范围是[-π/2,π/2],在实际应用中需要做象限的判断。

当 (x, y) 在第一象限, 0 < θ < π/2. 当 (x, y) 在第二象限 π/2 < θ≤π. 当 (x, y) 在第三象限, -π< θ < -π/2. 当 (x, y) 在第四象限, -π/2 < θ < 0.

Unity代码:这里只记录直角与极坐标的转换,核心还是上面的公式和注意事项,球坐标或者其他语言的实现套用就可以了。

/// /// 极坐标到直角坐标 /// /// 输入的极坐标 public Vector2 Polar2Orthogonal(Vector2 polar) { /* * polar.x 极坐标的偏移距离 * polar.y 极坐标的偏移弧度 */ Vector2 orthogonal =Vector2.zero; orthogonal.x = polar.x * Mathf.Cos(polar.y); orthogonal.y= polar.x * Mathf.Sin(polar.y); return orthogonal; } /// /// 直角坐标到极坐标 /// /// 输入的直角坐标 public Vector2 Orthogonal2Polar(Vector2 orthogonal) { /* * polar.x 极坐标的偏移距离 * polar.y 极坐标的偏移弧度 */ Vector2 polar = Vector2.zero; polar.x = Mathf.Sqrt(orthogonal.x * orthogonal.x + orthogonal.y * orthogonal.y); polar.y = Mathf.Atan(orthogonal.y / orthogonal.x); //象限判断 if(orthogonal.x>0&& orthogonal.y


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有