Class: Mageo::Polar2D
Overview
2次元極座標。 極座標ライブラリでは、角度は基本的に radian を使用する。 degree は人間の都合で決められた尺度だろう。 まあ人間用に degree 用インターフェイスも用意することもあるかもしれんが。
Instance Attribute Summary collapse
-
#r ⇒ Object
readonly
インスタンスメソッド.
-
#theta ⇒ Object
readonly
インスタンスメソッド.
Class Method Summary collapse
-
.minimum_radian(radian) ⇒ Object
与えられた角度 radian を 0 <= radian < 2*PI の間の角度に変換する破壊破壊的メソッド。.
Instance Method Summary collapse
-
#initialize(r, theta) ⇒ Polar2D
constructor
A new instance of Polar2D.
-
#minimize_theta ⇒ Object
theta を 0 <= theta < 2*PI の間の角度に変換したオブジェクトを返す非破壊破壊的メソッド。.
-
#minimize_theta! ⇒ Object
theta を 0 <= theta < 2*PI の間の角度に変換する破壊破壊的メソッド。.
-
#rotate(radian) ⇒ Object
極座標を回転させたオブジェクトを返す非破壊破壊的メソッド。 theta は左回りを正方向とした角度。.
-
#rotate!(radian) ⇒ Object
極座標を回転させる破壊的メソッド。 radian は左回りを正方向とした角度(ラジアン)。.
-
#to_v ⇒ Object
2次元 Vector に変換。.
Constructor Details
#initialize(r, theta) ⇒ Polar2D
Returns a new instance of Polar2D.
56 57 58 59 |
# File 'lib/mageo/polar2d.rb', line 56 def initialize( r, theta) @r = r @theta = theta end |
Instance Attribute Details
#r ⇒ Object (readonly)
インスタンスメソッド
53 54 55 |
# File 'lib/mageo/polar2d.rb', line 53 def r @r end |
#theta ⇒ Object (readonly)
インスタンスメソッド
53 54 55 |
# File 'lib/mageo/polar2d.rb', line 53 def theta @theta end |
Class Method Details
.minimum_radian(radian) ⇒ Object
与えられた角度 radian を 0 <= radian < 2*PI の間の角度に変換する破壊破壊的メソッド。
44 45 46 47 48 |
# File 'lib/mageo/polar2d.rb', line 44 def self.minimum_radian( radian ) tmp = ( radian / (2.0*PI) ) tmp = tmp - tmp.floor (2.0*PI) * tmp end |
Instance Method Details
#minimize_theta ⇒ Object
theta を 0 <= theta < 2*PI の間の角度に変換したオブジェクトを返す非破壊破壊的メソッド。
86 87 88 89 90 |
# File 'lib/mageo/polar2d.rb', line 86 def minimize_theta result = Marshal.load( Marshal.dump( self ) ) result.minimize_theta! result end |
#minimize_theta! ⇒ Object
theta を 0 <= theta < 2*PI の間の角度に変換する破壊破壊的メソッド。
81 82 83 |
# File 'lib/mageo/polar2d.rb', line 81 def minimize_theta! @theta = self.class.minimum_radian( @theta ) end |
#rotate(radian) ⇒ Object
極座標を回転させたオブジェクトを返す非破壊破壊的メソッド。 theta は左回りを正方向とした角度。
74 75 76 77 78 |
# File 'lib/mageo/polar2d.rb', line 74 def rotate( radian ) result = Marshal.load( Marshal.dump( self ) ) result.rotate!( radian ) result end |
#rotate!(radian) ⇒ Object
極座標を回転させる破壊的メソッド。 radian は左回りを正方向とした角度(ラジアン)。
68 69 70 |
# File 'lib/mageo/polar2d.rb', line 68 def rotate!( radian ) @theta += radian end |
#to_v ⇒ Object
2次元 Vector に変換。
62 63 64 |
# File 'lib/mageo/polar2d.rb', line 62 def to_v Vector[ @r * cos( @theta ), @r * sin( @theta ) ] end |