Method: Matrix.rot

Defined in:
lib/openc3/core_ext/matrix.rb

.rot(axis, rotation_angle_in_radians) ⇒ Object

Creates a rotation matrix around one axis as defined by: mathworld.wolfram.com/RotationMatrix.html

Parameters:

  • axis (Symbol)

    Must be :X,:x,1, or :Y,:y,2, or :Z,:z,3

  • rotation_angle_in_radians (Float)

    The rotation angle in radians to rotate the maxtrix about the given axis



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/openc3/core_ext/matrix.rb', line 61

def self.rot(axis, rotation_angle_in_radians)
  rotation_matrix = Matrix.identity(3).to_a

  case axis
  when :X, :x, 1
    rotation_matrix[1][1] = cos(rotation_angle_in_radians)
    rotation_matrix[1][2] = sin(rotation_angle_in_radians)
    rotation_matrix[2][2] = rotation_matrix[1][1]
    rotation_matrix[2][1] = -(rotation_matrix[1][2])
  when :Y, :y, 2
    rotation_matrix[0][0] = cos(rotation_angle_in_radians)
    rotation_matrix[2][0] = sin(rotation_angle_in_radians)
    rotation_matrix[2][2] = rotation_matrix[0][0]
    rotation_matrix[0][2] = -(rotation_matrix[2][0])
  when :Z, :z, 3
    rotation_matrix[0][0] = cos(rotation_angle_in_radians)
    rotation_matrix[0][1] = sin(rotation_angle_in_radians)
    rotation_matrix[1][1] = rotation_matrix[0][0]
    rotation_matrix[1][0] = -(rotation_matrix[0][1])
  end

  return Matrix[*rotation_matrix]
end