椭球体内的弹跳球和其他形状vpython

2024-06-25 06:12:01 发布

您现在位置:Python中文网/ 问答频道 /正文

怎么做? 我相信这应该很简单…我试过了 喜欢往正确的方向推(新手)

lips = ellipsoid(pos=vector(0,0,0),opacity=.4)
lips.axis=vector(2,0,0)


ball = sphere (color = color.green, radius = 0.1, make_trail=True, retain=200)
ball.mass = 1.0
ball.p = vector (-0.15, -0.23, +0.27)

dt = 0.3
while True:
    rate(200)
    ball.pos = ball.pos + (ball.p/ball.mass)*dt
    if not (lips > ball.pos.x > -lips):
        ball.p.x = -ball.p.x
    if not (lips > ball.pos.y > -lips):
        ball.p.y = -ball.p.y
    if not (lips > ball.pos.z > -lips):
        ball.p.z = -ball.p.z

Tags: postrueifdtnot方向masscolor