class Coords::Spherical

Public Class Methods

new(radius, theta, phi) click to toggle source
Calls superclass method Coords::Polar::new
# File lib/coords/spherical.rb, line 4
def initialize(radius, theta, phi)
  super(radius, theta)
  @phi = phi
end

Public Instance Methods

==(point) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# File lib/coords/spherical.rb, line 9
def phi
  @phi
end
to_cartesian() click to toggle source
# 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() click to toggle source
# File lib/coords/spherical.rb, line 24
def to_s
  radius.to_s + ',' + theta.to_s + ',' + phi.to_s
end