1
1
from vpython import vector , compound , mag , box
2
- from numpy import sign , ceil
2
+ from numpy import sign , ceil , arange
3
3
from graphics .graphics_text import update_grid_numbers
4
4
from graphics .graphics_object2d import Marker2D
5
5
from spatialmath import SE2
@@ -21,6 +21,7 @@ def __init__(self, scene):
21
21
22
22
self .__relative_cam = True
23
23
self .__num_squares = 10
24
+ self .__scale = 0.5
24
25
25
26
# Save the current camera settings
26
27
self .camera_pos = self .__scene .camera .pos
@@ -56,7 +57,8 @@ def __init_grid(self):
56
57
self .grid_object [self .__planes_idx ] = the_grid
57
58
58
59
# Update the labels instead of recreating them
59
- update_grid_numbers (self .__focal_point , self .grid_object [self .__labels_idx ], self .__num_squares , self .__scene )
60
+ update_grid_numbers (self .__focal_point , self .grid_object [self .__labels_idx ],
61
+ self .__num_squares , self .__scale , self .__scene )
60
62
61
63
def __create_grid_objects (self ):
62
64
"""
@@ -96,24 +98,34 @@ def __create_grid_objects(self):
96
98
# min = -num_squares or 0, around the default position
97
99
# max = +num_squares or 0, around the default position
98
100
# e.g. at the origin, for negative axes: -10 -> 0, positive axes: 0 -> 10
99
- min_x_coord = x_origin + int (- (self .__num_squares / 2 ) + (sign (camera_axes .x ) * - 1 ) * (self .__num_squares / 2 ))
100
- max_x_coord = x_origin + int ((self .__num_squares / 2 ) + (sign (camera_axes .x ) * - 1 ) * (self .__num_squares / 2 ))
101
+ min_x_coord = x_origin + int (- (self .__num_squares / 2 ) +
102
+ (sign (camera_axes .x ) * - 1 ) * (self .__num_squares / 2 )) * self .__scale
103
+ max_x_coord = x_origin + int ((self .__num_squares / 2 ) +
104
+ (sign (camera_axes .x ) * - 1 ) * (self .__num_squares / 2 )) * self .__scale
101
105
102
- min_y_coord = y_origin + int (- (self .__num_squares / 2 ) + (sign (camera_axes .y ) * - 1 ) * (self .__num_squares / 2 ))
103
- max_y_coord = y_origin + int ((self .__num_squares / 2 ) + (sign (camera_axes .y ) * - 1 ) * (self .__num_squares / 2 ))
106
+ min_y_coord = y_origin + int (- (self .__num_squares / 2 ) +
107
+ (sign (camera_axes .y ) * - 1 ) * (self .__num_squares / 2 )) * self .__scale
108
+ max_y_coord = y_origin + int ((self .__num_squares / 2 ) +
109
+ (sign (camera_axes .y ) * - 1 ) * (self .__num_squares / 2 )) * self .__scale
104
110
105
- min_z_coord = z_origin + int (- (self .__num_squares / 2 ) + (sign (camera_axes .z ) * - 1 ) * (self .__num_squares / 2 ))
106
- max_z_coord = z_origin + int ((self .__num_squares / 2 ) + (sign (camera_axes .z ) * - 1 ) * (self .__num_squares / 2 ))
111
+ min_z_coord = z_origin + int (- (self .__num_squares / 2 ) +
112
+ (sign (camera_axes .z ) * - 1 ) * (self .__num_squares / 2 )) * self .__scale
113
+ max_z_coord = z_origin + int ((self .__num_squares / 2 ) +
114
+ (sign (camera_axes .z ) * - 1 ) * (self .__num_squares / 2 )) * self .__scale
115
+
116
+ x_coords = arange (min_x_coord , max_x_coord + self .__scale , self .__scale )
117
+ y_coords = arange (min_y_coord , max_y_coord + self .__scale , self .__scale )
118
+ z_coords = arange (min_z_coord , max_z_coord + self .__scale , self .__scale )
107
119
108
120
# XZ plane
109
- for x_point in range ( min_x_coord , max_x_coord + 1 ) :
121
+ for x_point in x_coords :
110
122
# Draw a line across for each x coord, along the same y-axis, from min to max z coord
111
123
xz_lines .append (create_line (
112
124
vector (x_point , y_origin , min_z_coord ),
113
125
vector (x_point , y_origin , max_z_coord ),
114
126
self .__scene
115
127
))
116
- for z_point in range ( min_z_coord , max_z_coord + 1 ) :
128
+ for z_point in z_coords :
117
129
# Draw a line across each z coord, along the same y-axis, from min to max z coord
118
130
xz_lines .append (create_line (
119
131
vector (min_x_coord , y_origin , z_point ),
@@ -122,14 +134,14 @@ def __create_grid_objects(self):
122
134
))
123
135
124
136
# XY plane
125
- for x_point in range ( min_x_coord , max_x_coord + 1 ) :
137
+ for x_point in x_coords :
126
138
# Draw a line across each x coord, along the same z-axis, from min to max y coord
127
139
xy_lines .append (create_line (
128
140
vector (x_point , min_y_coord , z_origin ),
129
141
vector (x_point , max_y_coord , z_origin ),
130
142
self .__scene
131
143
))
132
- for y_point in range ( min_y_coord , max_y_coord + 1 ) :
144
+ for y_point in y_coords :
133
145
# Draw a line across each y coord, along the same z-axis, from min to max x coord
134
146
xy_lines .append (create_line (
135
147
vector (min_x_coord , y_point , z_origin ),
@@ -138,14 +150,14 @@ def __create_grid_objects(self):
138
150
))
139
151
140
152
# YZ plane
141
- for y_point in range ( min_y_coord , max_y_coord + 1 ) :
153
+ for y_point in y_coords :
142
154
# Draw a line across each y coord, along the same x-axis, from min to max z coord
143
155
yz_lines .append (create_line (
144
156
vector (x_origin , y_point , min_z_coord ),
145
157
vector (x_origin , y_point , max_z_coord ),
146
158
self .__scene
147
159
))
148
- for z_point in range ( min_z_coord , max_z_coord + 1 ) :
160
+ for z_point in z_coords :
149
161
# Draw a line across each z coord, along the same x-axis, from min to max y coord
150
162
yz_lines .append (create_line (
151
163
vector (x_origin , min_y_coord , z_point ),
@@ -203,14 +215,20 @@ def __move_grid_objects(self):
203
215
# min = -num_squares or 0, around the default position
204
216
# max = +num_squares or 0, around the default position
205
217
# e.g. at the origin, for negative axes: -10 -> 0, positive axes: 0 -> 10
206
- min_x_coord = x_origin + int (- (self .__num_squares / 2 ) + (sign (camera_axes .x ) * - 1 ) * (self .__num_squares / 2 ))
207
- max_x_coord = x_origin + int ((self .__num_squares / 2 ) + (sign (camera_axes .x ) * - 1 ) * (self .__num_squares / 2 ))
218
+ min_x_coord = x_origin + int (- (self .__num_squares / 2 ) +
219
+ (sign (camera_axes .x ) * - 1 ) * (self .__num_squares / 2 )) * self .__scale
220
+ max_x_coord = x_origin + int ((self .__num_squares / 2 ) +
221
+ (sign (camera_axes .x ) * - 1 ) * (self .__num_squares / 2 )) * self .__scale
208
222
209
- min_y_coord = y_origin + int (- (self .__num_squares / 2 ) + (sign (camera_axes .y ) * - 1 ) * (self .__num_squares / 2 ))
210
- max_y_coord = y_origin + int ((self .__num_squares / 2 ) + (sign (camera_axes .y ) * - 1 ) * (self .__num_squares / 2 ))
223
+ min_y_coord = y_origin + int (- (self .__num_squares / 2 ) +
224
+ (sign (camera_axes .y ) * - 1 ) * (self .__num_squares / 2 )) * self .__scale
225
+ max_y_coord = y_origin + int ((self .__num_squares / 2 ) +
226
+ (sign (camera_axes .y ) * - 1 ) * (self .__num_squares / 2 )) * self .__scale
211
227
212
- min_z_coord = z_origin + int (- (self .__num_squares / 2 ) + (sign (camera_axes .z ) * - 1 ) * (self .__num_squares / 2 ))
213
- max_z_coord = z_origin + int ((self .__num_squares / 2 ) + (sign (camera_axes .z ) * - 1 ) * (self .__num_squares / 2 ))
228
+ min_z_coord = z_origin + int (- (self .__num_squares / 2 ) +
229
+ (sign (camera_axes .z ) * - 1 ) * (self .__num_squares / 2 )) * self .__scale
230
+ max_z_coord = z_origin + int ((self .__num_squares / 2 ) +
231
+ (sign (camera_axes .z ) * - 1 ) * (self .__num_squares / 2 )) * self .__scale
214
232
215
233
# Compound origins are in the middle of the bounding boxes. Thus new pos will be between max and min.
216
234
x_middle = (max_x_coord + min_x_coord ) / 2
@@ -257,6 +275,7 @@ def update_grid(self):
257
275
update_grid_numbers (self .__focal_point ,
258
276
self .grid_object [self .__labels_idx ],
259
277
self .__num_squares ,
278
+ self .__scale ,
260
279
self .__scene )
261
280
262
281
def toggle_2d_3d (self ):
0 commit comments