fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. #define PI 3.14159265
  5.  
  6.  
  7. float theta_vals (float q1, float q2, float A_1p[3], float B_1[3]){
  8.  
  9.  
  10.  
  11. //float q1 = 0.001; //pitch angle
  12. //float q2 = 0; //roll angle
  13.  
  14. //Constants
  15. float r = 1.43;
  16. float s = 11.1;
  17.  
  18. float A_1[] = {A_1p[0]*cos(q2) + A_1p[1]*sin(q1)*sin(q2) + A_1p[2]*cos(q1)*sin(q2), A_1p[1]*cos(q1) + -A_1p[2]*sin(q1), -A_1p[0]*sin(q2) + A_1p[1]*sin(q1)*cos(q2) + A_1p[2]*cos(q1)*cos(q2)};
  19.  
  20. //printf("A1 = %lf , %lf , %f \n", A_1[0], A_1[1], A_1[2] );
  21.  
  22. float L_1 = 0;
  23.  
  24. //int x = sizeof(B_1);
  25. //printf("sizeofB_1 = %d \n", x);
  26.  
  27. for (int i = 0; i < 3; i++) {
  28. L_1 += pow((A_1[i] - B_1[i]), 2);
  29. }
  30.  
  31. L_1 = sqrt(L_1);
  32.  
  33. //printf("L1 = %lf \n", L_1);
  34. //printf("L2 = %lf \n", L_2);
  35.  
  36. if (L_1 > 12.53) {
  37. L_1 = 12.53;
  38. } else if (L_1 < 9.67) {
  39. L_1 = 9.67;
  40. }
  41.  
  42. //printf("L1 = %lf \n", L_1);
  43. //printf("L2 = %lf \n", L_2);
  44.  
  45. int sizeOfTheta = 5000;
  46. float theta[sizeOfTheta]; //values range from 0 to pi
  47. float delta = PI / (sizeOfTheta - 1);
  48. for (int i = 0; i < sizeOfTheta; i++) {
  49. theta[i] = i*delta;
  50. }
  51.  
  52. float L[sizeOfTheta];
  53. for (int i = 0; i < sizeOfTheta; i++) {
  54. L[i] = r*cos(theta[i]) + sqrt(pow(s,2) - (pow(r,2)*pow(sin(theta[i]),2)));
  55. }
  56.  
  57.  
  58. //find where L and L_1 are equal
  59. int found = 0;
  60. int index1 = 0;
  61. int index2 = 0;
  62. float tempL = -1;
  63. float tempL1 = -1;
  64. float tempL2 = -1;
  65. while (found == 0) {
  66. tempL = round(L[index1] * 1000) / 1000;
  67. tempL1 = round(L_1 * 1000) / 1000;
  68. if ((tempL == tempL1) && (tempL > 0) && (tempL1 > 0)) {
  69. found = 1;
  70. } else {
  71. index1++;
  72. }
  73. }
  74.  
  75. float theta1 = theta[index1];
  76.  
  77. float thetas = theta1;
  78.  
  79.  
  80. //printf("Theta1 = %lf \n", thetas);
  81.  
  82. return thetas;
  83. }
  84.  
  85. int main() {
  86.  
  87. float A_1p[] = {11, 11, 0};
  88. float A_2p[] = {-11, 11, 0};
  89.  
  90. float B_1[] = {11, 11, -11.1};
  91. float B_2[] = {-11, 11, -11.1};
  92.  
  93. float q1 = 0, q2 = 0;
  94. float theta1, theta2;
  95. theta1 = theta_vals (q1, q2, A_1p, B_2);
  96. theta2 = theta_vals (q1, q2, A_2p, B_1);
  97.  
  98. theta1 = (theta1/PI) * 180;
  99. theta2 = (theta2/PI) * 180;
  100.  
  101.  
  102. printf("Theta1 = %lf \n", theta1);
  103. printf("Theta2 = %lf \n", theta2);
  104.  
  105. }
  106.  
Success #stdin #stdout 0s 4364KB
stdin
Standard input is empty
stdout
Theta1 = 0.000000 
Theta2 = 0.000000