0
\$\begingroup\$

I'm reading through "Mathematics for 3D Game Programming, and Computer Graphics" as a refresher, and leading in to some more complex real world problems down the line. However, one of the early chapters has a bit of math that seems overly complicated. This question deals with a problem from the textbook, that I believe the solution is far simpler than their recommended one.

The problem is to find the distance between two lines (in 2 or 3 dimensions).

Some set up:

1) Lines are set up parametrically as opposed to two points.

Line 1: P_{1}(t_{1})

Line 2: P_{2}(t_{2})

Where P = S + tV -- S is the starting point (say, A) and equals (1-t) * A


Now the book states to use this solution : ||P_{1}-P_{2}|| ^2

Expanded looks like:

d = f( t_{1}, t_{2} ) = P_{1}(t_{1})^2 + P_{2}(t_{2})^2 - 2P_{1}\cdot P_{2}(t_{2})

Then the books next step is to reduce this, and take the derivatives with respect to time for both

t_{1} and t_{2}

Once the derivatives have been calculated. We move to a matrix form, and solve using some linear algebra.


My question is this, why would I use that series of steps when I already know the [ x, y, z ] for both points using the parametric. With those values wouldn't the simpler solution be just to do:

V_{a} = S_{1} + tV_{1}

V_{b} = S_{2} + tV

Then:

V = V_{b} - V_{a}

Finally:

\sqrt{V\cdot V}

Is there some direct application of the former equations that I am missing (the book does not elaborate currently on its applications here)? I've had some discussion with other game developers, and we haven't found much a use case for the linear algebra set up.


Edit: (The linear algebra solution)

First both derivatives with respect to time:

df/dt1

df/dt2

Then in matrix form, solve for both t variables:

Final matrix form

\$\endgroup\$
  • 3
    \$\begingroup\$ I recommend math.stackexchange.com for this. \$\endgroup\$ – Almo Dec 17 '15 at 19:06
  • \$\begingroup\$ This is really geared for software development, math.stackexchange may not know how this applies to games and software development \$\endgroup\$ – Bennett Yeates Dec 17 '15 at 19:07
  • 2
    \$\begingroup\$ I also recommend taking this to math.stackexchange.com. While this is meant for game development, a lot of software questions boil down to understanding the math involved. If you don't understand the math (such as here) then the place to ask is the place dealing with math. Nothing in your question explicitly deals with games at all. \$\endgroup\$ – Draco18s Dec 17 '15 at 19:16
  • \$\begingroup\$ I can definitely add this question to math.stackexchange, however, distance between points is a trivial and reoccurring game dev. problem. Also I disagree that this problem can be reduced to a simple math understanding, since comprehension of the math involved is not the problem, but the issue resides in the direct application of the more complicated solution which math.stackexchange may not know the answer to. \$\endgroup\$ – Bennett Yeates Dec 17 '15 at 19:21
  • 1
    \$\begingroup\$ The linear algebra you've shown is being used to solve for the values of t1 & t2 (which are initially unknown), so that we know which two points Va & Vb to measure the distance between. As Sam Hocevar says in an answer below, that makes this a necessary step to determining the distance between these lines in the way that you propose. (If you don't want to know the location of the closest approach, then there are simpler ways) \$\endgroup\$ – DMGregory Dec 18 '15 at 22:30
1
\$\begingroup\$

Your V = Vb - Va is a function of two variables t1 and t2, and so is your sqrt(V·V). You cannot minimise that value without analysing a function of t1 and t2 of some sort, which is what the author does. It’s complicated because it’s a difficult problem, but it’s not overly complicated.

\$\endgroup\$
  • \$\begingroup\$ can the downvoter please explain what was not clear in my answer, maybe? \$\endgroup\$ – sam hocevar Dec 18 '15 at 19:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.