c++ - 在斜坡上弹跳的弹性粒子
问题描述
我正在尝试模拟在 600x600 窗口(graphics.h)上弹跳的弹性粒子
当它从地板或墙壁反弹时,我已经有一个工作条件,但我不能让它在斜坡上正确反弹。
这是倾斜的条件:
if(y <= ((3.0/7.0)*x - 90.0/7.0)) //y = 3x/7 - 90/7 is the equation of the line
{
//by rotating the reference coordinates (the wedge becomes the new x axis)
//formula:
//x' = xcos(theta) - ysin(theta)
//y' = xsin(theta) + ycos(theta)
Vx = (Vx*(cos(theta)) - (Vy*(sin(theta))));
Vy = -(Vx*(sin(theta)) + (Vy*(cos(theta))));
}
附加说明:x 和 y 被计算为笛卡尔坐标,并使用以下函数在计算后转换回像素值 (Putpixel):
//convert to pixel value (scale of 6)
double conx(double x)
{
return x * (600/100) + 50;
}
double cony(double y)
{
return -y * (600/100) + 650;
}
解决方案
我认为 Vx 被分配了一个新值。然后在下一行的 Vy 赋值中使用它。应使用旧的 Vx 值。所以你需要 vxtemp = vx; 并在计算中使用 vxtemp。
推荐阅读
- python - 为什么 pandas 的索引这么慢?如何让它更快?
- java - Java:如何获取音频输入的当前频率?
- java - 如何从文本字段中获取值并在另一个类中使用它们?
- python - 尝试使用 tkinter 编写 Python 工具,但出现了窗口?
- html - 这是允许的吗?在 html 中分配 2 个类
- javascript - 如何通过 Fable 将 F# 模块的公共函数公开给 Javascript?
- python - 如何将 3 个 files.py 转换为 1 个 file.exe?
- python - 除了 wordcloud 中的默认停用词之外,如何添加额外的停用词?
- android - SQLite 的替代品
- javascript - 如何为从 html 文件调用的函数返回的字符串添加样式