LoginSignup
17
18

More than 3 years have passed since last update.

3次元の極座標変換

Last updated at Posted at 2015-01-08

直交座標から極座標に変換 (x,y,z)→(r,θ,φ)

kyoku
var radius = Math.sqrt(x * x + y * y + z * z);
var theta = Math.acos(z / radius);
var phi = Math.atan2(y, x);

※atan2を使うのがポイント

極座標から直交座標に変換 (r,θ,φ)→(x,y,z)

chokkou
x = radius * Math.sin(theta) * Math.cos(phi);
y = radius * Math.sin(theta) * Math.sin(phi);
z = radius * Math.cos(theta);

ちょいちがうバージョン

c#ですが。


        var vv = transform.position;

        var amp = vv.magnitude;
        var radX = (-Mathf.Atan2(vv.z,vv.x) + Mathf.PI/2f);
        var radY = Mathf.Asin(vv.y/amp);

        var xx = amp * Mathf.Sin( radX) * Mathf.Cos(radY);
        var yy = amp * Mathf.Sin( radY);
        var zz = amp * Mathf.Cos( radX ) * Mathf.Cos(radY);

参考

17
18
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
18