Sha256: 491be08e4dce9641171946f48529db8e58a750c5882e1a70a02d2f1f12806dd9
Contents?: true
Size: 564 Bytes
Versions: 1
Compression:
Stored size: 564 Bytes
Contents
# encoding: utf-8 module GSS class PolarPoint attr_reader :theta, :phi def initialize(theta, phi) @theta = theta @phi = phi end def to_cartesian x = Math.sin(@theta) * Math.cos(@phi) y = Math.sin(@theta) * Math.sin(@phi) z = Math.cos(@theta) [x, y, z] end def self.from_cartesian(x, y, z) theta = Math.acos(z / Math.sqrt(x * x + y * y + z * z)) phi = Math.atan2(y, x) self.new(theta, phi) end end # of class PolarPoint end # of module GSS
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
gss_generator-0.2.0 | lib/gss/polar_point.rb |