http://www.perlmonks.org?node_id=707467


in reply to Some simple 2d game-related maths questions

It is funny to reinvent the wheel sometimes :>)

I suppose that position of the line is constant and the radius of moving circle is constant too. In that case you can define that line by formula

[1] aX + bY + c = 0
(Note: vector (a,b) is perpendicular to the line.)

If you consider left side of [1] as function,

[2] f(X,Y) = aX + bY + c
you can easily see that f(X,Y) = 0 only if point X,Y is on the line, and, f(X,Y) > 0 for each points of one half-plane defined by the line, and, f(X,Y) < 0 for each point of the other half-plane.

Consequently, it is directly usable for testing if two points are on the same half-plane. But you want to test something different a bit. Let you construct two helper lines parallel to the [1] line, both in the distance equal to circle radius, g(X,Y) in positive half-plane and h(X,Y) in negative half-plane of the [1], with the same "orientation" of positivity/negativity. You can construct these functions just once when program starts, regardless on the position of the circle.

Let (X1,Y1) is position of the circle center before movement and (X2, Y2) is position after movement. Exploring signs of f(X1,Y1), f(X2,Y2), g(X1,Y1), g(X2,Y2), h(X1,Y1), h(X2,Y2) will give you, what do you need.

I think it is more suitable than some non-linear expressions.