Class: Suntrack::Point3D
- Inherits:
-
Object
- Object
- Suntrack::Point3D
- Defined in:
- lib/suntrack/Point3D.rb
Instance Attribute Summary collapse
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
-
#z ⇒ Object
Returns the value of attribute z.
Instance Method Summary collapse
-
#cartesian_to_polar! ⇒ Object
Convert to polar, from Cartesian M&P, page 10.
-
#ecliptic_to_equatorial!(t) ⇒ Object
Convert ecliptic coordinates to equatorial coordinates, given an epoch M&P, page 16.
-
#equatorial_to_ecliptic!(t) ⇒ Object
Convert equatorial coordinates to ecliptic coordinates, given an epoch.
-
#equatorial_to_horizon ⇒ Object
Convert equatorial coordinates to horizon coordinates M&P, pp.
-
#initialize(x, y, z) ⇒ Point3D
constructor
A new instance of Point3D.
-
#polar_to_cartesian! ⇒ Object
Convert to Cartesian, from polar.
-
#precess_ecliptic_cartesian!(t1, t2) ⇒ Object
Precess an ecliptic Cartesian point between two epochs M&P, page 21.
-
#precess_equatorial_cartesian!(t1, t2) ⇒ Object
Precess an equatorial Cartesian point between two epochs M&P, page 21.
- #to_s ⇒ Object
Constructor Details
#initialize(x, y, z) ⇒ Point3D
Returns a new instance of Point3D.
9 10 11 12 13 |
# File 'lib/suntrack/Point3D.rb', line 9 def initialize(x, y, z) @x = x @y = y @z = z end |
Instance Attribute Details
#x ⇒ Object
Returns the value of attribute x.
8 9 10 |
# File 'lib/suntrack/Point3D.rb', line 8 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
8 9 10 |
# File 'lib/suntrack/Point3D.rb', line 8 def y @y end |
#z ⇒ Object
Returns the value of attribute z.
8 9 10 |
# File 'lib/suntrack/Point3D.rb', line 8 def z @z end |
Instance Method Details
#cartesian_to_polar! ⇒ Object
Convert to polar, from Cartesian M&P, page 10
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/suntrack/Point3D.rb', line 56 def cartesian_to_polar! # Note that this is 90-usual theta x = @x y = @y z = @z rho = (x * x) + (y * y) @x = sqrt(rho + (z * z)) @z = atn2(y, x) @z += 360 if @z < 0 @y = atn2(z, sqrt(rho)) end |
#ecliptic_to_equatorial!(t) ⇒ Object
Convert ecliptic coordinates to equatorial coordinates, given an epoch M&P, page 16
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/suntrack/Point3D.rb', line 70 def ecliptic_to_equatorial!(t) # Correction for ecliptic obliquity # M&P, page 15 # Arises from slow alterations in the Earth's orbit as a result of # perturbations from other planets. eps = 23.43929111-(46.815+(0.00059-0.001813*t)*t)*t/3600 c = cs(eps) s = sn(eps) y = @y z = @z @y = (y * c) - (s * z) @z = (y * s) + (c * z) end |
#equatorial_to_ecliptic!(t) ⇒ Object
Convert equatorial coordinates to ecliptic coordinates, given an epoch
85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/suntrack/Point3D.rb', line 85 def equatorial_to_ecliptic!(t) # Correction for ecliptic obliquity # M&P, page 15 # Arises from slow alterations in the Earth's orbit as a result of # perturbations from other planets. eps = 23.43929111-(46.815+(0.00059-0.001813*t)*t)*t/3600 y = @y z = @z c = cs(eps) s = sn(eps) @y = (y * c) + (s * z) @z = (-1 * y * s) + (c * z) end |
#equatorial_to_horizon ⇒ Object
Convert equatorial coordinates to horizon coordinates M&P, pp. 34-35
101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/suntrack/Point3D.rb', line 101 def equatorial_to_horizon cs_phi = cs(@z) sn_phi = sn(@z) cs_dec = cs(@x) sn_dec = sn(@x) cs_tau = cs(@y) x = cs_dec * sn_phi * cs_tau - sn_dec * cs_phi y = cs_dec * sn(@y) z = cs_dec * cs_phi * cs_tau + sn_dec * sn_phi pt = Suntrack::Point3D.new(x,y,z) pt.cartesian_to_polar! pt end |
#polar_to_cartesian! ⇒ Object
Convert to Cartesian, from polar. No attempt is made to confirm that the original coordinates are polar (r, theta, phi). M&P, page 10.
21 22 23 24 25 26 27 28 |
# File 'lib/suntrack/Point3D.rb', line 21 def polar_to_cartesian! # Note that this is 90-usual theta. rcst = @x * cs(@y) z = @x * sn(@y) @x = rcst * cs(@z) @y = rcst * sn(@z) @z = z end |
#precess_ecliptic_cartesian!(t1, t2) ⇒ Object
Precess an ecliptic Cartesian point between two epochs M&P, page 21
32 33 34 35 36 37 38 39 40 |
# File 'lib/suntrack/Point3D.rb', line 32 def precess_ecliptic_cartesian!(t1,t2) a = pmat_ecliptic(t1,t2) x = @x y = @y z = @z @x = a[[0,0]] * x + a[[0,1]] * y + a[[0,2]] * z @y = a[[1,0]] * x + a[[1,1]] * y + a[[1,2]] * z @z = a[[2,0]] * x + a[[2,1]] * y + a[[2,2]] * z end |
#precess_equatorial_cartesian!(t1, t2) ⇒ Object
Precess an equatorial Cartesian point between two epochs M&P, page 21
44 45 46 47 48 49 50 51 52 |
# File 'lib/suntrack/Point3D.rb', line 44 def precess_equatorial_cartesian!(t1,t2) a = pmat_equatorial(t1,t2) x = @x y = @y z = @z @x = a[[0,0]] * x + a[[0,1]] * y + a[[0,2]] * z @y = a[[1,0]] * x + a[[1,1]] * y + a[[1,2]] * z @z = a[[2,0]] * x + a[[2,1]] * y + a[[2,2]] * z end |
#to_s ⇒ Object
15 16 17 |
# File 'lib/suntrack/Point3D.rb', line 15 def to_s "(" + @x.to_s + "," + @y.to_s + "," + @z.to_s + ")" end |