Yahoo Interview Question
Software Engineer / DevelopersThough you can google the math formula for this problem, but I personally prefer to do it in this way:
for one of the two 3D line, express it in three linear equations:
x = a1 * t + b1
y = c1 * t + d1
z = e1 * t + f1
for the other line, you have coefficient a2,b2....f2
now the distance can be expressed as a function of t.
so a little simple math can find the min of distance.
Nix: How do you guarantee that you can have two parallel planes always, why can't you have just two intersecting planes. Now how do you tackle the problem? check it out beibe !
If the planes are not parallel then the lines would intersect and if they do.. the minimum distance will be zero and the maximum distance will be infinity.. so they ahve to be parallel
I assume there exists at least an angle in which the 2 planes in which these 2 lines exist are parallel (else how do you define distance?).
- Nix October 17, 2009Now draw a third line perpendicular to line 1. Measure the distance to when this line hits line2.
Does this make sense?