fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. # define M_PI 3.14159265358979323846
  5.  
  6. static inline float DEGREES_TO_RADIANS(float degrees)
  7. {
  8. return degrees * ((float) M_PI / 180.0f);
  9. }
  10.  
  11.  
  12. int main(void) {
  13. // your code goes here
  14. static float roundDegrees = 1.0f;
  15. static float linesPerSecond = 320.f;
  16. static float trianglePercentIncreasing = 90.f;
  17. static float fovDeg = 20.f;
  18. static float scanFrequency = 5.f;
  19. static float roundFactor = 9.8f;
  20. static float angleOffset = 0;
  21. const float minDeg =
  22. (-fovDeg / 2) + angleOffset;
  23. const float ScanMinPosition = DEGREES_TO_RADIANS(minDeg);
  24. const float maxDeg =
  25. (fovDeg / 2) + angleOffset;
  26. const float ScanMaxPosition = DEGREES_TO_RADIANS(maxDeg);
  27. const float rpos = DEGREES_TO_RADIANS(roundDegrees);
  28. const float scanPeriodInLines =
  29. linesPerSecond / scanFrequency;
  30.  
  31. /* Sanitize the parameters */
  32. const float period1 =
  33. (scanPeriodInLines * trianglePercentIncreasing) / 100;
  34. const float periodRseg1 =
  35. ((period1 * roundDegrees) / fovDeg) *
  36. roundFactor;
  37. const float periodStraight1 = period1 - (2 * periodRseg1);
  38.  
  39. const float period2 = scanPeriodInLines - period1;
  40. const float periodRseg2 =
  41. ((period2 * roundDegrees) / fovDeg) *
  42. roundFactor;
  43. const float periodStraight2 = period2 - (2 * periodRseg2);
  44.  
  45. if (rpos >= ((ScanMaxPosition - ScanMinPosition) / 2) ||
  46. periodStraight1 <=
  47. 0.16 || /* Leave some room for a slope on the straight portion */
  48. periodStraight2 <= 0.16)
  49. {
  50. printf("hit, periodStraight1=%f, periodStraight2=%f", periodStraight1, periodStraight2);
  51. }
  52. else
  53. {
  54. printf("periodStraight1=%f, periodStraight2=%f", periodStraight1, periodStraight2);
  55. }
  56. return 0;
  57. }
  58.  
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
hit, periodStraight1=1.152000, periodStraight2=0.128000