Class: Suntrack::Point3D

Inherits:
Object
  • Object
show all
Defined in:
lib/suntrack/Point3D.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#xObject

Returns the value of attribute x.



8
9
10
# File 'lib/suntrack/Point3D.rb', line 8

def x
  @x
end

#yObject

Returns the value of attribute y.



8
9
10
# File 'lib/suntrack/Point3D.rb', line 8

def y
  @y
end

#zObject

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



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/suntrack/Point3D.rb', line 60

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



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/suntrack/Point3D.rb', line 74

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



89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/suntrack/Point3D.rb', line 89

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.
# @param [Float] t Epoch constant
  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_horizonSuntrack::Point3D

Convert equatorial coordinates to horizon coordinates M&P, pp. 34-35

Returns:

  • (Suntrack::Point3D)

    pt polar coordinates: the altitude (y) and azimuth(z) of the input vector



107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/suntrack/Point3D.rb', line 107

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

Parameters:

  • t1 (Float)

    Epoch constant for first epoch

  • t2 (Float)

    Epoch constant for second epoch



34
35
36
37
38
39
40
41
42
# File 'lib/suntrack/Point3D.rb', line 34

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

Parameters:

  • t1 (Float)

    Epoch constant for first epoch

  • t2 (Float)

    Epoch constant for second epoch



48
49
50
51
52
53
54
55
56
# File 'lib/suntrack/Point3D.rb', line 48

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_sObject



15
16
17
# File 'lib/suntrack/Point3D.rb', line 15

def to_s
  "(" + @x.to_s + "," + @y.to_s + "," + @z.to_s + ")"
end