Class: Mageo::Polar3D

Inherits:
Object
  • Object
show all
Includes:
Math
Defined in:
lib/mageo/polar3d.rb

Overview

3次元極座標。 極座標ライブラリでは、角度は基本的に radian を使用する。 degree は人間の都合で決められた尺度だろう。 まあ人間用に degree 用インターフェイスも用意することもあるかもしれんが。

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(r, theta, phi) ⇒ Polar3D

Returns a new instance of Polar3D.



15
16
17
18
19
# File 'lib/mageo/polar3d.rb', line 15

def initialize( r, theta, phi)
  @r = r
  @theta = theta
  @phi = phi
end

Instance Attribute Details

#phiObject (readonly)

Returns the value of attribute phi.



12
13
14
# File 'lib/mageo/polar3d.rb', line 12

def phi
  @phi
end

#rObject (readonly)

Returns the value of attribute r.



12
13
14
# File 'lib/mageo/polar3d.rb', line 12

def r
  @r
end

#thetaObject (readonly)

Returns the value of attribute theta.



12
13
14
# File 'lib/mageo/polar3d.rb', line 12

def theta
  @theta
end

Instance Method Details

#minimize_phiObject

phi を 0 <= phi < 2*PI の間の角度に変換したオブジェクトを返す非破壊破壊的メソッド。



38
39
40
41
42
# File 'lib/mageo/polar3d.rb', line 38

def minimize_phi
  result = Marshal.load( Marshal.dump( self ) )
  result.minimize_phi!
  result
end

#minimize_phi!Object

phi を 0 <= phi < 2*PI の間の角度に変換する破壊破壊的メソッド。



31
32
33
34
35
# File 'lib/mageo/polar3d.rb', line 31

def minimize_phi!
  tmp = ( @phi / (2.0*PI) )
  tmp = tmp - tmp.floor
  @phi = (2.0*PI) * tmp
end

#to_v3dObject

3次元 Vector に変換。



22
23
24
25
26
27
28
# File 'lib/mageo/polar3d.rb', line 22

def to_v3d
  #Vector[ @r * cos( @theta ), @r * sin( @theta ) ]
  x = @r * sin( @theta ) * cos( @phi )
  y = @r * sin( @theta ) * sin( @phi )
  z = @r * cos( @theta )
  Mageo::Vector3D[ x, y, z ]
end