How to ensure that a point A(x,y) doesn't cross a imaginary line between two other points.

75 Views Asked by At

I'm programming an web app and I need some help with a problem, as my mathematical skills are not great. I have 4 points in an XOY system with the origin in the top left. I need to make sure that any point does not cross the imaginary line between two other that are diagonally-opposed. This example shows better what I mean.

enter image description here

So A and C should not go across the imaginary line BD and B and D should not go across the imaginary line AC.

Few notes

  • The points can be moved around in any possible way.
  • I'm working only with positive coordinates.

What I know: x and y coordinates for all the points.

What I don't know: any of the angles.

What I need to find out: The maximum x and y coordinates that a point can reach before it passes to the other side of the line. Something like: Max(Ax) = Bx - ...; Max(Ay) = By - .... Thanks.

2

There are 2 best solutions below

0
On

The dot product of the vector $\vec {DA}$ and the vector, orthogonal to the vector $\vec {DB}$, should be non-negative.

In coordinates:

$$(x_A - x_D) \cdot (y_B - y_D) - (y_A - y_D) \cdot (x_B - x_D) \ge 0$$

where: $$A = (x_A, y_A)$$ $$B = (x_B, y_B)$$ $$D = (x_D, y_D)$$

0
On

The line $ax+by+c=0$, separates the plane into two half-planes. In one half-plane it will always be true that $ax+by+c>0$ and in the other it will always be true that $ax+by+c<0$. The distance of the point $(x_0, y_0)$ from the line $ax+by+c=0$ is $\dfrac{|ax+by+c|}{\sqrt{a^2+b^2}}$.

If $(0,0)$ is going to be in the desired half-plane, then you could choose $a,b,$ and $c$ such that $c>0$. Then $(x_0, y_0)$ will be in the correct half-plane if and only if $ax_0+by_0+c > 0$.

Given two points, $(x_1,y_1)$ and $(x_2,y_2)$, you can use

$$(a,b,c) = \pm(y_2-y_1, x_1-x_2, x_2y_1 - x_1y_2)$$

where the plus or minus is chosen to make the sign of $ax+by+c$ positive (if you so desire).