c++dev-c++bgi

Elastic particle bouncing on an incline


I'm trying to simulate an elastic particle bouncing on a 600x600 window (graphics.h)

I already have a working condition when it bounces off the floor or the walls, but I cant make it bounce properly on an incline.

Here's the condition for the incline:

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))));
}

Additional note: the x and y are calculated into cartesian coordinates and converted back to pixel value after calculation (Putpixel) using these functions:

//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;
}

Here is the output so far


Solution

  • I think the Vx is assigned a new value. Then it is used in the Vy assignment in the next line. The old value of Vx should be used. So you need vxtemp = vx; and use vxtemp in the calculations.