How to Annotate/Label an Object (Arrow) in VPython?

1.7k Views Asked by At

I am using VPython to draw coordinate systems.

Since I did not find any readily avalible coordinate system object, I thus draw three mutual-perpendicular arrows to represent the coordinate system as follows:

y = arrow(pos=(0,0,0), axis=(6,6,0), shaftwidth=0.00001, color=color.red)
x = arrow(pos=(0,0,0), axis=(-6,6,0), shaftwidth=0.00001, color=color.green)
z = arrow(pos=(0,0,0), axis=(0,0,-10), shaftwidth=0.00001, color=color.blue)

Problem is that I cannot label/annotate them. I can only distinguish them by color, which is not very convenient.

How can I write a 'x' by the side of the x object?

2

There are 2 best solutions below

0
On

You could use a text object to do that.

text(text='x', axis=x.axis, pos=x.axis)
text(text='y', axis=y.axis, pos=y.axis)
text(text='z', axis=z.axis, pos=z.axis)

For more information see the vpython reference for text.

0
On

Maybe the label object is more appropriate to label the axes, since it always faces forward, even if you rotate the scene. Look at the VPython documentation for details.

Example (untested):

label(pos=x.axis, text='x')
label(pos=y.axis, text='y')
label(pos=z.axis, text='z')