Direction test by... adding sine and cosine?

Mr. Bland

Junior Member
Joined
Dec 27, 2019
Messages
195
While picking apart the machine code of an old video game, I came across a routine that was doing something I haven't personally seen before regarding trigonometry. I'm sure it's very common knowledge and that I just happen to not know about it... But I can't figure out why it works and am hopeful someone could spell it out for me.

It goes something like this: given a reference angle [imath]\theta[/imath] and a point of interest [imath](x,y)[/imath], determine whether the point is "in front of" or "behind" the reference angle... or in other words, test if the angle to the point is more than 90 degrees off from the reference angle.

Mechanically, the test is very simple:

[imath]x cos\theta + y sin\theta < 0[/imath]​

If true, the point [imath](x,y)[/imath] is situated "behind" with respect to the reference angle. This Desmos setup demonstrates the technique.

Why does this work? I can see that it's related to projecting a point onto circles with radii given by the coordinates of the point of interest, but how that unto itself is useful or why adding them gives a meaningful result eludes me. Does this have a name, like, Someguy's Formula or something?
 
You know, I've been bouncing this around in my head for the past three days, but now that I've gone and opened my mouth I think I know what's going on. The point [imath](cos\theta, sin\theta)[/imath] produces a unit-length vector, while [imath](x,y)[/imath] is a vector with arbitrary magnitude. The multiply-and-add operation is dot product, projecting one onto the other. If the resulting scalar is negative, it's because they're—speaking in the broadest possible sense—pointing in opposite directions.
 
Top