我玩了一会儿,但我简直无法理解.
我制造了一个发射导弹的坦克,当导弹击中墙壁时,我希望它们反弹,但我希望它们能够以正确的角度反弹.
现在我没有任何障碍,当导弹越过viewportRectangle我制造的时候导弹就会反弹.
我正在寻找的解决方案是否相当先进?
有相对简单的方法吗?
我正在尝试将我在此处找到的“带处理的受控圆包装”算法移植到 Python:
现在我的目标只是让它工作,然后我根据自己的需要调整它。这个问题不是关于做圆形包装的最佳方法。
到目前为止,这是我所拥有的:
#!/usr/bin/python
# coding: utf-8
import numpy as np
import matplotlib.pyplot as plt
from random import uniform
class Ball:
def __init__(self, x, y, radius):
self.r = radius
self.acceleration = np.array([0, 0])
self.velocity = np.array([uniform(0, 1),
uniform(0, 1)])
self.position = np.array([x, y])
@property
def x(self):
return self.position[0]
@property
def y(self):
return self.position[1]
def applyForce(self, force):
self.acceleration = np.add(self.acceleration, force)
def update(self):
self.velocity = np.add(self.velocity, self.acceleration)
self.position = np.add(self.position, self.velocity)
self.acceleration *= 0
class Pack:
def __init__(self, radius, …Run Code Online (Sandbox Code Playgroud)