Class: Orbit::Eci

Inherits:
Object
  • Object
show all
Defined in:
lib/orbit/eci.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(geo = nil, date = nil) ⇒ Eci

Returns a new instance of Eci.



19
20
21
22
23
# File 'lib/orbit/eci.rb', line 19

def initialize( geo = nil, date = nil )
  if !geo.nil? && !date.nil?
    setup( geo, date )
  end
end

Instance Attribute Details

#m_DateObject

Returns the value of attribute m_Date.



5
6
7
# File 'lib/orbit/eci.rb', line 5

def m_Date
  @m_Date
end

#m_PositionObject

Returns the value of attribute m_Position.



3
4
5
# File 'lib/orbit/eci.rb', line 3

def m_Position
  @m_Position
end

#m_VelocityObject

Returns the value of attribute m_Velocity.



4
5
6
# File 'lib/orbit/eci.rb', line 4

def m_Velocity
  @m_Velocity
end

Class Method Details

.new_with_pos_vel_gmt(pos, vel, gmt) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/orbit/eci.rb', line 7

def self.new_with_pos_vel_gmt(pos, vel, gmt)
  # puts "new_with_pos_vel_gmt #{pos}, #{vel}, #{gmt}"

  eci = self.new

  eci.m_Position = pos
  eci.m_Velocity = vel
  eci.m_Date     = gmt

  eci
end

Instance Method Details

#dateObject



69
70
71
# File 'lib/orbit/eci.rb', line 69

def date
  @m_Date
end

#positionObject

region Properties



61
62
63
# File 'lib/orbit/eci.rb', line 61

def position
  @m_Position
end

#scale_pos_vector(factor) ⇒ Object

/ <summary> / Scale the position vector by the given scaling factor. / </summary> / <param name=“factor”>The scaling factor.</param>



116
117
118
# File 'lib/orbit/eci.rb', line 116

def scale_pos_vector(factor)
  @m_Position.mul(factor)
end

#scale_vel_vector(factor) ⇒ Object

/ <summary> / Scales the velocity vector by the given scaling factor. / </summary> / <param name=“factor”>The scaling factor.</param>



124
125
126
# File 'lib/orbit/eci.rb', line 124

def scale_vel_vector(factor)
  @m_Velocity.mul(factor)
end

#setup(geo, date) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/orbit/eci.rb', line 25

def setup( geo, date )
# puts "Eci.setup( geo, #{date} )"
   mfactor = OrbitGlobals::TWO_PI * (OrbitGlobals::OMEGAE / OrbitGlobals::SEC_PER_DAY)
   lat = geo.latitude_rad
   lon = geo.longitude_rad
   alt = geo.altitude

   # Calculate Local Mean Sidereal Time (theta)
   theta = OrbitGlobals.time_to_lmst( date, lon )
   c = 1.0 / Math.sqrt(1.0 + OrbitGlobals::F * (OrbitGlobals::F - 2.0) * OrbitGlobals::sqr(Math.sin(lat)))
   s = ((1.0 - OrbitGlobals::F) ** 2 ) * c
   achcp = (OrbitGlobals::XKMPER * c + alt) * Math.cos(lat)

   @m_Date = date
   @m_Position = Vector.new()

   @m_Position.m_x = achcp * Math.cos(theta)                    # km
   @m_Position.m_y = achcp * Math.sin(theta)                    # km
   @m_Position.m_z = (OrbitGlobals::XKMPER * s + alt) * Math.sin(lat) # km
   @m_Position.m_w = Math.sqrt(OrbitGlobals::sqr(@m_Position.m_x) +
      OrbitGlobals::sqr(@m_Position.m_y) +
      OrbitGlobals::sqr(@m_Position.m_z))            # range, km

   @m_Velocity = Vector.new()

   @m_Velocity.m_x = -mfactor * @m_Position.m_y               # km / sec
   @m_Velocity.m_y =  mfactor * @m_Position.m_x
   @m_Velocity.m_z = 0.0
   @m_Velocity.m_w = Math.sqrt(OrbitGlobals::sqr(@m_Velocity.m_x) +  # range rate km/sec^2
      OrbitGlobals::sqr(@m_Velocity.m_y))
end

#to_geoObject

#####################################/ Return the corresponding geodetic position (based on the current ECI coordinates/Julian date). Assumes the earth is an oblate spheroid as defined in WGS ‘72. Reference: The 1992 Astronomical Almanac, page K12. Reference: www.celestrak.com (Dr. TS Kelso)



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/orbit/eci.rb', line 81

def to_geo
 # puts "to_geo"
  theta = OrbitGlobals::actan(@m_Position.m_y, @m_Position.m_x)
  # puts "theta: #{theta}"
  # puts "m_Date: #{@m_Date}"
  lon   = (theta - OrbitGlobals.time_to_gmst( @m_Date )) % OrbitGlobals::TWO_PI

  if (lon < 0.0)
     lon += OrbitGlobals::TWO_PI  # "wrap" negative modulo
   end

  r   = Math.sqrt(OrbitGlobals.sqr(@m_Position.m_x) + OrbitGlobals.sqr(@m_Position.m_y))
  e2  = OrbitGlobals::F * (2.0 - OrbitGlobals::F)
  lat = OrbitGlobals.actan(@m_Position.m_z, r)

  delta = 1.0e-07
  phi = nil
  c = nil

  begin
     phi = lat
     c   = 1.0 / Math.sqrt(1.0 - e2 * OrbitGlobals::sqr(Math.sin(phi)))
     lat = OrbitGlobals::actan(@m_Position.m_z + OrbitGlobals::XKMPER * c * e2 * Math.sin(phi), r)
  end while ((lat - phi).abs > delta)

  alt = r / Math.cos(lat) - OrbitGlobals::XKMPER * c

  return GeocentricCoordinates.new(lat, lon, alt) # radians, radians, kilometers
end

#velocityObject



65
66
67
# File 'lib/orbit/eci.rb', line 65

def velocity
  @m_Velocity
end