-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
55 lines (43 loc) · 1.35 KB
/
Copy pathexample.py
File metadata and controls
55 lines (43 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
import numpy as np
import gnc
# =============
# GNC functions
# =============
# Transforms
nu = np.array([2, 0, 0])
eta_dot = gnc.B2N(nu) # BODY to NED transformation
# Helpful functions
wp0 = [59.65918355434504, 10.62844055814729]
wp1 = [59.90875817046556, 10.71927031763238]
distance = gnc.distance_along_great_circle(wp0[0], wp0[1], wp1[0], wp1[1])
print(
f"Distance between {np.round(wp0, 2)} and {np.round(wp1, 2)} is {np.round(distance, 2)} metres"
)
# ==============
# Linear algebra
# ==============
A = np.array([
[2, 0, 0],
[1, 0, 3],
[7, 0, 5]
]) # Non-invertable matrix
# Inverting using Moore-Penrose pseudo-inverse
A_inv = gnc.linalg.moore_penrose(A)
# 3x3 skew-symmetric matrix
vector = np.array([1, 5, 3])
S = gnc.linalg.Smtrx(vector)
print(f"The Pseudo-inverse of {A} is {A_inv}")
print(f"The skew-symmetric matrix of {vector} is {S}")
# ===============
# Maths shortcuts
# ===============
# Conversion
radians = np.pi
degrees = gnc.R2D(radians)
radians2 = gnc.D2R(degrees)
speed_knots = 11
speed_ms = gnc.kts2ms(speed_knots)
speed_knots = gnc.ms2kts(speed_ms)
speed_kph = gnc.kts2kph(speed_knots)
print(f"{np.round(radians, 2)} radians is {np.round(degrees, 2)} in degrees and {np.round(radians2, 2)} in radians again")
print(f"{np.round(speed_knots, 2)} knots is {np.round(speed_ms, 2)} in m/s and {np.round(speed_kph, 2)} in km/h")