PyAttitude 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- adi/__init__.py +2 -0
- adi/cli.py +33 -0
- adi/frames.py +114 -0
- adi/render/__init__.py +0 -0
- adi/render/pillow_backend.py +293 -0
- pyattitude-0.1.0.dist-info/METADATA +46 -0
- pyattitude-0.1.0.dist-info/RECORD +11 -0
- pyattitude-0.1.0.dist-info/WHEEL +5 -0
- pyattitude-0.1.0.dist-info/entry_points.txt +2 -0
- pyattitude-0.1.0.dist-info/licenses/LICENSE +21 -0
- pyattitude-0.1.0.dist-info/top_level.txt +1 -0
adi/__init__.py
ADDED
adi/cli.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""CLI entry point."""
|
|
2
|
+
import argparse
|
|
3
|
+
|
|
4
|
+
from .render.pillow_backend import render_sphere
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def main():
|
|
8
|
+
p = argparse.ArgumentParser(description="ADI image generator")
|
|
9
|
+
p.add_argument("--quat", nargs=4, type=float, metavar=("W", "X", "Y", "Z"))
|
|
10
|
+
p.add_argument("--roll", type=float, default=0.0)
|
|
11
|
+
p.add_argument("--pitch", type=float, default=0.0)
|
|
12
|
+
p.add_argument("--yaw", type=float, default=0.0)
|
|
13
|
+
p.add_argument("--out", default="adi.png")
|
|
14
|
+
p.add_argument("--size", type=int, default=400)
|
|
15
|
+
p.add_argument("--grid", type=int, default=15, help="grid spacing in degrees")
|
|
16
|
+
p.add_argument("--no-labels", action="store_true", help="disable axis labels")
|
|
17
|
+
p.add_argument("--2d", action="store_true", help="render classic 2D ADI instead of 3D")
|
|
18
|
+
args = p.parse_args()
|
|
19
|
+
|
|
20
|
+
if args.quat:
|
|
21
|
+
from .frames import rpy_deg
|
|
22
|
+
roll, pitch, yaw = rpy_deg(args.quat)
|
|
23
|
+
else:
|
|
24
|
+
roll, pitch, yaw = args.roll, args.pitch, args.yaw
|
|
25
|
+
|
|
26
|
+
from .render.pillow_backend import render_adu
|
|
27
|
+
img = render_adu(roll, pitch, yaw, size=args.size) if args.__dict__.get("2d") else render_sphere(roll, pitch, yaw, size=args.size, grid=args.grid, labels=not args.no_labels)
|
|
28
|
+
img.save(args.out)
|
|
29
|
+
print(f"saved {args.out} roll={roll:.2f} pitch={pitch:.2f} yaw={yaw:.2f}")
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
if __name__ == "__main__":
|
|
33
|
+
main()
|
adi/frames.py
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"""Quaternion / frame helpers. Scalar-first [w, x, y, z], Hamilton."""
|
|
2
|
+
import numpy as np
|
|
3
|
+
from scipy.spatial.transform import Rotation
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def normalize(q):
|
|
7
|
+
"""Normalize a quaternion.
|
|
8
|
+
|
|
9
|
+
Parameters
|
|
10
|
+
----------
|
|
11
|
+
q : array_like
|
|
12
|
+
Quaternion [w, x, y, z].
|
|
13
|
+
|
|
14
|
+
Returns
|
|
15
|
+
-------
|
|
16
|
+
ndarray
|
|
17
|
+
Unit quaternion.
|
|
18
|
+
"""
|
|
19
|
+
q = np.asarray(q, dtype=float).ravel()
|
|
20
|
+
n = np.linalg.norm(q)
|
|
21
|
+
if n == 0:
|
|
22
|
+
raise ValueError("zero quaternion")
|
|
23
|
+
if abs(n - 1.0) > 1e-9:
|
|
24
|
+
pass
|
|
25
|
+
return q / n
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def quat_mul(a, b):
|
|
29
|
+
"""Multiply two quaternions.
|
|
30
|
+
|
|
31
|
+
Parameters
|
|
32
|
+
----------
|
|
33
|
+
a, b : array_like
|
|
34
|
+
Quaternions [w, x, y, z].
|
|
35
|
+
|
|
36
|
+
Returns
|
|
37
|
+
-------
|
|
38
|
+
ndarray
|
|
39
|
+
Product quaternion.
|
|
40
|
+
"""
|
|
41
|
+
a = np.asarray(a, dtype=float); b = np.asarray(b, dtype=float)
|
|
42
|
+
w = a[0]*b[0] - a[1]*b[1] - a[2]*b[2] - a[3]*b[3]
|
|
43
|
+
x = a[0]*b[1] + a[1]*b[0] + a[2]*b[3] - a[3]*b[2]
|
|
44
|
+
y = a[0]*b[2] - a[1]*b[3] + a[2]*b[0] + a[3]*b[1]
|
|
45
|
+
z = a[0]*b[3] + a[1]*b[2] - a[2]*b[1] + a[3]*b[0]
|
|
46
|
+
return np.array([w, x, y, z])
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def quat_conj(q):
|
|
50
|
+
"""Conjugate of a quaternion.
|
|
51
|
+
|
|
52
|
+
Parameters
|
|
53
|
+
----------
|
|
54
|
+
q : array_like
|
|
55
|
+
Quaternion [w, x, y, z].
|
|
56
|
+
|
|
57
|
+
Returns
|
|
58
|
+
-------
|
|
59
|
+
ndarray
|
|
60
|
+
Conjugate quaternion.
|
|
61
|
+
"""
|
|
62
|
+
q = np.asarray(q, dtype=float)
|
|
63
|
+
return np.array([q[0], -q[1], -q[2], -q[3]])
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def body_to_lvlh(q_body_j2000, q_lvlh_j2000):
|
|
67
|
+
"""Convert body->J2000 and LVLH->J2000 to body->LVLH.
|
|
68
|
+
|
|
69
|
+
Parameters
|
|
70
|
+
----------
|
|
71
|
+
q_body_j2000, q_lvlh_j2000 : array_like
|
|
72
|
+
Quaternions.
|
|
73
|
+
|
|
74
|
+
Returns
|
|
75
|
+
-------
|
|
76
|
+
ndarray
|
|
77
|
+
body->LVLH quaternion.
|
|
78
|
+
"""
|
|
79
|
+
return quat_mul(quat_conj(q_lvlh_j2000), q_body_j2000)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def to_rotation(q):
|
|
83
|
+
"""Convert quaternion to scipy Rotation.
|
|
84
|
+
|
|
85
|
+
Parameters
|
|
86
|
+
----------
|
|
87
|
+
q : array_like
|
|
88
|
+
Quaternion [w, x, y, z].
|
|
89
|
+
|
|
90
|
+
Returns
|
|
91
|
+
-------
|
|
92
|
+
Rotation
|
|
93
|
+
"""
|
|
94
|
+
q = normalize(q)
|
|
95
|
+
return Rotation.from_quat([q[1], q[2], q[3], q[0]])
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def rpy_deg(q):
|
|
99
|
+
"""Convert quaternion to roll, pitch, yaw (degrees).
|
|
100
|
+
|
|
101
|
+
Parameters
|
|
102
|
+
----------
|
|
103
|
+
q : array_like
|
|
104
|
+
Quaternion [w, x, y, z].
|
|
105
|
+
|
|
106
|
+
Returns
|
|
107
|
+
-------
|
|
108
|
+
tuple
|
|
109
|
+
(roll, pitch, yaw) in degrees.
|
|
110
|
+
"""
|
|
111
|
+
r = to_rotation(q)
|
|
112
|
+
ypr = r.as_euler("ZYX", degrees=True)
|
|
113
|
+
yaw, pitch, roll = ypr
|
|
114
|
+
return float(roll), float(pitch), float(yaw)
|
adi/render/__init__.py
ADDED
|
File without changes
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
"""Pillow backend: render an ADI to a PIL Image."""
|
|
2
|
+
import math
|
|
3
|
+
|
|
4
|
+
import numpy as np
|
|
5
|
+
from PIL import Image, ImageDraw, ImageFont
|
|
6
|
+
from scipy.spatial.transform import Rotation
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def _shade(base, n, light=(0.4, 0.6, 0.7)):
|
|
10
|
+
dot = max(0.0, n[0]*light[0] + n[1]*light[1] + n[2]*light[2])
|
|
11
|
+
f = 0.35 + 0.65 * dot
|
|
12
|
+
return tuple(int(c * f) for c in base)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def render_sphere(roll, pitch, yaw=0.0, size=400, bg=(10, 10, 20), grid=15, labels=True,
|
|
16
|
+
sky=(70, 130, 220), ground=(140, 90, 45), grid_color=(200, 200, 200),
|
|
17
|
+
label_color=(220, 220, 220), horizon_color=(255, 255, 255)):
|
|
18
|
+
"""Render a 3D ADI sphere to a PIL Image.
|
|
19
|
+
|
|
20
|
+
Parameters
|
|
21
|
+
----------
|
|
22
|
+
roll, pitch, yaw : float
|
|
23
|
+
Euler angles in degrees.
|
|
24
|
+
size : int
|
|
25
|
+
Image size in pixels.
|
|
26
|
+
bg : tuple
|
|
27
|
+
Background color.
|
|
28
|
+
grid : int
|
|
29
|
+
Grid spacing in degrees.
|
|
30
|
+
labels : bool
|
|
31
|
+
Whether to draw labels.
|
|
32
|
+
sky, ground, grid_color, label_color, horizon_color : tuple
|
|
33
|
+
Colors.
|
|
34
|
+
|
|
35
|
+
Returns
|
|
36
|
+
-------
|
|
37
|
+
PIL.Image.Image
|
|
38
|
+
"""
|
|
39
|
+
img = Image.new("RGB", (size, size), bg)
|
|
40
|
+
draw = ImageDraw.Draw(img)
|
|
41
|
+
try:
|
|
42
|
+
font = ImageFont.load_default()
|
|
43
|
+
except OSError:
|
|
44
|
+
font = None
|
|
45
|
+
cx, cy = size // 2, size // 2
|
|
46
|
+
r = size // 2 - 10
|
|
47
|
+
|
|
48
|
+
# rotation body->inertial from RPY (aerospace ZYX)
|
|
49
|
+
R = Rotation.from_euler("ZYX", [yaw, pitch, roll], degrees=True).as_matrix()
|
|
50
|
+
|
|
51
|
+
for y in range(cy - r, cy + r + 1):
|
|
52
|
+
for x in range(cx - r, cx + r + 1):
|
|
53
|
+
dx = (x - cx) / r
|
|
54
|
+
dy = (y - cy) / r
|
|
55
|
+
rr2 = dx * dx + dy * dy
|
|
56
|
+
if rr2 > 1.0:
|
|
57
|
+
continue
|
|
58
|
+
dz = math.sqrt(max(0.0, 1.0 - rr2))
|
|
59
|
+
# point on sphere in view coords; normal = point
|
|
60
|
+
p_view = np.array([dx, -dy, dz]) # y up
|
|
61
|
+
# body coords
|
|
62
|
+
p_body = R.T @ p_view
|
|
63
|
+
color_base = sky if p_body[2] >= 0 else ground
|
|
64
|
+
color = _shade(color_base, p_view)
|
|
65
|
+
img.putpixel((x, y), color)
|
|
66
|
+
|
|
67
|
+
# outline
|
|
68
|
+
draw.ellipse((cx - r, cy - r, cx + r, cy + r), outline=(220, 220, 220), width=2)
|
|
69
|
+
|
|
70
|
+
# horizon great circle: points with body z = 0
|
|
71
|
+
pts = []
|
|
72
|
+
for i in range(361):
|
|
73
|
+
ang = math.radians(i)
|
|
74
|
+
# circle in body xy-plane
|
|
75
|
+
bx, by, bz = math.cos(ang), math.sin(ang), 0.0
|
|
76
|
+
p_body = np.array([bx, by, bz])
|
|
77
|
+
p_view = R @ p_body
|
|
78
|
+
if p_view[2] < 0:
|
|
79
|
+
continue
|
|
80
|
+
x = cx + p_view[0] * r
|
|
81
|
+
y = cy - p_view[1] * r
|
|
82
|
+
pts.append((x, y))
|
|
83
|
+
# draw as polyline segments (breaks when z<0)
|
|
84
|
+
seg = []
|
|
85
|
+
for i in range(361):
|
|
86
|
+
ang = math.radians(i)
|
|
87
|
+
bx, by, bz = math.cos(ang), math.sin(ang), 0.0
|
|
88
|
+
p_body = np.array([bx, by, bz])
|
|
89
|
+
p_view = R @ p_body
|
|
90
|
+
if p_view[2] < 0:
|
|
91
|
+
if len(seg) > 1:
|
|
92
|
+
draw.line(seg, fill=horizon_color, width=2)
|
|
93
|
+
seg = []
|
|
94
|
+
continue
|
|
95
|
+
x = cx + p_view[0] * r
|
|
96
|
+
y = cy - p_view[1] * r
|
|
97
|
+
seg.append((x, y))
|
|
98
|
+
if len(seg) > 1:
|
|
99
|
+
draw.line(seg, fill=(255, 255, 255), width=2)
|
|
100
|
+
|
|
101
|
+
# latitude/longitude grid on sphere
|
|
102
|
+
# parallels (latitude)
|
|
103
|
+
for lat in range(-90, 91, grid):
|
|
104
|
+
la = math.radians(lat)
|
|
105
|
+
seg = []
|
|
106
|
+
|
|
107
|
+
for i in range(361):
|
|
108
|
+
lo = math.radians(i)
|
|
109
|
+
bx = math.cos(la) * math.cos(lo)
|
|
110
|
+
by = math.cos(la) * math.sin(lo)
|
|
111
|
+
bz = math.sin(la)
|
|
112
|
+
p_view = R @ np.array([bx, by, bz])
|
|
113
|
+
if p_view[2] < 0:
|
|
114
|
+
if len(seg) > 1:
|
|
115
|
+
draw.line(seg, fill=grid_color, width=1)
|
|
116
|
+
seg = []
|
|
117
|
+
continue
|
|
118
|
+
seg.append((cx + p_view[0] * r, cy - p_view[1] * r))
|
|
119
|
+
if len(seg) > 1:
|
|
120
|
+
draw.line(seg, fill=grid_color, width=1)
|
|
121
|
+
# elevation labels on four meridians for every 30 deg latitude
|
|
122
|
+
if labels and (lat % 30 == 0):
|
|
123
|
+
for lon in (0, 90, 180, 270):
|
|
124
|
+
bx = math.cos(math.radians(lat)) * math.cos(math.radians(lon))
|
|
125
|
+
by = math.cos(math.radians(lat)) * math.sin(math.radians(lon))
|
|
126
|
+
bz = math.sin(math.radians(lat))
|
|
127
|
+
pv = R @ np.array([bx, by, bz])
|
|
128
|
+
if pv[2] >= 0:
|
|
129
|
+
t = R @ np.array([-math.sin(math.radians(lon)), math.cos(math.radians(lon)), 0.0])
|
|
130
|
+
ang = math.degrees(math.atan2(-t[1], t[0]))
|
|
131
|
+
tmp = Image.new("RGBA", (40, 16), (0, 0, 0, 0))
|
|
132
|
+
ImageDraw.Draw(tmp).text((0, 0), str(lat), fill=label_color, font=font)
|
|
133
|
+
bb = tmp.getbbox()
|
|
134
|
+
if bb:
|
|
135
|
+
tmp = tmp.crop(bb)
|
|
136
|
+
rot = tmp.rotate(-yaw, expand=True, resample=Image.BICUBIC)
|
|
137
|
+
ix = int(cx + pv[0]*r - rot.width/2)
|
|
138
|
+
iy = int(cy - pv[1]*r - rot.height/2)
|
|
139
|
+
img.paste(rot, (ix, iy), rot)
|
|
140
|
+
# meridians (longitude)
|
|
141
|
+
for lo in range(0, 360, grid):
|
|
142
|
+
lo_r = math.radians(lo)
|
|
143
|
+
seg = []
|
|
144
|
+
|
|
145
|
+
for i in range(-90, 91):
|
|
146
|
+
la = math.radians(i)
|
|
147
|
+
bx = math.cos(la) * math.cos(lo_r)
|
|
148
|
+
by = math.cos(la) * math.sin(lo_r)
|
|
149
|
+
bz = math.sin(la)
|
|
150
|
+
p_view = R @ np.array([bx, by, bz])
|
|
151
|
+
if p_view[2] < 0:
|
|
152
|
+
if len(seg) > 1:
|
|
153
|
+
draw.line(seg, fill=grid_color, width=1)
|
|
154
|
+
seg = []
|
|
155
|
+
continue
|
|
156
|
+
seg.append((cx + p_view[0] * r, cy - p_view[1] * r))
|
|
157
|
+
if len(seg) > 1:
|
|
158
|
+
draw.line(seg, fill=grid_color, width=1)
|
|
159
|
+
# longitude label for every meridian
|
|
160
|
+
if labels:
|
|
161
|
+
bx = math.cos(0) * math.cos(math.radians(lo))
|
|
162
|
+
by = math.cos(0) * math.sin(math.radians(lo))
|
|
163
|
+
bz = 0.0
|
|
164
|
+
pv = R @ np.array([bx, by, bz])
|
|
165
|
+
if pv[2] >= 0:
|
|
166
|
+
t = R @ np.array([0.0, 0.0, 1.0])
|
|
167
|
+
ang = math.degrees(math.atan2(-t[1], t[0]))
|
|
168
|
+
tmp = Image.new("RGBA", (40, 16), (0, 0, 0, 0))
|
|
169
|
+
ImageDraw.Draw(tmp).text((0, 0), str(lo), fill=label_color, font=font)
|
|
170
|
+
bb = tmp.getbbox()
|
|
171
|
+
if bb:
|
|
172
|
+
tmp = tmp.crop(bb)
|
|
173
|
+
rot = tmp.rotate(-yaw, expand=True, resample=Image.BICUBIC)
|
|
174
|
+
ix = int(cx + pv[0]*r - rot.width/2)
|
|
175
|
+
iy = int(cy - pv[1]*r - rot.height/2)
|
|
176
|
+
img.paste(rot, (ix, iy), rot)
|
|
177
|
+
|
|
178
|
+
# billboard labels (screen-upright) projected onto sphere
|
|
179
|
+
if labels:
|
|
180
|
+
try:
|
|
181
|
+
font = ImageFont.load_default()
|
|
182
|
+
except OSError:
|
|
183
|
+
font = None
|
|
184
|
+
label_items = [("X", (1, 0, 0)), ("Y", (0, 1, 0)), ("Z", (0, 0, 1)),
|
|
185
|
+
("-X", (-1, 0, 0)), ("-Y", (0, -1, 0)), ("-Z", (0, 0, -1))]
|
|
186
|
+
for text, vec in label_items:
|
|
187
|
+
p_view = R @ np.array(vec, dtype=float)
|
|
188
|
+
if p_view[2] < 0:
|
|
189
|
+
continue
|
|
190
|
+
x = cx + p_view[0] * (r + 8)
|
|
191
|
+
y = cy - p_view[1] * (r + 8)
|
|
192
|
+
draw.text((x, y), text, fill=(255, 255, 255), font=font)
|
|
193
|
+
|
|
194
|
+
# crosshair
|
|
195
|
+
draw.line((cx - 15, cy, cx + 15, cy), fill=(255, 255, 0), width=2)
|
|
196
|
+
draw.line((cx, cy - 15, cx, cy + 15), fill=(255, 255, 0), width=2)
|
|
197
|
+
|
|
198
|
+
try:
|
|
199
|
+
font = ImageFont.load_default()
|
|
200
|
+
except OSError:
|
|
201
|
+
font = None
|
|
202
|
+
draw.text((10, 10), f"Roll {roll:+.1f} Pitch {pitch:+.1f} Yaw {yaw:+.1f}", fill=(255, 255, 255), font=font)
|
|
203
|
+
return img
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def render_adu(roll, pitch, yaw=0.0, size=400, bg=(20, 20, 30)):
|
|
207
|
+
# keep original 2D ADI
|
|
208
|
+
img = Image.new("RGB", (size, size), bg)
|
|
209
|
+
draw = ImageDraw.Draw(img)
|
|
210
|
+
try:
|
|
211
|
+
font = ImageFont.load_default()
|
|
212
|
+
except OSError:
|
|
213
|
+
font = None
|
|
214
|
+
cx, cy = size // 2, size // 2
|
|
215
|
+
r = size // 2 - 10
|
|
216
|
+
draw.ellipse((cx - r, cy - r, cx + r, cy + r), outline=(200, 200, 200), width=2)
|
|
217
|
+
|
|
218
|
+
roll_rad = math.radians(roll)
|
|
219
|
+
pitch_px = pitch * 4.0
|
|
220
|
+
sky_top = (100, 170, 230); sky_bot = (40, 90, 160)
|
|
221
|
+
gnd_top = (170, 110, 60); gnd_bot = (90, 55, 30)
|
|
222
|
+
for y in range(cy - r, cy + r + 1):
|
|
223
|
+
for x in range(cx - r, cx + r + 1):
|
|
224
|
+
if (x - cx) ** 2 + (y - cy) ** 2 > r * r:
|
|
225
|
+
continue
|
|
226
|
+
dx = x - cx; dy = y - cy
|
|
227
|
+
v = -dx * math.sin(roll_rad) + dy * math.cos(roll_rad)
|
|
228
|
+
dist = math.hypot(dx, dy) / r
|
|
229
|
+
shade = 1.0 - 0.35 * dist
|
|
230
|
+
if v < -pitch_px:
|
|
231
|
+
t = (v + r) / (2 * r)
|
|
232
|
+
base = tuple(int(sky_top[i] * (1 - t) + sky_bot[i] * t) for i in range(3))
|
|
233
|
+
else:
|
|
234
|
+
t = (v + r) / (2 * r)
|
|
235
|
+
base = tuple(int(gnd_top[i] * (1 - t) + gnd_bot[i] * t) for i in range(3))
|
|
236
|
+
color = tuple(int(c * shade) for c in base)
|
|
237
|
+
img.putpixel((x, y), color)
|
|
238
|
+
|
|
239
|
+
pts = []
|
|
240
|
+
for t in range(-r, r + 1):
|
|
241
|
+
u = t; v = -pitch_px
|
|
242
|
+
x = cx + u * math.cos(roll_rad) + v * math.sin(roll_rad)
|
|
243
|
+
y = cy + u * math.sin(roll_rad) - v * math.cos(roll_rad)
|
|
244
|
+
if (x - cx) ** 2 + (y - cy) ** 2 <= r * r:
|
|
245
|
+
pts.append((x, y))
|
|
246
|
+
if len(pts) > 1:
|
|
247
|
+
draw.line(pts, fill=(255, 255, 255), width=2)
|
|
248
|
+
|
|
249
|
+
for deg in range(-30, 31, 5):
|
|
250
|
+
if deg == 0:
|
|
251
|
+
continue
|
|
252
|
+
v0 = -pitch_px + (deg * 4.0)
|
|
253
|
+
def to_xy(u, v):
|
|
254
|
+
x = cx + u * math.cos(roll_rad) + v * math.sin(roll_rad)
|
|
255
|
+
y = cy + u * math.sin(roll_rad) - v * math.cos(roll_rad)
|
|
256
|
+
return (x, y)
|
|
257
|
+
p1 = to_xy(-60, v0); p2 = to_xy(60, v0)
|
|
258
|
+
draw.line((p1[0], p1[1], p2[0], p2[1]), fill=(255, 255, 255), width=1)
|
|
259
|
+
draw.text((p2[0] + 4, p2[1]), str(deg), fill=(255, 255, 255))
|
|
260
|
+
|
|
261
|
+
draw.line((cx - 31, cy + 1, cx - 11, cy + 1), fill=(80, 80, 0), width=3)
|
|
262
|
+
draw.line((cx + 9, cy + 1, cx + 29, cy + 1), fill=(80, 80, 0), width=3)
|
|
263
|
+
draw.line((cx - 30, cy, cx - 10, cy), fill=(255, 255, 0), width=3)
|
|
264
|
+
draw.line((cx + 10, cy, cx + 30, cy), fill=(255, 255, 0), width=3)
|
|
265
|
+
draw.line((cx, cy - 5, cx, cy + 5), fill=(255, 255, 0), width=3)
|
|
266
|
+
|
|
267
|
+
for deg in (-60, -30, -20, -10, 0, 10, 20, 30, 60):
|
|
268
|
+
a = math.radians(deg)
|
|
269
|
+
x1 = cx + (r - 12) * math.sin(a)
|
|
270
|
+
y1 = cy - (r - 12) * math.cos(a)
|
|
271
|
+
x2 = cx + r * math.sin(a)
|
|
272
|
+
y2 = cy - r * math.cos(a)
|
|
273
|
+
draw.line((x1, y1, x2, y2), fill=(255, 255, 255), width=2)
|
|
274
|
+
|
|
275
|
+
ba = math.radians(roll)
|
|
276
|
+
px = cx + (r - 6) * math.sin(ba)
|
|
277
|
+
py = cy - (r - 6) * math.cos(ba)
|
|
278
|
+
draw.polygon([(px, py), (px - 6, py + 10), (px + 6, py + 10)], fill=(255, 255, 0))
|
|
279
|
+
|
|
280
|
+
try:
|
|
281
|
+
font = ImageFont.load_default()
|
|
282
|
+
except OSError:
|
|
283
|
+
font = None
|
|
284
|
+
draw.text((10, 10), f"Roll {roll:+.1f} Pitch {pitch:+.1f} Yaw {yaw:+.1f}", fill=(255, 255, 255), font=font)
|
|
285
|
+
return img
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
def render(q, size=400, mode="3d", grid=15, labels=True):
|
|
289
|
+
from ..frames import rpy_deg
|
|
290
|
+
roll, pitch, yaw = rpy_deg(q)
|
|
291
|
+
if mode == "3d":
|
|
292
|
+
return render_sphere(roll, pitch, yaw, size=size, grid=grid, labels=labels)
|
|
293
|
+
return render_adu(roll, pitch, yaw, size=size)
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: PyAttitude
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Attitude Determination Indicator (ADI) in Python
|
|
5
|
+
Requires-Python: >=3.10
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: numpy
|
|
9
|
+
Requires-Dist: scipy
|
|
10
|
+
Requires-Dist: Pillow
|
|
11
|
+
Dynamic: license-file
|
|
12
|
+
|
|
13
|
+
# Attitude Determination Indicator (ADI)
|
|
14
|
+
|
|
15
|
+
Python-based ADI that ingests LVLH or Body→J2000 quaternions and renders
|
|
16
|
+
a 3D attitude sphere (Pillow-based, headless/web-friendly).
|
|
17
|
+
|
|
18
|
+
## Features
|
|
19
|
+
- Quaternion math (normalize, multiply, conjugate, frame conversion)
|
|
20
|
+
- RPY extraction (aerospace ZYX)
|
|
21
|
+
- 3D sphere rendering with grid, labels, configurable colors
|
|
22
|
+
- FastAPI demo with interactive controls
|
|
23
|
+
- CLI for single-shot image generation
|
|
24
|
+
- Tests + CI + docs
|
|
25
|
+
|
|
26
|
+
## Install
|
|
27
|
+
```
|
|
28
|
+
pip install -r requirements.txt
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
32
|
+
```
|
|
33
|
+
python -m adi.cli --roll 20 --pitch -10 --yaw 30 --out adi.png
|
|
34
|
+
python -m adi.cli --quat 1 0 0 0 --out q.png
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## FastAPI demo
|
|
38
|
+
```
|
|
39
|
+
uvicorn examples.fastapi_demo:app
|
|
40
|
+
```
|
|
41
|
+
Open http://localhost:8000
|
|
42
|
+
|
|
43
|
+
## Tests
|
|
44
|
+
```
|
|
45
|
+
pytest --cov=adi
|
|
46
|
+
```
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
adi/__init__.py,sha256=yjPrzCqQfMfKW5xj5__xivE4aZoXX-T1_ZnqRjuLD4M,76
|
|
2
|
+
adi/cli.py,sha256=079VBoqG3L1yUuXqWSLqXYoyEgPSMx5ou5OJABK1zHY,1337
|
|
3
|
+
adi/frames.py,sha256=olp22OsIFP8Gn61zzJFoFdb1pjZLPxD829dOHzWV_90,2344
|
|
4
|
+
adi/render/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
adi/render/pillow_backend.py,sha256=ih8FsyeyOmaEyb1pmfQ7lJgjh2ullEHSnZVFSHcv1aI,11040
|
|
6
|
+
pyattitude-0.1.0.dist-info/licenses/LICENSE,sha256=F9A3y6GVGk2-jFC5om6-xrBuuCUcHyyHr9jbl9xa94g,1068
|
|
7
|
+
pyattitude-0.1.0.dist-info/METADATA,sha256=6Nl1g6PLFACSopW9whC4TrT06xbjbKKgGI85nsxcDXk,1037
|
|
8
|
+
pyattitude-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
9
|
+
pyattitude-0.1.0.dist-info/entry_points.txt,sha256=vBlOXVMemajgO-LMkR2fK0iv7t259VtdUkrGW3OQqzI,37
|
|
10
|
+
pyattitude-0.1.0.dist-info/top_level.txt,sha256=nMcwlaMqGFXzctqbFK8B5olitOpGSbJ3hXcb8vIrPGM,4
|
|
11
|
+
pyattitude-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 the-schroed
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
adi
|