cgse-coordinates 0.17.2__py3-none-any.whl → 0.17.4__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.
- cgse_coordinates/settings.yaml +0 -16
- {cgse_coordinates-0.17.2.dist-info → cgse_coordinates-0.17.4.dist-info}/METADATA +1 -1
- cgse_coordinates-0.17.4.dist-info/RECORD +16 -0
- {cgse_coordinates-0.17.2.dist-info → cgse_coordinates-0.17.4.dist-info}/entry_points.txt +0 -3
- egse/coordinates/__init__.py +27 -334
- egse/coordinates/avoidance.py +33 -41
- egse/coordinates/cslmodel.py +48 -57
- egse/coordinates/laser_tracker_to_dict.py +16 -25
- egse/coordinates/point.py +544 -418
- egse/coordinates/pyplot.py +117 -105
- egse/coordinates/reference_frame.py +1417 -0
- egse/coordinates/refmodel.py +311 -203
- egse/coordinates/rotation_matrix.py +95 -0
- egse/coordinates/transform3d_addon.py +292 -228
- cgse_coordinates-0.17.2.dist-info/RECORD +0 -16
- egse/coordinates/referenceFrame.py +0 -1251
- egse/coordinates/rotationMatrix.py +0 -82
- {cgse_coordinates-0.17.2.dist-info → cgse_coordinates-0.17.4.dist-info}/WHEEL +0 -0
egse/coordinates/pyplot.py
CHANGED
|
@@ -1,190 +1,202 @@
|
|
|
1
|
-
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
|
-
"""
|
|
4
|
-
This module defines some plotting functions for Reference Frames.
|
|
5
|
-
|
|
6
|
-
@author: Pierre Royer
|
|
7
|
-
"""
|
|
1
|
+
""" " This module contains plotting utility functions for reference frames."""
|
|
8
2
|
|
|
3
|
+
import matplotlib
|
|
9
4
|
import matplotlib.pyplot as plt
|
|
10
|
-
from
|
|
5
|
+
from egse.coordinates.reference_frame import ReferenceFrame
|
|
11
6
|
import numpy as np
|
|
12
7
|
import egse
|
|
13
|
-
from egse.coordinates.referenceFrame import ReferenceFrame
|
|
14
8
|
from egse.coordinates.point import Point, Points
|
|
15
9
|
|
|
16
10
|
|
|
17
|
-
def plot_reference_frame(
|
|
18
|
-
|
|
11
|
+
def plot_reference_frame(
|
|
12
|
+
frame: ReferenceFrame, master: ReferenceFrame | None = None, fig_name: str | None = None, **kwargs
|
|
13
|
+
) -> matplotlib.axes._subplots.Axes3DSubplot:
|
|
14
|
+
"""Plots a reference frame.
|
|
15
|
+
|
|
16
|
+
Use ax.set_xlim3d(min, max) to properly set the ranges of the display.
|
|
19
17
|
|
|
20
18
|
Args:
|
|
21
|
-
frame
|
|
22
|
-
master : master
|
|
23
|
-
|
|
24
|
-
kwargs : passed to matplotlib.axes._subplots.Axes3DSubplot.quiver
|
|
19
|
+
frame (ReferenceFrame): Reference frame
|
|
20
|
+
master (ReferenceFrame | None): Optional master reference frame.
|
|
21
|
+
fig_name (str): Name of the plot figure.
|
|
22
|
+
kwargs : Keyword arguments passed to matplotlib.axes._subplots.Axes3DSubplot.quiver.
|
|
25
23
|
|
|
26
24
|
Returns:
|
|
27
|
-
matplotlib.axes._subplots.Axes3DSubplot displaying the reference frame.
|
|
28
|
-
|
|
29
|
-
The three unit vectors are shown with the following colors ('RGB'):
|
|
25
|
+
matplotlib.axes._subplots.Axes3DSubplot displaying the reference frame. The three unit vectors are shown in
|
|
26
|
+
the following colours (RGB):
|
|
30
27
|
x: Red
|
|
31
28
|
y: Green
|
|
32
29
|
z: Blue
|
|
33
|
-
|
|
34
|
-
.. note::
|
|
35
|
-
Use ax.set_xlim3d(min,max) to properly set the ranges of the display
|
|
36
|
-
|
|
37
30
|
"""
|
|
31
|
+
|
|
38
32
|
if master is None:
|
|
39
|
-
|
|
33
|
+
temp_master = ReferenceFrame.create_master()
|
|
40
34
|
else:
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
35
|
+
temp_master = master.__copy__()
|
|
36
|
+
|
|
37
|
+
# Origin and unit axes of the reference frame
|
|
38
|
+
|
|
39
|
+
origin = frame.get_origin()
|
|
40
|
+
unit_axis_x = frame.get_axis("x", name="fx")
|
|
41
|
+
unit_axis_y = frame.get_axis("y", name="fy")
|
|
42
|
+
unit_axis_z = frame.get_axis("z", name="fz")
|
|
43
|
+
|
|
44
|
+
# Now expressed in the master reference frame
|
|
45
|
+
|
|
46
|
+
origin_master = origin.express_in(temp_master)[:3]
|
|
47
|
+
unit_axis_x_master = unit_axis_x.express_in(temp_master)[:3]
|
|
48
|
+
unit_axis_y_master = unit_axis_y.express_in(temp_master)[:3]
|
|
49
|
+
z_axis_master = unit_axis_z.express_in(temp_master)[:3]
|
|
50
|
+
|
|
51
|
+
del temp_master
|
|
52
|
+
|
|
53
|
+
# Coordinates of the origin, expressed in the master reference frame
|
|
54
|
+
origin_x_master, origin_y_master, origin_z_master = (
|
|
55
|
+
np.array([origin_master[0]]),
|
|
56
|
+
np.array([origin_master[1]]),
|
|
57
|
+
np.array([origin_master[2]]),
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
# Orientation of the unit vectors of the reference frame, expressed in the master reference frame
|
|
61
|
+
|
|
62
|
+
vecxx, vecyx, veczx = (
|
|
63
|
+
np.array([unit_axis_x_master[0] - origin_master[0]]),
|
|
64
|
+
np.array([unit_axis_y_master[0] - origin_master[0]]),
|
|
65
|
+
np.array([z_axis_master[0] - origin_master[0]]),
|
|
66
|
+
)
|
|
67
|
+
vecxy, vecyy, veczy = (
|
|
68
|
+
np.array([unit_axis_x_master[1] - origin_master[1]]),
|
|
69
|
+
np.array([unit_axis_y_master[1] - origin_master[1]]),
|
|
70
|
+
np.array([z_axis_master[1] - origin_master[1]]),
|
|
71
|
+
)
|
|
72
|
+
vecxz, vecyz, veczz = (
|
|
73
|
+
np.array([unit_axis_x_master[2] - origin_master[2]]),
|
|
74
|
+
np.array([unit_axis_y_master[2] - origin_master[2]]),
|
|
75
|
+
np.array([z_axis_master[2] - origin_master[2]]),
|
|
76
|
+
)
|
|
61
77
|
|
|
62
78
|
kwargs.setdefault("length", 1)
|
|
63
79
|
kwargs.setdefault("normalize", True)
|
|
64
80
|
# kwargs.setdefault('figsize', (10,10))
|
|
65
81
|
|
|
66
|
-
fig = plt.figure(
|
|
82
|
+
fig = plt.figure(fig_name, figsize=plt.figaspect(1.0))
|
|
67
83
|
ax = fig.add_subplot(projection="3d")
|
|
68
|
-
ax.quiver(
|
|
69
|
-
ax.quiver(
|
|
70
|
-
ax.quiver(
|
|
84
|
+
ax.quiver(origin_x_master, origin_y_master, origin_z_master, vecxx, vecxy, vecxz, color="r", **kwargs)
|
|
85
|
+
ax.quiver(origin_x_master, origin_y_master, origin_z_master, vecyx, vecyy, vecyz, color="g", **kwargs)
|
|
86
|
+
ax.quiver(origin_x_master, origin_y_master, origin_z_master, veczx, veczy, veczz, color="b", **kwargs)
|
|
71
87
|
# ax.axis('equal')
|
|
72
88
|
|
|
73
89
|
return ax
|
|
74
90
|
|
|
75
91
|
|
|
76
|
-
def plot_points(
|
|
77
|
-
|
|
92
|
+
def plot_points(
|
|
93
|
+
points: Points | list[Point], master=None, fig_name: str | None = None, **kwargs
|
|
94
|
+
) -> matplotlib.axes._subplots.Axes3DSubplot:
|
|
95
|
+
"""Plots the given collection of points.
|
|
96
|
+
|
|
97
|
+
Use ax.set_xlim3d(min, max) to properly set the ranges of the display.
|
|
78
98
|
|
|
79
99
|
Args:
|
|
80
|
-
points
|
|
81
|
-
master : master
|
|
82
|
-
|
|
83
|
-
kwargs : passed to matplotlib.axes._subplots.Axes3DSubplot.scatter
|
|
100
|
+
points (Points | list[Point]): Collection of points to plot.
|
|
101
|
+
master (ReferenceFrame | None): Optional master reference frame.
|
|
102
|
+
fig_name (str): Name of the plot figure.
|
|
103
|
+
kwargs : Keyword arguments passed to matplotlib.axes._subplots.Axes3DSubplot.scatter.
|
|
84
104
|
|
|
85
105
|
Returns:
|
|
86
|
-
matplotlib.axes._subplots.Axes3DSubplot displaying the
|
|
87
|
-
|
|
88
|
-
.. note::
|
|
89
|
-
Use ax.set_xlim3d(min,max) to properly set the ranges of the display.
|
|
90
|
-
|
|
106
|
+
matplotlib.axes._subplots.Axes3DSubplot displaying the given collection of points
|
|
91
107
|
"""
|
|
108
|
+
|
|
92
109
|
if master is None:
|
|
93
|
-
|
|
110
|
+
temp_master = ReferenceFrame.create_master()
|
|
94
111
|
else:
|
|
95
|
-
|
|
96
|
-
|
|
112
|
+
temp_master = master.__copy__()
|
|
113
|
+
|
|
97
114
|
if isinstance(points, list):
|
|
98
|
-
|
|
115
|
+
all_points = Points(points, reference_frame=temp_master)
|
|
99
116
|
elif isinstance(points, Points) or isinstance(points, egse.coordinates.point.Points):
|
|
100
|
-
|
|
117
|
+
all_points = points
|
|
101
118
|
else:
|
|
102
119
|
raise ValueError("If the input is a list, all items in it must be Point objects")
|
|
103
|
-
|
|
104
|
-
del
|
|
105
|
-
|
|
106
|
-
coordinates =
|
|
120
|
+
|
|
121
|
+
del temp_master
|
|
122
|
+
|
|
123
|
+
coordinates = all_points.coordinates
|
|
107
124
|
xs = coordinates[0, :]
|
|
108
125
|
ys = coordinates[1, :]
|
|
109
126
|
zs = coordinates[2, :]
|
|
110
|
-
|
|
127
|
+
|
|
111
128
|
kwargs.setdefault("s", 50)
|
|
112
129
|
kwargs.setdefault("marker", "o")
|
|
113
130
|
kwargs.setdefault("color", "k")
|
|
114
|
-
|
|
115
|
-
fig = plt.figure(
|
|
131
|
+
|
|
132
|
+
fig = plt.figure(fig_name)
|
|
116
133
|
ax = fig.add_subplot(projection="3d")
|
|
117
134
|
ax.scatter(xs, ys, zs, **kwargs)
|
|
118
135
|
|
|
119
136
|
return ax
|
|
120
137
|
|
|
121
138
|
|
|
122
|
-
def plot_vectors(
|
|
123
|
-
|
|
139
|
+
def plot_vectors(
|
|
140
|
+
points: Points | list[Point], master=None, fig_name: str | None = None, from_origin: bool = True, **kwargs
|
|
141
|
+
) -> matplotlib.axes._subplots.Axes3DSubplot:
|
|
142
|
+
"""Plots the given collection of vectors.
|
|
143
|
+
|
|
144
|
+
Use ax.set_xlim3d(min, max) to properly set the ranges of the display.
|
|
124
145
|
|
|
125
146
|
Args:
|
|
126
|
-
points
|
|
127
|
-
master : master
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
if True, all vectors are displayed starting from the origin
|
|
131
|
-
if False, all vectors go towards the origin
|
|
132
|
-
kwargs : passed to matplotlib.axes._subplots.Axes3DSubplot.scatter
|
|
147
|
+
points (Points | list[Point]): Collection of vectors to plot.
|
|
148
|
+
master (ReferenceFrame | None): Optional master reference frame.
|
|
149
|
+
fig_name (str): Name of the plot figure.
|
|
150
|
+
kwargs : Keyword arguments passed to matplotlib.axes._subplots.Axes3DSubplot.scatter.
|
|
133
151
|
|
|
134
152
|
Returns:
|
|
135
|
-
matplotlib.axes._subplots.Axes3DSubplot displaying the
|
|
136
|
-
|
|
137
|
-
.. note::
|
|
138
|
-
Use ax.set_xlim3d(min,max) to properly set the ranges of the display.
|
|
139
|
-
|
|
153
|
+
matplotlib.axes._subplots.Axes3DSubplot displaying the given collection of points
|
|
140
154
|
"""
|
|
141
155
|
|
|
142
156
|
if master is None:
|
|
143
|
-
|
|
157
|
+
temp_master = ReferenceFrame.create_master()
|
|
144
158
|
else:
|
|
145
|
-
|
|
146
|
-
|
|
159
|
+
temp_master = master.__copy__()
|
|
160
|
+
|
|
147
161
|
if isinstance(points, list):
|
|
148
|
-
|
|
162
|
+
all_points = Points(points, reference_frame=temp_master)
|
|
149
163
|
elif isinstance(points, Points) or isinstance(points, egse.coordinates.point.Points):
|
|
150
|
-
|
|
164
|
+
all_points = points
|
|
151
165
|
else:
|
|
152
166
|
raise ValueError("If the input is a list, all items in it must be Point objects")
|
|
153
|
-
#
|
|
154
|
-
del tmpmaster
|
|
155
|
-
#
|
|
156
167
|
|
|
157
|
-
|
|
168
|
+
del temp_master
|
|
169
|
+
|
|
158
170
|
kwargs.setdefault("color", "k")
|
|
159
|
-
#
|
|
160
171
|
|
|
161
|
-
#
|
|
162
|
-
|
|
172
|
+
# Prepare vector coordinates
|
|
173
|
+
|
|
174
|
+
coordinates = all_points.coordinates
|
|
163
175
|
xs = coordinates[0, :]
|
|
164
176
|
ys = coordinates[1, :]
|
|
165
177
|
zs = coordinates[2, :]
|
|
166
178
|
|
|
167
|
-
# Origin of the
|
|
168
|
-
#
|
|
169
|
-
#
|
|
170
|
-
x, y, z = points.
|
|
179
|
+
# Origin of the x, y, and z vectors
|
|
180
|
+
# -> x = The x coordinates of the origin of all vectors
|
|
181
|
+
# -> [x,y,z] = Origin of points.reference_frame
|
|
182
|
+
x, y, z = points.reference_frame.get_origin().coordinates[:3]
|
|
171
183
|
x = np.ones_like(xs) * x
|
|
172
184
|
y = np.ones_like(xs) * y
|
|
173
185
|
z = np.ones_like(xs) * z
|
|
174
186
|
|
|
175
|
-
#
|
|
187
|
+
# Plot
|
|
176
188
|
|
|
177
|
-
fig = plt.figure(
|
|
189
|
+
fig = plt.figure(fig_name)
|
|
178
190
|
ax = fig.gca(projection="3d")
|
|
179
191
|
|
|
180
|
-
if
|
|
192
|
+
if from_origin:
|
|
181
193
|
ax.quiver(x, y, z, xs - x, ys - y, zs - z, **kwargs)
|
|
182
194
|
|
|
183
|
-
elif not
|
|
195
|
+
elif not from_origin:
|
|
184
196
|
ax.quiver(xs, ys, zs, x - xs, y - ys, z - zs, **kwargs)
|
|
185
197
|
|
|
186
198
|
else:
|
|
187
|
-
print("Parameter '
|
|
199
|
+
print("Parameter 'from_origin' must be True or False")
|
|
188
200
|
print("Setting it to True by default")
|
|
189
201
|
ax.quiver(x, y, z, xs - x, ys - y, zs - z, **kwargs)
|
|
190
202
|
|