Determining if a circle is in your field of view in 2D "without" trig functions.

http://pastebin.com/yeESVkhZ

Given your direction vector is normalized, and you store FOV as cos/sin, you can pretty quickly determine if a circle is within your view (either partially or entirely).

This works by creating vectors that extend from the origin to the sides of their view port - rotating them by the view’s direction. Using these vectors it can rotate the vector between the circle’s center and the object down to the x-axis. Once you do this, the y-component of that vector is the signed distance of the circle to that extent.

This also works where FOV >= 90 (and by FOV, I’m talking half of your actual field of view, in radians).

This is some code from a library I’m working on called Steerio.

If someone can figure out a more efficient method, I challenge thee!

Peace!

Why is this function better then:

circle.x - circle.width/2 <= rect.x + rect.width && circle.x + circle.width >= rect.x (same with y)

By “your” FOV, I mean something in your game like a unit.

Imagine that on the head of a unit of yours, and it want’s to know everything it can see based on it’s direction, location, and FOV.

Oh awesome i was looking for that a while ago!