I have two velocity vectors in 3D and their positions, how would I check if they are colliding in 3D without using bounding sphere or any other primitive.
const double tx = poi.Position().GetLongitude() - m_sPosAV.GetLongitude() / m_sVelAV.x - velocity.at(0).toDouble();
const double ty = poi.Position().GetAltitude() - m_sPosAV.GetAltitude() / m_sVelAV.y - velocity.at(1).toDouble();
const double tz = poi.Position().GetLatitude() - m_sPosAV.GetLatitude() / m_sVelAV.z - velocity.at(2).toDouble();
if (tx == 0 || ty == 0 || tz == 0)
{
qDebug() << "collision ";
return true;
}
if (tx && ty && tz)
{
if (tx == ty)
{
qDebug() << "collision at that time ";
return true;
}
else if (tx == tz)
{
qDebug() << "collision at that time";
return true;
}
}
}
Suppose, the starting points are $$a=\pmatrix{a_1\\a_2\\a_3}$$ and $$b=\pmatrix{b_1\\b_2\\b_3}$$ and the velocities are $$u=\pmatrix{u_1\\u_2\\u_3}$$ and $$v=\pmatrix{v_1\\v_2\\v_3}$$
To find out whether a collision actually occurs, check whether there exists $t\in \mathbb R$ with $a+tu=b+tv$. If you want to know whether the lines have a common point, check whether there exist $s,t\in \mathbb R$ with $a+su=b+tv$
The second verification is not trivial to program in c++ , but the first is relatively easy : If $u=v$ , then a collision occurs if and only if $a=b$.
Otherwise find different components (for example $u_1$ and $v_1$) and calculate $t=\frac{b_1-a_1}{u_1-v_1}$ (the index could be $2$ or $3$) and verify whether $a_2+tu_2=b_2+tv_2$ and $a_3+tu_3=b_3+tv_3$ is satisfied
(Checking equality is problematic in a program, so verify that the absolute difference of two numbers is smaller than, lets say, $10^{-9}$ instead of verifying the equality directly)