Home Pictures of 3D objects
Attach a trail or arrow
trails

Attach a trail

If an object is named "ball", the following statement will cause a curve to be drawn along the path of the moving object:

attach_trail(ball)

By default, the radius of the cross-section of the curve is 0.1 times the size.y of the object, and the color of the curve is the color of the object. You can change this:

attach_trail(ball, radius=0.1,
                   color=color.white )

You can also specify that only the most recent N points are displayed, which has the effect of giving the object something like a comet's tail:

attach_trail(ball, retain=30 )

By default, points are added to the trail every time the scene is rendered, which is typically about 30 times per second. No trail is started until you explicitly specify a position of the ball. You can limit the number of points per second ("pps") to be added to the trail. In the following case, 5 points are added to the trail per second (the maximum value of pps that makes sense is about 30):

attach_trail(ball, pps=5 )

By default, the trail is a curve (connected points), but you can make a trail of separated spheres:

attach_trail(ball, type='points' )

Instead of specifying an object whose position is used to add points to the curve or set of spheres, you can specify a function which yields a vector to be used as a position. If you have a function named "center" that returns a vector position, you can say this:

def center():
    return (ball1.pos+ball2.pos)/2

attach_trail(center)

In summary, you can specify a trail to be constructed as a curve or a set of spheres, using the position of an object or the vector result of a function. You can specify options to control color, radius, retain, pps, and type. The default for the "curve" option is 0, which makes a thin curve (this works best in the xy plane; if it doesn't give the result you want, set trail_radius to the desired value).

The default for the "points" option is 0.2 times the radius, 0.1 times the height or size.y, of the moving object at the time your create that object. If you don't assign your own size to an object until after you've created it, you may also need to set radius at that time. If you change radius during the motion, later portions of the trail will have this radius.You can change color or radius and the following points will be displayed with the new attributes.

start, stop, clear

You can start and stop adding points to a trail, and you can clear the trail (remove the existing points):

b = attach_trail(ball)
...
b.stop()
...
b.start()
...
b.clear()

 

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

JavaScript

Here is an example of the form to use in JavaScript:

attach_trail(ball, {type:spheres, pps:5})

Top of page