Guest User

Untitled

a guest
Aug 19th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. #define USE_CONSOLE
  2. #define _USE_MATH_DEFINES
  3. #include<iostream>
  4. #include<cmath>
  5. #include<allegro.h>
  6. #define XRES 640
  7. #define YRES 640
  8.  
  9. using namespace std;
  10.  
  11. const int k=5000;
  12. double const G=6.67e-8;
  13. double const m=10000000000000;
  14. double const M=10000000000000;
  15. double const Q=10000000000000;
  16. double const dt=0.07;
  17. int konwersjaX(double x, double xmin, double xmax, int W)
  18. {
  19. return W*(x-xmin)/(xmax-xmin);
  20. }
  21. int konwersjaY(double y, double ymin, double ymax, int H)
  22. {
  23. return H-H*(y-ymin)/(ymax-ymin);
  24. }
  25.  
  26. int main()
  27. {
  28. double vx, vy, ua, ub, r1, r2, r3, wc, wd;
  29. double alfa=180, beta=0, gamma=180; //M / m
  30. double v=10, u=37, w=40;
  31. allegro_init();
  32. install_keyboard();
  33. set_color_depth(desktop_color_depth());
  34. set_gfx_mode( GFX_AUTODETECT_WINDOWED, XRES, YRES, 0, 0);
  35.  
  36. double x=0, y=0, a=0, b=400, c=0, d=-400; // M / m / Q
  37. alfa=alfa*M_PI/180;
  38. beta=beta*M_PI/180;
  39. gamma=gamma*M_PI/180;
  40. vx=v*cos(alfa);
  41. vy=v*sin(alfa);
  42. ua=u*cos(beta);
  43. ub=u*sin(beta);
  44. wc=w*cos(gamma);
  45. wd=w*sin(gamma);
  46.  
  47. for(int i=0; i<500000; i++)
  48. {
  49. r1=sqrt(pow((x-a), 2)+pow((y-b),2));
  50. r2=sqrt(pow((x-c), 2)+pow((y-d),2));
  51. r3=sqrt(pow((c-a), 2)+pow((d-b),2));
  52.  
  53. vx=vx+(a-x)*dt*G*m/pow(r1, 3)+(c-x)*dt*G*Q/pow(r2, 3); // ciało o masie M
  54. vy=vy+(b-y)*dt*G*m/pow(r1, 3)+(d-y)*dt*G*Q/pow(r2, 3);
  55.  
  56. ua=ua-(a-x)*dt*G*M/pow(r1, 3)+(c-a)*dt*G*Q/pow(r3, 3); //ciało o masie m
  57. ub=ub-(b-y)*dt*G*M/pow(r1, 3)+(d-b)*dt*G*Q/pow(r3, 3);
  58.  
  59. wc=wc-(c-x)*dt*G*M/pow(r2, 3)-(c-a)*dt*G*m/pow(r3, 3); // ciało o masie Q
  60. wd=wd-(d-y)*dt*G*M/pow(r2, 3)-(d-b)*dt*G*m/pow(r3, 3);
  61.  
  62. x=x+vx*dt;
  63. y=y+vy*dt;
  64.  
  65. a=a+ua*dt;
  66. b=b+ub*dt;
  67.  
  68. c=c+wc*dt;
  69. d=d+wd*dt;
  70.  
  71. putpixel(screen, konwersjaX(x, -k, k, XRES), konwersjaY(y, -k, k, YRES), makecol(250, 0, 0));
  72. putpixel(screen, konwersjaX(a, -k, k, XRES), konwersjaY(b, -k, k, YRES), makecol(0, 250, 0));
  73. putpixel(screen, konwersjaX(c, -k, k, XRES), konwersjaY(d, -k, k, YRES), makecol(0, 0, 250));
  74. }
  75.  
  76.  
  77. acquire_screen();
  78. release_screen();
  79. readkey();
  80. return 0;
  81. }
  82. END_OF_MAIN();
Add Comment
Please, Sign In to add comment