Skip to content

Commit 71a02de

Browse files
committed
Add R3 derivative function
1 parent 243df89 commit 71a02de

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

Tests/test_matrix_derivatives.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import numpy as np
2+
3+
from TerraFrame.Utilities import TransformationMatrices
4+
5+
6+
def test_r3_derivative():
7+
n = 25
8+
t = np.linspace(0, 24 * 60 * 60, n)
9+
psi = [x ** 1.2 for x in t]
10+
dpsidt = 1.2
11+
dt = 1e-4
12+
dpsi = dpsidt * dt
13+
14+
error = np.zeros((n,))
15+
16+
for i in reversed(range(n)):
17+
r1 = TransformationMatrices.r3(psi[i])
18+
r2 = TransformationMatrices.r3(psi[i] + dpsi)
19+
20+
drdt_e = (r2 - r1) / dt
21+
drdt = TransformationMatrices.dr3dt(psi[i], dpsidt)
22+
23+
error[i] = np.max(np.abs(drdt_e - drdt))
24+
25+
assert (max(error) < 1e-4)

src/TerraFrame/Utilities/TransformationMatrices.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,35 @@ def r3(psi):
9090
return r
9191

9292

93+
def dr3dt(psi, dpsi_dt):
94+
"""
95+
This function computes the time derivative of the R3 rotation matrix. As
96+
per Kaplan (2005), R3 is defined as:
97+
98+
[A] rotation matrix to transform column 3-vectors from one cartesian
99+
coordinate system to another. Final system is formed by rotating original
100+
system about its own z-axis by angle φ (counterclockwise as viewed from
101+
the +z direction):
102+
103+
Source:
104+
Kaplan, G. H., 2005, U.S. Naval Observatory Circular No. 179 (Washington:
105+
USNO), page xi
106+
107+
:param psi: Input rotation angle in radians
108+
:param dpsi_dt: The time derivative of psi where dt is in seconds
109+
:return: dR3dt matrix
110+
:type psi: float
111+
:type dpsi_dt: float
112+
:rtype: np.ndarray
113+
"""
114+
115+
dr_dt = np.array([[-np.sin(psi) * dpsi_dt, np.cos(psi) * dpsi_dt, 0.0],
116+
[-np.cos(psi) * dpsi_dt, -np.sin(psi) * dpsi_dt, 0.0],
117+
[0.0, 0.0, 0.0]])
118+
119+
return dr_dt
120+
121+
93122
def euler_angles_from_transformation(t_m):
94123
"""
95124
This function takes a transformation matrix and calculates the corresponding

0 commit comments

Comments
 (0)