Java – calculate which side a line is on

I need to figure out how to calculate which side of a line I am looking for a very fast and simple collision algorithm because I only need to know which side of the object defines the collision state

Like:

if(x > line.x)
    return EnumSide.LEFT;

But the line needs a diagonal Any ideas?

Solution

Given the directed line from point P0 (x0, Y0) to P1 (x1, Y1), you can use the following conditions to determine whether point P2 (X2, Y2) is on the left, right, or the same row:

value =(x1 – x0)(y2 – y0) – (x2 – x0)(y1 – y0)

If the value > 0, P2 is to the left of the row If value = 0, P2 is on the same line If the value < 0, P2 is on the right side of the row This is a number that explains everything:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>