2
\$\begingroup\$

I am trying to implement a FOV for my light casting algorithm. In the diagram below each white line represents a ray cast from a std::vector<float> of normalized radians. How can I only include angles which lie between the two green lines? (The FOV min and max).

enter image description here

\$\endgroup\$
7
  • \$\begingroup\$ Do you mean how do you filter the vector of ints to be between the two radians values of the fov? \$\endgroup\$
    – Steven
    Oct 18, 2015 at 18:50
  • \$\begingroup\$ Yes. Or filter before they are even placed into the vector. \$\endgroup\$
    – fatnic
    Oct 18, 2015 at 18:53
  • \$\begingroup\$ What units are the radians in? They are not floats so what are they? What do you mean normalized radians if they are ints \$\endgroup\$
    – Steven
    Oct 18, 2015 at 18:55
  • \$\begingroup\$ Sorry. Yes, they are floats. I'll edit my question now. \$\endgroup\$
    – fatnic
    Oct 18, 2015 at 18:55
  • \$\begingroup\$ Is there a way of making the first green line 0 then seeing if the angle of the other lines aren't greater than the second green line? \$\endgroup\$
    – fatnic
    Oct 18, 2015 at 18:56

1 Answer 1

1
\$\begingroup\$

I found this which works pretty well.

bool angleBetween(float _angle, float _min, float _max)
{
    float angle = std::fmod(360 + (rad2deg(_angle)), 360);
    float min = std::fmod(3600000 + rad2deg(_min), 360);
    float max = std::fmod(3600000 + rad2deg(_max), 360);

    if(min < max)
        return (min <= angle && angle <= max);

    return (min <= angle || angle <= max);
}
\$\endgroup\$
1
  • 1
    \$\begingroup\$ It seems like it would be simpler to compare the radian values instead of converting to degrees first. \$\endgroup\$
    – shade4159
    Oct 19, 2015 at 4:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .