问题标签 [pymunk]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
527 浏览

python - pymunk 更新了形状过滤器的使用

我试图检测从我的玩家位置开始的段的第一个形状,但我不想检测到玩家。

在之前的 pymunk 版本中,pymunk.Space.segment_query_first 函数接受一个整数作为 shape_filter,它只检测该整数组中的形状。这工作得很好,但现在它接受一个列表或字典。我尝试将整数放入列表中,但没有成功。我不知道它想要什么字典。我已经尝试了我能想到的一切。似乎没有什么能阻止它检测到我的播放器。该文档根本没有帮助。提前致谢。

0 投票
2 回答
169 浏览

2d - What types of velocity-over-time curve models an object sliding to a halt on a level surface?

I'm writing a little game with a top-down view of some sliding objects, like curling or shuffleboard. (I happen to be using PyMunk for the physics, but since this question is about physics simulations in general, don't worry about language specifics.) Before I start tweaking all the values in my little sim to get behaviour that 'feels' right, I thought I'd better check to make sure that I'm at least modelling the right kind of velocity curve in the first place. However, finding a clear answer about this has turned out to be substantially harder than expected.

Model A

To simulate the way an object slides to a halt, pymunk allows the programmer to set space.damping, which works like this (quoting from the API reference): "A value of 0.9 means that each body will lose 10% of its velocity per second."

That makes sense, but it seems that that would produce a velocity-over-time curve with this basic shape (never mind the exact numbers):

In other words, acceleration decreases over time. (Some might prefer to say "deceleration" or "negetive acceleration" decreases, but in the purest physics sense any change in velocity is 'acceleration', and in the chart above the change in velocity becomes smaller over time.) Because such a curve will approach but never cross 0, a cutoff is employed under which a body's velocity is forced to 0. Pymunk provides a setting for the cutoff, too: space.idle_speed_threshold.

This seems straightforward enough but gave rather unsatisfying results when I tried it in my little simulation. So, I began to consider Model B, below.

Model B

Thinking about it intuitively, it seems like the acceleration would increase over time, making a curve like this:

If I imagine pushing a book across a level table it seems like it maintains most of its speed at first but then comes to a halt very quickly (possibly because the friction causes the rate of slowdown to increase? Although the 'why' of it isn't so important here). This is a little harder to implement in pymunk, if only because there isn't a built-in method for it, but it can be done. It's not that I don't trust the chipmunk/pymunk developers, but I'm not sure if they meant for damping to simulate what I'm trying to simulate.

So, my question is not how to implement either of those curves in code, but rather - which type of curve accurately models an object sliding to a halt on a level surface?

You might think "Why is this person asking a physics question on a programming website?", but after looking at physics websites for the past four hours and getting nowhere, my hope is that, since physics modelling is common enough in programming these days, someone in the SO community might have prior knowledge about this that they can readily share.

I'm aware of this discussion on SO: how to calculate a negative acceleration? in which both types of curves are suggested, but while the asker got his question answered (someone helped him implement a Model-B type curve), the community did not come to a consensus about which is more 'physically accurate'. (I also borrowed that asker's ASCII art for one of the charts - thanks.)

I'm also aware of this example of a carrom board simulation from the pymunk showcase: https://github.com/samiranrl/Carrom_rl This also uses the built-in damping (model A, above). It seems to work fine for their purposes. But it might be that we human observers wouldn't notice if model A wasn't right since the carrom pieces are not in motion for very long. Model A looked wrong when I tried it in my sim, but then, but I am trying for much longer, slower shots, so maybe it's more noticeable there.

Or, maybe what 'seems' right to me (Model B) isn't right after all. Any thoughts are appreciated. Thanks!

0 投票
1 回答
136 浏览

pymunk - 如何检查我是否正确安装了 pymunk

我在终端中输入了“python3 install pymunk”,似乎它已安装。但是我如何在终端中检查它是否正确安装?我试图在终端中输入“import pymunk”,但它说

当我在 sublime 中运行 pymunk 时,它说

0 投票
1 回答
257 浏览

python - 可以在没有屏幕的情况下运行 Pymunk 模拟(就像没有实际看到它一样)?

我的问题是,是否可以在不弹出屏幕的情况下运行 Pymunk 模拟?

我正在从事一个涉及 Pymunk 和 Pygame 的研究项目。目标是开发一种代理,该代理可以推断涉及 Pymunk 空间内的对象和代理的物理模拟的某些属性。

项目的一部分需要对许多不同的模拟进行比较,并且弹出一个屏幕以便我可以查看每个模拟的事实导致问题花费太多时间(因为我必须查看每个模拟才能从中收集数据)。

我想基本上在后台尽可能快地运行每个模拟,以收集物理数据。我不需要在某些点实际可视化模拟。

让我知道我是否已经足够清楚或者这是重复的。虽然,我在这里搜索了答案,但我没有找到答案。

0 投票
1 回答
126 浏览

python - Pymunk 中的每体阻尼是否与空间阻尼复合?

为一个项目做一些模拟。

我的问题是身体的阻尼值是否与 pymunk 空间的阻尼值(如果有的话)复合?

例如,如果我有一个 pymunk 空间 SPACE,SPACE.damping = 0.9,然后我有一个主体 BODY,我将其 BODY.update_velocity() 方法设置为阻尼值为 0.5,那么 BODY 的阻尼是否为 0.9 *0.5(或其他一些成分)还是 0.5?

让我知道我是否可以让我的问题更清楚,并提前感谢您。

0 投票
1 回答
285 浏览

python - 有没有办法在 Pymunk 中实现静态摩擦

我的问题很简单:有没有办法或解决方法在 pymunk 中同时实现静态和动态摩擦?

我理解这个问题很困难,但相信有人可能会解决 pymunk 中的问题。

谢谢!

0 投票
1 回答
392 浏览

python-3.x - Pymunk绘图工具不起作用

我正在努力pymunk在我的 Ubuntu 16.04 上进行设置。我正在使用 virtualenv,我安装了 Python 3.5.2、pymunk 5.3.0 和 cffi 1.11.0。

我首先尝试了一个非常简单的代码;基本上,我创建了一个空Space并调用step它,一切都很顺利。但是,当我尝试将其可视化并创建DrawOptions实例时,会出现奇怪的错误,我无法破译。另外,我尝试了matplotlib_utiland pygame_util,但都未能创建DrawOptions.

这是我使用的代码片段:

这是我得到的输出:

你认为是什么原因造成的?是我使用的python版本,还是cffi编译有问题?

0 投票
1 回答
304 浏览

python - 碰撞中从一个物体到另一个物体的能量转移(在 pymunk/花栗鼠中)

这个问题是关于 pymunk 的,但我知道那里有更多的 Chimpunk 用户。因此,如果您的答案涉及 C/Chipmunk 代码,那没关系。虽然我不知道如何编写 C 代码,但如果我阅读别人的代码,我通常可以弄清楚发生了什么。

设置

我正在模拟一个自上而下的滑动对象游戏(想想冰壶或沙狐球)。我已经为代码的相关部分做了一个最小的例子(在问题的结尾),但它的核心是:

  • 创建了两个相同的物理对象(按照冰壶术语,我称它们为“石头”)
  • 它们的位置具有相同的 x 值但不同的 y 值(一个在另一个上方的直线上)。
  • 使用 apply_impulse (目前,虽然尝试了其他方法),下面的石头直接“发射”到另一块石头上

我希望达到的目标

当石头碰撞时,下面的石头应该会突然停止(或者可能会反弹一点——我还没有为那个细节出汗),而它的全部或大部分能量都转移到上面的石头上,这将开始向上移动。

我得到的是

当石头碰撞时,下面的石头并没有停止,而是开始将上面的石头推上屏幕。就好像下部比上部有更多的质量,但它们是用相同的功能创建的,所以它们应该是相同的。

我已经上传了一个 .gif 到 imgur 来说明这一点,如果有帮助的话:http: //imgur.com/a/FF6Xq

它的帧速率低于实际运行脚本时的帧速率,但它仍然说明了正在发生的事情。

我试过的

通读 pygame 文档,以尝试识别所有可能相关的 body 和 shape 属性,我尝试以各种组合调整以下所有内容:

  • 身体质量
  • 形状摩擦
  • 形状弹性
  • “地面摩擦”(在自上而下的场景中模拟地面摩擦的枢轴约束的 max_force)
  • 发射下石头的“力量”(传递给 apply_impulse 的参数之一)
  • 使用 apply_force 而不是 apply_impulse

调整任何/所有这些都会使石头的行为发生明显和预期的变化,但没有一个可以改变石头在碰撞时推动另一块石头的根本问题。

我已经阅读了有关使用 pymunk.CollisionHandler() 的信息,但还没有尝试过使用它。从文档中,我感觉到这主要是为了给碰撞添加额外的效果,而不是为了修改碰撞时发生的基本物理特性。但我可能误解了,我愿意接受任何建议。

我看过几个 pymunk 演示。最值得注意的是,一个名为 newtons_cradle.py 的演示展示了我想要的行为。这是对其中一个有五个球连续悬挂的小工具的模拟;当用户将一端的一个球向后拉时,它会撞击该排的其余部分,并且能量会转移到另一侧的球上。newtons_crade.py 与我的代码只有两个主要区别:

  • 它是“侧视图”(因此,重力大于 0)
  • 而不是使用 apply_impulse 或 apply_force,仅使用重力将球推向其他球(受约束)。

遗憾的是,在我的自上而下设置中,使用重力不是一个选项。所以问题可能是我使用了 apply_impulse/apply_force,但我看不到任何修改这些使用方式的方法(我已经尝试过各种功率和质量组合,以及调整约束的设置)。

即使指出我正确的方向——即关于我可能阅读的其他内容的一些建议,我可能会尝试修改的其他内容——将不胜感激。我不能成为第一个在 pymunk/chipmunk 中尝试这个的人,但我找不到一个例子。至少不是在 pymunk 方面;如果我可以学习 C/Chipmunk 中有一个很好的例子,那也很有用。

谢谢大家的时间。

最小示例代码

无需研究代码即可理解问题,但我已将其发布在这里以防万一。尽管被剥离以显示代码的核心,但它是一个完整的脚本并且可以运行。它在 Python 3 中。

再次感谢大家的时间。

0 投票
2 回答
462 浏览

python - PyMunk 不创建窗口 - Python

我正在尝试学习 PyMunk 库,我使用了他们网站上的示例。这是一个代码:

当我运行它时,窗口没有出现,在 CMD 中它说:Loading chipmunk for Windows (64bit) [C:\Users\Theo\AppData\Local\Programs\Python\Python35\lib\site-packages\pymunk\chipmunk.dll]并且不加载任何东西。我等了一个小时。问题是什么?

0 投票
2 回答
2737 浏览

python - 使用 PyGame 显示 PyMunk - Python

我正在尝试学习 PyMunk,我使用了网站上的基本示例:

但它不创建一个窗口,不显示任何东西。如何使用 PyGame 创建图形窗口?