Guest User

Untitled

a guest
Jul 17th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. //initial conditions
  2. x = 0;
  3. y = 100;
  4. Vx = 15.0;
  5. Vy = 0.0;
  6. double dt = 0.0001; //initial time step and increment
  7.  
  8. for(double t = 0; t < 50; t += dt)
  9. {
  10. Vy = Vy + grav*dt;
  11.  
  12. //Conditions when the particle hits a wall or the floor and retaining only 97% of its speed
  13. if (y<0.0)
  14. {
  15. Vy = -Vy + grav*dt;
  16. }
  17.  
  18. if(x >100.0 || x < 0.0)
  19. {
  20. Vx = -Vx;
  21. }
  22.  
  23. //condition when the particle hits the semicircle
  24. //semicircle equation: y = sqrt(30^2 - (x-50)^2)
  25. if(y < sqrt((30*30)-((x-50)*(x-50))) )
  26. {
  27. Vxnew = ((Vx)*(cos(2.0*theta)) + (Vy*(sin(2.0*theta))));
  28. Vy = (Vy*(cos(2.0*theta)) - ((Vx)*(sin(2.0*theta))));
  29.  
  30. Vx = Vxnew;
  31. }
  32.  
  33. x = x + Vx*dt;
  34. y = y + Vy*dt;
  35.  
  36. putpixel(conx(x), cony(y), 15);
  37. }
  38.  
  39. //convert to pixel value (scale of 6)
  40. double conx(double x)
  41. {
  42. return x * (600/100) + 50;
  43. }
  44.  
  45. double cony(double y)
  46. {
  47. return -y * (600/100) + 650;
  48. }
Add Comment
Please, Sign In to add comment