Class: Korba::Kep

Inherits:
Object
  • Object
show all
Includes:
OrbitUtils
Defined in:
lib/korba/kep.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from OrbitUtils

#deg_to_rad, #distance, #eccentric_anomaly, #height_at_apogee, #height_at_perigee, #normalize_deg, #normalize_rad, #path_angle, #rad_to_deg, #true_anomaly, #velocity

Constructor Details

#initialize(object_name:, epoch:, semi_major_axis:, eccentricity:, inclination:, ra_of_asc_node:, arg_of_pericenter:, mean_anomaly:) ⇒ Kep



10
11
12
13
14
15
16
17
18
19
# File 'lib/korba/kep.rb', line 10

def initialize(object_name:, epoch:, semi_major_axis:, eccentricity:, inclination:, ra_of_asc_node:, arg_of_pericenter:, mean_anomaly:)
  @object_name = object_name
  @epoch = epoch
  @semi_major_axis = semi_major_axis
  @eccentricity = eccentricity
  @inclination = inclination
  @ra_of_asc_node = ra_of_asc_node
  @arg_of_pericenter = arg_of_pericenter
  @mean_anomaly = mean_anomaly
end

Instance Attribute Details

#arg_of_pericenterObject (readonly)

Returns the value of attribute arg_of_pericenter.



8
9
10
# File 'lib/korba/kep.rb', line 8

def arg_of_pericenter
  @arg_of_pericenter
end

#eccentricityObject (readonly)

Returns the value of attribute eccentricity.



8
9
10
# File 'lib/korba/kep.rb', line 8

def eccentricity
  @eccentricity
end

#epochObject (readonly)

Returns the value of attribute epoch.



8
9
10
# File 'lib/korba/kep.rb', line 8

def epoch
  @epoch
end

#inclinationObject (readonly)

Returns the value of attribute inclination.



8
9
10
# File 'lib/korba/kep.rb', line 8

def inclination
  @inclination
end

#mean_anomalyObject (readonly)

Returns the value of attribute mean_anomaly.



8
9
10
# File 'lib/korba/kep.rb', line 8

def mean_anomaly
  @mean_anomaly
end

#object_nameObject (readonly)

Returns the value of attribute object_name.



8
9
10
# File 'lib/korba/kep.rb', line 8

def object_name
  @object_name
end

#ra_of_asc_nodeObject (readonly)

Returns the value of attribute ra_of_asc_node.



8
9
10
# File 'lib/korba/kep.rb', line 8

def ra_of_asc_node
  @ra_of_asc_node
end

#semi_major_axisObject (readonly)

Returns the value of attribute semi_major_axis.



8
9
10
# File 'lib/korba/kep.rb', line 8

def semi_major_axis
  @semi_major_axis
end

Instance Method Details

#to_carObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/korba/kep.rb', line 21

def to_car
  vector_n = Vector[
    Math.sin(deg_to_rad(inclination)) * Math.sin(deg_to_rad(ra_of_asc_node)),
    -Math.sin(deg_to_rad(inclination)) * Math.cos(deg_to_rad(ra_of_asc_node)),
    Math.cos(deg_to_rad(inclination))
  ]
  vector_omega = Vector[Math.cos(deg_to_rad(ra_of_asc_node)), Math.sin(deg_to_rad(ra_of_asc_node)), 0]
  vector_m = vector_n.cross(vector_omega)

  r_angle_factor = deg_to_rad(arg_of_pericenter + true_anomaly)
  vector_r = distance * (Math.cos(r_angle_factor) * vector_omega + Math.sin(r_angle_factor) * vector_m)
  v_angle_factor = deg_to_rad(arg_of_pericenter + true_anomaly - path_angle)
  vector_v = velocity * (-Math.sin(v_angle_factor) * vector_omega + (Math.cos(v_angle_factor)) * vector_m)

  Car.new(object_name:, epoch:, x: vector_r[0], y: vector_r[1], z: vector_r[2], vx: vector_v[0], vy: vector_v[1], vz: vector_v[2])
end