Guest User

Untitled

a guest
Apr 21st, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. int data1[2], data2[2], DBTM = 2, ODBTM = 2;
  2. float pos1x, pos1y, pos2x, pos2y, dsq;
  3. double hvx = 0, hvy = 0, direction = 2*M_PI; //direction is the angle of the craft's orientation compared to the x axis, in radians! (going anticlockwise from the east) eg, 2pi = forward, pi/2 = facing to the left, pi = facing backwards, 3pi/2 = facing right, 0 = 2pi. direction = direction +- 2pi. in math.h pi is defined as M_PI. pi/2 = M_PI_2
  4. data1[1]=0;
  5. data1[2]=0;
  6. data2[1]=-1;
  7. data2[2]=1;
  8. pos1x = data1[1];
  9. pos1y = data1[2];
  10. while (((pow(DBTM+sqrt(data2[1]*data2[1]+data2[2]*data2[2]),2)-dsq)*(dsq-pow(DBTM-sqrt(data2[1]*data2[1]+data2[2]*data2[2]),2))>0) && (DBTM >= 0))
  11. {
  12. dsq = pow(DBTM-data1[1],2) + (data1[2]*data1[2]);
  13. DBTM--;
  14. }
  15. if (DBTM < 1) {DBTM = ODBTM;}
  16. while (((pow(DBTM+sqrt(data2[1]*data2[1]+data2[2]*data2[2]),2)-dsq)*(dsq-pow(DBTM-sqrt(data2[1]*data2[1]+data2[2]*data2[2]),2))>0) && (DBTM < (ODBTM * 2.0)))
  17. {
  18. dsq = pow(DBTM-data1[1],2) + (data1[2]*data1[2]);
  19. DBTM++;
  20. }
  21. if (DBTM<ODBTM*2.0)
  22. {
  23. dsq = pow(DBTM-data1[1],2) + (data1[2]*data1[2]);
  24. pos2x = DBTM;
  25. pos2y = 0;
  26. if (data2[2]<=0)
  27. {
  28. pos2y = (0.5 * (0 + data1[2])) + (0.5 * (0 - data1[2]) * (pow(DBTM,2) - (data2[1]*data2[1]+data2[2]*data2[2])) / dsq) - (2.0 * (DBTM-data1[1])*(0.25*sqrt(((pow(DBTM+sqrt(data2[1]*data2[1]+data2[2]*data2[2]),2)-dsq)*(dsq-pow(DBTM-sqrt(data2[1]*data2[1]+data2[2]*data2[2]),2)))))/dsq);
  29. }
  30. else if (data2[2]>0)
  31. {
  32. pos2y = (0.5 * (0 + data1[2])) + (0.5 * (0 - data1[2]) * (pow(DBTM,2) - (data2[1]*data2[1]+data2[2]*data2[2])) / dsq) + (2.0 * (DBTM-data1[1])*(0.25*sqrt(((pow(DBTM+sqrt(data2[1]*data2[1]+data2[2]*data2[2]),2)-dsq)*(dsq-pow(DBTM-sqrt(data2[1]*data2[1]+data2[2]*data2[2]),2)))))/dsq);
  33. }
  34. if (data2[1]<=0)
  35. {
  36. pos2x = (0.5 * (DBTM + data1[1])) + (0.5 * (DBTM - data1[1]) * (pow(DBTM,2) - (data2[1]*data2[1]+data2[2]*data2[2])) / dsq) - (2.0 * (0-data1[2])*(0.25*sqrt(((pow(DBTM+sqrt(data2[1]*data2[1]+data2[2]*data2[2]),2)-dsq)*(dsq-pow(DBTM-sqrt(data2[1]*data2[1]+data2[2]*data2[2]),2)))))/dsq);
  37. }
  38. else if (data2[1]>0)
  39. {
  40. pos2x = (0.5 * (DBTM + data1[1])) + (0.5 * (DBTM - data1[1]) * (pow(DBTM,2) - (data2[1]*data2[1]+data2[2]*data2[2])) / dsq) + (2.0 * (0-data1[2])*(0.25*sqrt(((pow(DBTM+sqrt(data2[1]*data2[1]+data2[2]*data2[2]),2)-dsq)*(dsq-pow(DBTM-sqrt(data2[1]*data2[1]+data2[2]*data2[2]),2)))))/dsq);
  41. }
  42. } else {
  43. DBTM = ODBTM;
  44. pos2x = DBTM+data2[1];
  45. pos2y = data2[2];
  46. }
  47.  
  48. if ((pos2x-pos1x > pow (2, -24)) || (pos2y-pos2x > pow (2, -24)) || (pos2y-pos2x < -pow (2, -24)) || (pos2y-pos2x < -pow (2, -24))) //pow(2, -24) = machine epsilon of "float"
  49. {
  50. direction += atan2(pos2y-pos1y, pos2x-pos1x);
  51. if (direction <= pow (2, -24)) {direction+=2*M_PI;}
  52. if (direction > 2*M_PI) {direction-=2*M_PI;}
  53. }
  54.  
  55. printf("pos1x: %.1f\npos1y: %.1f\npos2x: %.1f\npos2y: %.1f\ndirection: %.5f\n",pos1x,pos1y,pos2x,pos2y,direction);
Add Comment
Please, Sign In to add comment