首页 > 解决方案 > 在斜坡上弹跳的弹性粒子

问题描述

我正在尝试模拟在 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;
}

这是到目前为止的输出

标签: c++dev-c++

解决方案


我认为 Vx 被分配了一个新值。然后在下一行的 Vy 赋值中使用它。应使用旧的 Vx 值。所以你需要 vxtemp = vx; 并在计算中使用 vxtemp。


推荐阅读