简体   繁体   中英

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

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 ?

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 .

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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM