
I have two polygons that may be moving or rotating. They are each made up of an arbitrary number of line segments with two endpoints each. I know the formula for shortest distance between a point and line and how to find that intersection point of the line and the perpendicular line through the point then use the distance formula (in this case distance squared) to determine if the point is on the line segment.
Relevant formulas
Distance between point and line :
L1: $Ax + By + C = 0$
L2: $Dx + Ey + F = 0$
$A = dy$
$B = -dx$
$C = dy*x_1 + dx*y_1$
$D = -dx$
$E = -dy$
$F = dx*x_3 - dy*y_3$
Where x1,y1 is any point on line 1 and x3,y3 is the point being tested against the line.
The intersection point is given by:
$I_x = \frac{CE-BF}{BD-AE}$
$I_y = \frac{AF-CD}{BD-AE}$
Let M,N and P,Q be the two pairs of points making up the line segments. Their movement is governed by t.
$M_x(t) = G_x + G_{vx} * t + r_1\cos(\theta_1 + \omega_1 * t)$
$M_y(t) = G_y + G_{vy} * t + r_1\sin(\theta_1 + \omega_1 * t)$
$N_x(t) = G_x + G_{vx} * t + r_2\cos(\theta_2 + \omega_1 * t)$
$N_y(t) = G_y + G_{vy} * t + r_2\sin(\theta_2 + \omega_1 * t)$
$P_x(t) = H_x + H_{vx} * t + r_3\cos(\theta_3 + \omega_2 * t)$
$P_y(t) = H_y + H_{vy} * t + r_3\sin(\theta_3 + \omega_2 * t)$
$Q_x(t) = H_x + H_{vx} * t + r_4\cos(\theta_4 + \omega_2 * t)$
$Q_y(t) = H_y + H_{vy} * t + r_4\sin(\theta_4 + \omega_2 * t)$
Now I need to find the zeros of the distance or distance squared function. We find the distance between I and P using M and N to compute dx and dy.
The distance formula is :
$D^2 = X^2 + Y^2 == 0$
$X = Px(t) - Ix(t)$
$Y = Py(t) - Iy(t)$
I suppose I can solve both X^2 = 0 and Y^2 = 0 but I don't know how and the substitution is a nightmare. What can I do from here?
Since $D^2=X^2+Y^2$, $D^2=0\implies X=0\land Y=0$.
Then I believe you get something like $P_x(t)=I_x(t)$ and $P_y(t)=I_y(t)$. I believe it should be easier from here.
Hope this helps,
Gareth