I apologize ahead of time if this question was already answered - I may have stumbled across it but not realized it since I'm not entirely certain what all the symbols mean even after looking them up.
I'm attempting to iterate through a two-dimensional array (grid for a game) and check if a given coordinate is within the bounds of a polygon, in this case an octagon.
I'm just can't seem to figure out what the distance should be to check for.
As an example, for a circle I can just use the Pythagorean theorem to see if "c" is less than or equal to the given radius. If it is, then I change the value in my grid for that coordinate.
If it matters, this uses quadrant I in the Cartesian coordinates grid.
Please let me know if this is too vague and I will clarify - thanks in advance to anyone who even bothers to look at this!
Let $S$ be a regular octagon in the $xy$-plane.
Given a point $Q$ in the $xy$-plane, the goal is to decide whether $Q$ is inside $S$, on $S$, or outside $S$.
Let $r$ be the distance from the center of the octagon to one of the vertices.
Preliminary transformations:
Let the new coordinates of $Q$ be $(a,b)$.
Let $L:\mathbb{R}^2 \to \mathbb{R}$ be defined by $$L(x,y) = x + y(\sqrt{2}-1) - r$$ and let $v = L(a',b')$, where \begin{align*} a' &= \max(|a|,|b|)\\[4pt] b' &= \min(|a|,|b|)\\[4pt] \end{align*} The sign of $v$ is decisive:
Done!