@@ -102,7 +102,7 @@ def draw_text(label_text, label_position, scene):
102
102
return the_label
103
103
104
104
105
- def update_grid_numbers (focal_point , numbers_list , num_squares , scale , scene ):
105
+ def update_grid_numbers (focal_point , numbers_list , num_squares , scale , is_3d , scene ):
106
106
"""
107
107
Draw the grid numbers along the xyz axes.
108
108
@@ -114,6 +114,8 @@ def update_grid_numbers(focal_point, numbers_list, num_squares, scale, scene):
114
114
:type num_squares: `int`
115
115
:param scale: The scaled length of 1 square unit
116
116
:type scale: `float`
117
+ :param is_3d: Whether the grid is 3D or not
118
+ :type is_3d: `bool`
117
119
:param scene: The scene in which to draw the object
118
120
:type scene: class:`vpython.canvas`
119
121
"""
@@ -160,7 +162,13 @@ def update_grid_numbers(focal_point, numbers_list, num_squares, scale, scene):
160
162
for x_pos in x_coords :
161
163
# Draw the corresponding unit number at each x coordinate
162
164
txt = "{:.2f}" .format (x_pos )
163
- pos = vector (x_pos + padding , y_origin + padding , z_origin )
165
+ if is_3d :
166
+ if (sign (camera_axes .y ) * - 1 ) > 0 :
167
+ pos = vector (x_pos , max_y_coord + padding , z_origin )
168
+ else :
169
+ pos = vector (x_pos , min_y_coord - padding , z_origin )
170
+ else :
171
+ pos = vector (x_pos , y_origin - padding , z_origin )
164
172
if append :
165
173
numbers_list .append (draw_text (txt , pos , scene ))
166
174
numbers_list [len (numbers_list )- 1 ].height = get_text_size (scene )
@@ -169,13 +177,16 @@ def update_grid_numbers(focal_point, numbers_list, num_squares, scale, scene):
169
177
numbers_list [index ].pos = pos
170
178
numbers_list [index ].height = get_text_size (scene )
171
179
index += 1
172
- # Draw the axis label at either the positive or negative side away from center
173
- # If sign = -1, draw off max side, if sign = 0 or 1, draw off negative side
180
+ # Draw the axis label at the centre of the axes numbers
174
181
txt = "X"
175
- if (sign (camera_axes .x ) * - 1 ) > 0 :
176
- pos = vector (max_x_coord + 1 , y_origin , z_origin )
182
+ if (sign (camera_axes .y ) * - 1 ) > 0 :
183
+ x = (max_x_coord + min_x_coord ) / 2
184
+ y = max_y_coord + scale * 2
185
+ pos = vector (x , y , z_origin )
177
186
else :
178
- pos = vector (min_x_coord - 1 , y_origin , z_origin )
187
+ x = (max_x_coord + min_x_coord ) / 2
188
+ y = min_y_coord - scale * 2
189
+ pos = vector (x , y , z_origin )
179
190
if append :
180
191
numbers_list .append (draw_text (txt , pos , scene ))
181
192
numbers_list [len (numbers_list ) - 1 ].height = get_text_size (scene )
@@ -189,7 +200,13 @@ def update_grid_numbers(focal_point, numbers_list, num_squares, scale, scene):
189
200
for y_pos in y_coords :
190
201
# Draw the corresponding unit number at each x coordinate
191
202
txt = "{:.2f}" .format (y_pos )
192
- pos = vector (x_origin , y_pos + padding , z_origin + padding )
203
+ if is_3d :
204
+ if (sign (camera_axes .x ) * - 1 ) > 0 :
205
+ pos = vector (max_x_coord + padding , y_pos , z_origin )
206
+ else :
207
+ pos = vector (min_x_coord - padding , y_pos , z_origin )
208
+ else :
209
+ pos = vector (x_origin - padding , y_pos , z_origin )
193
210
if append :
194
211
numbers_list .append (draw_text (txt , pos , scene ))
195
212
numbers_list [len (numbers_list ) - 1 ].height = get_text_size (scene )
@@ -198,13 +215,17 @@ def update_grid_numbers(focal_point, numbers_list, num_squares, scale, scene):
198
215
numbers_list [index ].pos = pos
199
216
numbers_list [index ].height = get_text_size (scene )
200
217
index += 1
201
- # Draw the axis label at either the positive or negative side away from center
202
- # If sign = -1, draw off max side, if sign = 0 or 1, draw off negative side
218
+ # Draw the axis label at the centre of the axes numbers
203
219
txt = "Y"
204
- if (sign (camera_axes .y ) * - 1 ) > 0 :
205
- pos = vector (x_origin , max_y_coord + 1 , z_origin )
220
+ if (sign (camera_axes .x ) * - 1 ) > 0 :
221
+ x = max_x_coord + scale * 2
222
+ y = (max_y_coord + min_y_coord ) / 2
223
+ pos = vector (x , y , z_origin )
206
224
else :
207
- pos = vector (x_origin , min_y_coord - 1 , z_origin )
225
+ x = min_x_coord - scale * 2
226
+ y = (max_y_coord + min_y_coord ) / 2
227
+ pos = vector (x , y , z_origin )
228
+
208
229
if append :
209
230
numbers_list .append (draw_text (txt , pos , scene ))
210
231
numbers_list [len (numbers_list ) - 1 ].height = get_text_size (scene )
@@ -218,7 +239,10 @@ def update_grid_numbers(focal_point, numbers_list, num_squares, scale, scene):
218
239
for z_pos in z_coords :
219
240
# Draw the corresponding unit number at each x coordinate
220
241
txt = "{:.2f}" .format (z_pos )
221
- pos = vector (x_origin , y_origin - padding , z_pos + padding )
242
+ if (sign (camera_axes .x ) * - 1 ) > 0 :
243
+ pos = vector (max_x_coord + padding , y_origin , z_pos )
244
+ else :
245
+ pos = vector (min_x_coord - padding , y_origin , z_pos )
222
246
if append :
223
247
numbers_list .append (draw_text (txt , pos , scene ))
224
248
numbers_list [len (numbers_list ) - 1 ].height = get_text_size (scene )
@@ -230,10 +254,10 @@ def update_grid_numbers(focal_point, numbers_list, num_squares, scale, scene):
230
254
# Draw the axis label at either the positive or negative side away from center
231
255
# If sign = -1, draw off max side, if sign = 0 or 1, draw off negative side
232
256
txt = "Z"
233
- if (sign (camera_axes .z ) * - 1 ) > 0 :
234
- pos = vector (x_origin , y_origin , max_z_coord + 1 )
257
+ if (sign (camera_axes .x ) * - 1 ) > 0 :
258
+ pos = vector (max_x_coord + scale * 2 , y_origin , ( max_z_coord + min_z_coord ) / 2 )
235
259
else :
236
- pos = vector (x_origin , y_origin , min_z_coord - 1 )
260
+ pos = vector (min_x_coord - scale * 2 , y_origin , ( max_z_coord + min_z_coord ) / 2 )
237
261
if append :
238
262
numbers_list .append (draw_text (txt , pos , scene ))
239
263
numbers_list [len (numbers_list ) - 1 ].height = get_text_size (scene )
0 commit comments