Having a vector pointing at an object

20 views
Skip to first unread message

Antoine Vauterin

unread,
Aug 20, 2016, 5:12:21 AM8/20/16
to VPython-users
Hi I was wandering if there was any way to use an objects position as the coordinate of a vector. I want to be able to do something like this:
Thank you

Anim'n of object undergoing UCM

Steve Spicklemire

unread,
Aug 20, 2016, 7:15:56 AM8/20/16
to vpytho...@googlegroups.com, Steve Spicklemire
Sure, just update the ‘pos’ and ‘axis’ attributes of the arrow object at the same time you modify the position of the object you’d with which like it to move.

ball.pos = ball.pos + v*dt
arrowObject.pos = ball.pos
arrowObject.axis = “whatever you need to axis to be”

-steve

Bruce Sherwood

unread,
Aug 20, 2016, 9:31:29 AM8/20/16
to VPython-users, Steve Spicklemire
Also, in the case of GlowScript VPython or Jupyter VPython, you can attach an arrow to a moving object like this (in the Help at glowscript.org see "Work with 3D objects" > "Attach a Trail or Arrow"):

Attach an arrow

You can attach an arrow to a moving object. The following statement will automatically display a green arrow at the current location of the ball. The arrow will have shaftwidth=0.3, and its axis and length is determined by scale*ball.axis:

attach_arrow(ball, "axis", scale=1e3,
         shaftwidth=0.3, color=color.green)

The default value of scale is 1, and the default color of the arrow is the color of the ball. You can specify any vector attribute of the moving object, not just "axis". For example, if you continually update a vector quantity ball.velocity and want to continually display an arrow representing this quantity at the location of the moving ball (with scale=1 and the color of the ball), just say this:

attach_arrow(ball, "velocity")

You can start and stop displaying the arrow:

b = attach_arrow(ball)
...
b.stop()
...
b.start()

Reply all
Reply to author
Forward
0 new messages