Module: Ephem::Core::Rotation

Defined in:
lib/ephem/core/rotation.rb

Overview

Builds and applies 3x3 rotation matrices. Kernel-agnostic: callers choose the axis sequence and order that matches their frame convention.

The elementary rotations use the coordinate-frame (passive) convention: they express a fixed vector in a frame rotated by +angle about the axis

Class Method Summary collapse

Class Method Details

.about_x(angle) ⇒ Array<Array<Float>>

Returns rotation about the X axis.

Parameters:

  • angle (Numeric)

    rotation angle in radians

Returns:

  • (Array<Array<Float>>)

    rotation about the X axis



13
14
15
16
17
18
19
20
21
# File 'lib/ephem/core/rotation.rb', line 13

def self.about_x(angle)
  cosine = Math.cos(angle)
  sine = Math.sin(angle)
  [
    [1.0, 0.0, 0.0],
    [0.0, cosine, sine],
    [0.0, -sine, cosine]
  ]
end

.about_y(angle) ⇒ Array<Array<Float>>

Returns rotation about the Y axis.

Parameters:

  • angle (Numeric)

    rotation angle in radians

Returns:

  • (Array<Array<Float>>)

    rotation about the Y axis



25
26
27
28
29
30
31
32
33
# File 'lib/ephem/core/rotation.rb', line 25

def self.about_y(angle)
  cosine = Math.cos(angle)
  sine = Math.sin(angle)
  [
    [cosine, 0.0, -sine],
    [0.0, 1.0, 0.0],
    [sine, 0.0, cosine]
  ]
end

.about_z(angle) ⇒ Array<Array<Float>>

Returns rotation about the Z axis.

Parameters:

  • angle (Numeric)

    rotation angle in radians

Returns:

  • (Array<Array<Float>>)

    rotation about the Z axis



37
38
39
40
41
42
43
44
45
# File 'lib/ephem/core/rotation.rb', line 37

def self.about_z(angle)
  cosine = Math.cos(angle)
  sine = Math.sin(angle)
  [
    [cosine, sine, 0.0],
    [-sine, cosine, 0.0],
    [0.0, 0.0, 1.0]
  ]
end

.apply(matrix, vector) ⇒ Core::Vector

Applies a rotation matrix to a vector.

Parameters:

  • matrix (Array<Array<Float>>)

    a 3x3 rotation matrix

  • vector (Core::Vector, Array<Numeric>)

    the vector to rotate

Returns:



61
62
63
64
65
66
67
68
# File 'lib/ephem/core/rotation.rb', line 61

def self.apply(matrix, vector)
  x, y, z = vector.to_a
  Vector.new(
    matrix[0][0] * x + matrix[0][1] * y + matrix[0][2] * z,
    matrix[1][0] * x + matrix[1][1] * y + matrix[1][2] * z,
    matrix[2][0] * x + matrix[2][1] * y + matrix[2][2] * z
  )
end

.multiply(*matrices) ⇒ Array<Array<Float>>

Product of rotation matrices in the given order, as standard matrix multiplication: multiply(a, b, c) returns a * b * c.

Parameters:

  • matrices (Array<Array<Array<Float>>>)

    one or more 3x3 matrices

Returns:

  • (Array<Array<Float>>)

    the combined rotation matrix



52
53
54
# File 'lib/ephem/core/rotation.rb', line 52

def self.multiply(*matrices)
  matrices.reduce { |product, matrix| multiply_pair(product, matrix) }
end