Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //initial conditions
- x = 0;
- y = 100;
- Vx = 15.0;
- Vy = 0.0;
- double dt = 0.0001; //initial time step and increment
- for(double t = 0; t < 50; t += dt)
- {
- Vy = Vy + grav*dt;
- //Conditions when the particle hits a wall or the floor and retaining only 97% of its speed
- if (y<0.0)
- {
- Vy = -Vy + grav*dt;
- }
- if(x >100.0 || x < 0.0)
- {
- Vx = -Vx;
- }
- //condition when the particle hits the semicircle
- //semicircle equation: y = sqrt(30^2 - (x-50)^2)
- if(y < sqrt((30*30)-((x-50)*(x-50))) )
- {
- Vxnew = ((Vx)*(cos(2.0*theta)) + (Vy*(sin(2.0*theta))));
- Vy = (Vy*(cos(2.0*theta)) - ((Vx)*(sin(2.0*theta))));
- Vx = Vxnew;
- }
- x = x + Vx*dt;
- y = y + Vy*dt;
- putpixel(conx(x), cony(y), 15);
- }
- //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;
- }
Add Comment
Please, Sign In to add comment