3
$\begingroup$

I am trying to calculate the intersection point (if any) of two line segments for a 2D computer game. I am trying to use this method, but I want to make sure I understand what is going on as I do it. This method talks about using cross-products, and calculating that by using the determinant of the 2x2 matrix: (x1y2) - (x2y1).

My confusion comes from my remembering that a cross-product gives a vector perpendicular to the others... but it seems to me that calculating that determinant should just give a scalar - we end up with a single number at the end of it.

Where is my misunderstanding?

  • 4
    I think the use of the term "cross product" for that determinant in that blog post is a terminological error. Yes, you remember correctly the proper result of a cross product. There is a determinantal formula for the cross product of two three-dimensional vectors, but there is a special convention in its evaluation and it thus yields a vector instead of a scalar.2011-09-03
  • 3
    In short: he may call it a cross product, but I recommend that you do **not** do the same.2011-09-03
  • 0
    If it's not the cross-product, is there a name for what this blog actually does?2011-09-03
  • 0
    I don't know about name, but the magnitude of 2x2 determinant is twice the area of the triangle with vertices $(0,0)$, $(x_1, y_1)$ and $(x_2, y_2)$. Note that this area is zero if the vector $(x_1,y_1)$ is parallel to $(x_2,y_2)$.2011-09-03
  • 0
    Looks like Cramer's rule to me, slightly modified to account for the fact that we're dealing with segments and not lines.2011-09-03
  • 2
    @J.M. Aha, found the culprit. The Algorithms textbook CLRS gives an identical definition of cross product as a 2x2 determinant (with a footnote saying that it is actually a 3-dimensional concept). Chapter 33 on Computational Geometry.2011-09-03
  • 0
    \*facepalm\* I would have thought those people are above abuse of terminology... oh boy. @Sri, I wouldn't mind if you write an answer that expands on my comments, since you've pinpointed the source of this unfortunate terminology.2011-09-03
  • 1
    @J.M. As you surmised, the book is discussing algorithms for tasks like: (1.) given two vectors, do they turn left or right?, and (2.) intersection of given line segments (this is what is actually discussed in the blog as well). Since all vectors are in the plane and cross-products are always along the z-axis for such vectors, it makes sense for them to treat it just as a scalar.2011-09-03
  • 1
    @Sri: I suppose, but it doesn't mean I have to like/adopt it. It can become a source of confusion (e.g. for Smashery) that a supposedly vector result suddenly becomes scalar.2011-09-03
  • 1
    Smashery, to expand on Srivatsan's last comment: note that if you take the cross product of two vectors $(a,b,0)$ and $(c,d,0)$ lying in the x-y plane, the resulting cross product is $\left(0,0,\begin{vmatrix}a&b\\c&d\end{vmatrix}\right)$.2011-09-03

5 Answers 5