Is there a representation of a directed line in 3D such that for any 2 lines, they are collinear if and only if the parameters of their representations are the same?
In addition, I would also need to know how to derive such a representation from 2 vertices on the line.
I have done some searching on this site, and I found an answer for a different question explaining that directed lines in 3D have 4 degrees of freedom: 2 for the direction of the line, and 2 for the point intersecting the line on the origin-intersecting plane said direction vector is a normal of. For simplicity I could represent the plane with 6 degrees, 3 for the unit direction vector of the line, and 3 for the intersection point of the line on the aforementioned plane. My problem is in deriving these from 2 vertices in the line.
This is for a computational geometry algorithm that needs to test collinearity of directed line segments in a set against others in the set. Given a representation with this property, I could potentially derive a hash function for it such that 2 lines with similar hashes are likely to be nearly collinear. This would allow my algorithm to be linear in the best case.
Are you sure that you don’t know how to compute a unit direction vector $\mathbf n$ from the coordinates $P$ and $Q$ of two points? Once you have that, the equation of the plane is just $\mathbf n\cdot\mathbf x=0$ and you can find many questions and answers here and elsewhere on the Web about how to compute the intersection of a line and plane. Many of them involve solving equations, but this intersection can be computed directly: A convenient way is to observe that since the plane goes through the origin, it is the orthogonal rejection of either $P$ or $Q$ from $\mathbf n$, i.e., $P-(\mathbf n\cdot P)\mathbf n$ or $Q-(\mathbf n\cdot Q)\mathbf n$.
You can also use the Plücker matrix representation of a line in order to compute this point directly: if the homogeneous coordinate vectors of the two points are $\mathbf p$ and $\mathbf q$, then the intersection of the line through these points and the plane $\mathbf\pi$ is $$(\mathbf p\mathbf q^T-\mathbf q\mathbf p^T)\mathbf\pi = (\mathbf\pi^T\mathbf q)\mathbf p - (\mathbf\pi^T\mathbf p)\mathbf q.$$ In your case, $\mathbf\pi = (\mathbf n;0)^T$, so the above formula translates into inhomogeneous Cartesian coordinates as $${(\mathbf n\cdot Q)P-(\mathbf n\cdot P)Q \over \mathbf n\cdot Q-\mathbf n\cdot P}.$$ Assuming that the line goes in the direction of $Q$ from $P$, this simplifies to $${(\mathbf n\cdot Q)P-(\mathbf n\cdot P)Q \over \lVert P-Q\rVert}.$$ You’ve already computed this denominator when you found the unit vector $\mathbf n$. This can be further expanded in terms of $Q-P$ instead of $\mathbf n$, but since you need $\mathbf n$ anyway, the orthogonal rejection described earlier is less expensive to compute.