Class: Motel::MovementStrategies::Elliptical
- Inherits:
-
Motel::MovementStrategy
- Object
- Motel::MovementStrategy
- Motel::MovementStrategies::Elliptical
- Defined in:
- lib/motel/movement_strategies/elliptical.rb
Overview
The Elliptical MovementStrategy moves a location on an elliptical path described by major/minor axis direction vectors, and an eccentricity / semi_latus_rectum. The path equation will also depend on the value of the relative_to field indicating if the parent location is the center or a foci of the ellipse. Lastly a speed value is required indicating the angular velocity of the location.
Constant Summary collapse
- RELATIVE_TO_CENTER =
the possible relative_to values
"center"
- RELATIVE_TO_FOCI =
"foci"
Instance Attribute Summary collapse
-
#direction_major_x ⇒ Object
Returns the value of attribute direction_major_x.
-
#direction_major_y ⇒ Object
Returns the value of attribute direction_major_y.
-
#direction_major_z ⇒ Object
Returns the value of attribute direction_major_z.
-
#direction_minor_x ⇒ Object
Returns the value of attribute direction_minor_x.
-
#direction_minor_y ⇒ Object
Returns the value of attribute direction_minor_y.
-
#direction_minor_z ⇒ Object
Returns the value of attribute direction_minor_z.
-
#eccentricity ⇒ Object
Returns the value of attribute eccentricity.
-
#relative_to ⇒ Object
Returns the value of attribute relative_to.
-
#semi_latus_rectum ⇒ Object
Returns the value of attribute semi_latus_rectum.
-
#speed ⇒ Object
Returns the value of attribute speed.
Attributes inherited from Motel::MovementStrategy
Instance Method Summary collapse
- #e ⇒ Object
- #e=(v) ⇒ Object
-
#initialize(args = {}) ⇒ Elliptical
constructor
A new instance of Elliptical.
-
#move(location, elapsed_seconds) ⇒ Object
Motel::Models::MovementStrategy::move.
- #p ⇒ Object
- #p=(v) ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Elliptical
Returns a new instance of Elliptical.
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 56 57 58 59 60 |
# File 'lib/motel/movement_strategies/elliptical.rb', line 29 def initialize(args = {}) @relative_to = args[:relative_to] if args.has_key? :relative_to @speed = args[:speed] if args.has_key? :speed @eccentricity = args[:eccentricity] if args.has_key? :eccentricity @semi_latus_rectum = args[:semi_latus_rectum] if args.has_key? :semi_latus_rectum @direction_major_x = args[:direction_major_x] if args.has_key? :direction_major_x @direction_major_y = args[:direction_major_y] if args.has_key? :direction_major_y @direction_major_z = args[:direction_major_z] if args.has_key? :direction_major_z @direction_minor_x = args[:direction_minor_x] if args.has_key? :direction_minor_x @direction_minor_y = args[:direction_minor_y] if args.has_key? :direction_minor_y @direction_minor_z = args[:direction_minor_z] if args.has_key? :direction_minor_z @direction_major_x = 1 if @direction_major_x.nil? @direction_major_y = 0 if @direction_major_y.nil? @direction_major_z = 0 if @direction_major_z.nil? @direction_minor_x = 0 if @direction_minor_x.nil? @direction_minor_y = 1 if @direction_minor_y.nil? @direction_minor_z = 0 if @direction_minor_z.nil? super(args) @direction_major_x, @direction_major_y, @direction_major_z = normalize(@direction_major_x, @direction_major_y, @direction_major_z) @direction_minor_x, @direction_minor_y, @direction_minor_z = normalize(@direction_minor_x, @direction_minor_y, @direction_minor_z) unless orthogonal?(@direction_major_x, @direction_major_y, @direction_major_z, @direction_minor_x, @direction_minor_y, @direction_minor_z) raise InvalidMovementStrategy.new("elliptical direction vectors not orthogonal") end end |
Instance Attribute Details
#direction_major_x ⇒ Object
Returns the value of attribute direction_major_x.
26 27 28 |
# File 'lib/motel/movement_strategies/elliptical.rb', line 26 def direction_major_x @direction_major_x end |
#direction_major_y ⇒ Object
Returns the value of attribute direction_major_y.
26 27 28 |
# File 'lib/motel/movement_strategies/elliptical.rb', line 26 def direction_major_y @direction_major_y end |
#direction_major_z ⇒ Object
Returns the value of attribute direction_major_z.
26 27 28 |
# File 'lib/motel/movement_strategies/elliptical.rb', line 26 def direction_major_z @direction_major_z end |
#direction_minor_x ⇒ Object
Returns the value of attribute direction_minor_x.
26 27 28 |
# File 'lib/motel/movement_strategies/elliptical.rb', line 26 def direction_minor_x @direction_minor_x end |
#direction_minor_y ⇒ Object
Returns the value of attribute direction_minor_y.
26 27 28 |
# File 'lib/motel/movement_strategies/elliptical.rb', line 26 def direction_minor_y @direction_minor_y end |
#direction_minor_z ⇒ Object
Returns the value of attribute direction_minor_z.
26 27 28 |
# File 'lib/motel/movement_strategies/elliptical.rb', line 26 def direction_minor_z @direction_minor_z end |
#eccentricity ⇒ Object
Returns the value of attribute eccentricity.
24 25 26 |
# File 'lib/motel/movement_strategies/elliptical.rb', line 24 def eccentricity @eccentricity end |
#relative_to ⇒ Object
Returns the value of attribute relative_to.
22 23 24 |
# File 'lib/motel/movement_strategies/elliptical.rb', line 22 def relative_to @relative_to end |
#semi_latus_rectum ⇒ Object
Returns the value of attribute semi_latus_rectum.
24 25 26 |
# File 'lib/motel/movement_strategies/elliptical.rb', line 24 def semi_latus_rectum @semi_latus_rectum end |
#speed ⇒ Object
Returns the value of attribute speed.
22 23 24 |
# File 'lib/motel/movement_strategies/elliptical.rb', line 22 def speed @speed end |
Instance Method Details
#e ⇒ Object
62 63 64 |
# File 'lib/motel/movement_strategies/elliptical.rb', line 62 def e eccentricity end |
#e=(v) ⇒ Object
65 66 67 |
# File 'lib/motel/movement_strategies/elliptical.rb', line 65 def e=(v) eccentricity= v end |
#move(location, elapsed_seconds) ⇒ Object
Motel::Models::MovementStrategy::move
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/motel/movement_strategies/elliptical.rb', line 81 def move(location, elapsed_seconds) # FIXME make sure this movement strategy is valid #unless valid? # Logger.warn "elliptical movement strategy not valid, not proceeding with move" # return #end ## FIXME make sure location is on ellipse #unless location_valid? location # cx,cy,cz = closest_coordinates location # Logger.warn "location #{location} not on ellipse, the closest location is #{cl}, not proceeding with move" # return #end Logger.debug "moving location #{location.id} via elliptical movement strategy" # calculate distance moved and update x,y,z accordingly distance = speed * elapsed_seconds nX,nY,nZ = coordinates_from_theta(theta(location) + distance) location.x = nX location.y = nY location.z = nZ end |
#p ⇒ Object
69 70 71 |
# File 'lib/motel/movement_strategies/elliptical.rb', line 69 def p semi_latus_rectum end |
#p=(v) ⇒ Object
72 73 74 |
# File 'lib/motel/movement_strategies/elliptical.rb', line 72 def p=(v) semi_latus_rectum = v end |