Class: Coords::Spherical
- Inherits:
-
Polar
- Object
- Polar
- Coords::Spherical
show all
- Defined in:
- lib/coords/spherical.rb
Instance Method Summary
collapse
Methods inherited from Polar
#distance, #radius, #rotate, #rotate!, #theta, #translate, #translate!
Constructor Details
#initialize(radius, theta, phi) ⇒ Spherical
Returns a new instance of Spherical.
4
5
6
7
|
# File 'lib/coords/spherical.rb', line 4
def initialize(radius, theta, phi)
super(radius, theta)
@phi = phi
end
|
Instance Method Details
#==(point) ⇒ Object
36
37
38
|
# File 'lib/coords/spherical.rb', line 36
def ==(point)
radius.round(12) == point.radius.round(12) && theta.round(12) == point.theta.round(12) && phi.round(12) == point.phi.round(12)
end
|
#distance_squared(point) ⇒ Object
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/coords/spherical.rb', line 13
def distance_squared(point)
x1 = radius * Math.sin(theta) * Math.cos(phi)
x2 = point.radius * Math.sin(point.theta) * Math.cos(point.phi)
y1 = radius * Math.sin(theta) * Math.sin(phi)
y2 = point.radius * Math.sin(point.theta) * Math.sin(point.phi)
z1 = radius * Math.cos(theta)
z2 = point.radius * Math.cos(point.theta)
((x2 - x1).abs ** 2) + ((y2 - y1).abs ** 2) + ((z2 - z1).abs ** 2)
end
|
#phi ⇒ Object
9
10
11
|
# File 'lib/coords/spherical.rb', line 9
def phi
@phi
end
|
#to_cartesian ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/coords/spherical.rb', line 28
def to_cartesian
x = radius * Math.sin(theta) * Math.cos(phi)
y = radius * Math.sin(theta) * Math.sin(phi)
z = radius * Math.cos(theta)
Cartesian3d.new(x, y, z)
end
|
#to_s ⇒ Object
24
25
26
|
# File 'lib/coords/spherical.rb', line 24
def to_s
radius.to_s + ',' + theta.to_s + ',' + phi.to_s
end
|