Advertisement
Guest User

Untitled

a guest
Mar 15th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. // PhysicsSim Shuttle Orientation.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <cmath>
  6. #include <iostream>
  7. #include <math.h>
  8.  
  9. using namespace std;
  10.  
  11. int main()
  12. {
  13. double rotinput;
  14. cout << "Nose rotation: ";
  15. cin >> rotinput;
  16.  
  17. double const pi = 3.14159265359;
  18. double rotangle = rotinput *pi/180; // in radians. For zero rotation, craft is pointing with nose in +y direction.
  19.  
  20.  
  21. double p1[3] = { 2.5 * (cos(pi / 2 + rotangle)), 2.5 * (sin(pi / 2 + rotangle)), 3 }; // X, Y, and mass
  22.  
  23. double p2[3] = { 1.552417 * (cos(1.310194 + rotangle)), 1.552417 * (sin(1.310194 + rotangle)), 5 };
  24. // double p2[3] = { 0.4, 1.5, 5 };
  25.  
  26. double p3[3] = { 1.552417 * (cos(pi-1.310194 + rotangle)), 1.552417 * (sin(pi-1.310194 + rotangle)), 5 };
  27.  
  28. double p4[3] = { 1.581139*(cos(-0.321751 + rotangle)), 1.581139*(sin(-0.321751 + rotangle)), 6 };
  29. // double p4[3] = { 1.5, -0.5, 6 };
  30.  
  31. double p5[3] = { 1.581139*(cos(pi+0.321751 + rotangle)), 1.581139*(sin(pi+0.321751 + rotangle)), 6 };
  32.  
  33. double p6[3] = { 1.5 * (cos(-pi / 2 + rotangle)), 1.5 * (sin(-pi / 2 + rotangle)), 11 };
  34.  
  35. double points[6][3] = { { p1[0], p1[1], p1[2] }, { p2[0], p2[1], p2[2] }, { p3[0], p3[1], p3[2] }, { p4[0], p4[1], p4[2] }, { p5[0], p5[1], p5[2] }, { p6[0], p6[1], p6[2] } };
  36. // single massive 2-dim array allows for these values to be cycled through in the for loops for force and torque
  37.  
  38. double y_zero = 6600000; // "zero point" for y-coordinate. Distance to Earth's center, meters.
  39.  
  40. double m_Earth = (5.972 * pow(10,24));
  41. double G = (6.67 * pow(10, -11));
  42.  
  43. double localg = -G*m_Earth / (y_zero*y_zero);
  44.  
  45. // double velx = sqrt(abs(localg)*y_zero); // velocity required for a circular orbit at this point.
  46. /*
  47. cout << p1[0] << " " << p1[1] << " " << p1[2] << endl;
  48. cout << p2[0] << " " << p2[1] << " " << p2[2] << endl;
  49. cout << p3[0] << " " << p3[1] << " " << p3[2] << endl;
  50. cout << p4[0] << " " << p4[1] << " " << p4[2] << endl;
  51. cout << p5[0] << " " << p5[1] << " " << p5[2] << endl;
  52. cout << p6[0] << " " << p6[1] << " " << p6[2] << endl;
  53. */
  54. cout << endl;
  55.  
  56. double torquesum = 0;
  57.  
  58. for (int i = 0; i <= 5; i++)
  59. {
  60. cout << i << endl;
  61. cout << points[i][0] << " " << points[i][1] << " " << points[i][2] << endl;
  62.  
  63. double p_y = points[i][1] + y_zero;
  64. double p_dir = atan(points[i][1] / points[i][0]);
  65. double p_dist = sqrt(points[i][0] * points[i][0] + points[i][1] * points[i][1]);
  66.  
  67. double g_dir = atan(p_y / points[i][0]);
  68. double dist = sqrt(p_y * p_y + points[i][0] * points[i][0]);
  69. double g_mag = G*m_Earth / (dist*dist);
  70.  
  71. double f_mag = g_mag*points[i][2];
  72.  
  73. double torque = p_dist*f_mag*sin(p_dir - g_dir);
  74. torquesum = torquesum + torque;
  75.  
  76. }
  77.  
  78. cout << endl << endl << "Torque Sum: " << torquesum*1000 << " * 10^-3" << endl;
  79.  
  80. system("pause");
  81. return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement