#include <stdio.h>
#include <math.h>
# define M_PI 3.14159265358979323846
static inline float DEGREES_TO_RADIANS(float degrees)
{
return degrees * ((float) M_PI / 180.0f);
}
int main(void) {
// your code goes here
static float roundDegrees = 1.0f;
static float linesPerSecond = 320.f;
static float trianglePercentIncreasing = 90.f;
static float fovDeg = 20.f;
static float scanFrequency = 5.f;
static float roundFactor = 9.8f;
static float angleOffset = 0;
const float minDeg =
(-fovDeg / 2) + angleOffset;
const float ScanMinPosition = DEGREES_TO_RADIANS(minDeg);
const float maxDeg =
(fovDeg / 2) + angleOffset;
const float ScanMaxPosition = DEGREES_TO_RADIANS(maxDeg);
const float rpos = DEGREES_TO_RADIANS(roundDegrees);
const float scanPeriodInLines =
linesPerSecond / scanFrequency;
/* Sanitize the parameters */
const float period1 =
(scanPeriodInLines * trianglePercentIncreasing) / 100;
const float periodRseg1 =
((period1 * roundDegrees) / fovDeg) *
roundFactor;
const float periodStraight1 = period1 - (2 * periodRseg1);
const float period2 = scanPeriodInLines - period1;
const float periodRseg2 =
((period2 * roundDegrees) / fovDeg) *
roundFactor;
const float periodStraight2 = period2 - (2 * periodRseg2);
if (rpos >= ((ScanMaxPosition - ScanMinPosition) / 2) ||
periodStraight1 <=
0.16 || /* Leave some room for a slope on the straight portion */
periodStraight2 <= 0.16)
{
printf("hit, periodStraight1=%f, periodStraight2=%f", periodStraight1
, periodStraight2
); }
else
{
printf("periodStraight1=%f, periodStraight2=%f", periodStraight1
, periodStraight2
); }
return 0;
}