점과 선, 선과 선 사이의 거리

학술 2010. 10. 20. 23:59 Posted by 양고
출처: http://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html

1. 점과 선의 거리 (2D)

PointLineDistance2DVec

If the line is specified by two points x_1=(x_1,y_1) and x_2=(x_2,y_2), then a vector perpendicular to the line is given by

 v=[y_2-y_1; -(x_2-x_1)].
(12)

Let r be a vector from the point x_0=(x_0,y_0) to the first point on the line

 r=[x_1-x_0; y_1-y_0],
(13)

then the distance from (x_0,y_0) to the line is again given by projecting r onto v, giving

 d=|v^^·r|=(|(x_2-x_1)(y_1-y_0)-(x_1-x_0)(y_2-y_1)|)/(sqrt((x_2-x_1)^2+(y_2-y_1)^2)).


2. 점과 선의 거리 (3D)


PointLineDistance3D

Let a line in three dimensions be specified by two points x_1=(x_1,y_1,z_1) and x_2=(x_2,y_2,z_2) lying on it, so a vector along the line is given by

 v=[x_1+(x_2-x_1)t; y_1+(y_2-y_1)t; z_1+(z_2-z_1)t].
(1)

The squared distance between a point on the line with parameter t and a point x_0=(x_0,y_0,z_0) is therefore

 d^2=[(x_1-x_0)+(x_2-x_1)t]^2+[(y_1-y_0)+(y_2-y_1)t]^2+[(z_1-z_0)+(z_2-z_1)t]^2.
(2)

To minimize the distance, set d(d^2)/dt=0 and solve for t to obtain

 t=-((x_1-x_0)·(x_2-x_1))/(|x_2-x_1|^2),
(3)

where · denotes the dot product. The minimum distance can then be found by plugging t back into (2) to obtain

d^2=(x_1-x_0)^2+(y_1-y_0)^2+(z_1-z_0)^2+2t[(x_2-x_1)(x_1-x_0)+(y_2-y_1)(y_1-y_0)+(z_2-z_1)(z_1-z_0)]+t^2[(x_2-x_1)^2+(y_2-y_1)^2+(z_2-z_1)^2]
(4)
=|x_1-x_0|^2-2([(x_1-x_0)·(x_2-x_1)]^2)/(|x_2-x_1|^2)+([(x_1-x_0)·(x_2-x_1)]^2)/(|x_2-x_1|^2)
(5)
=(|x_1-x_0|^2|x_2-x_1|^2-[(x_1-x_0)·(x_2-x_1)]^2)/(|x_2-x_1|^2).
(6)

Using the vector quadruple product

 (AxB)^2=A^2B^2-(A·B)^2
(7)

where x denotes the cross product then gives

 d^2=(|(x_2-x_1)x(x_1-x_0)|^2)/(|x_2-x_1|^2),
(8)

and taking the square root results in the beautiful formula

d = (|(x_2-x_1)x(x_1-x_0)|)/(|x_2-x_1|)
(9)
= (|(x_0-x_1)x(x_0-x_2)|)/(|x_2-x_1|)
(10)
.
(11)

Here, the numerator is simply twice the area of the triangle formed by points x_0, x_1, and x_2, and the denominator is the length of one of the bases of the triangle, which follows since, from the usual triangle area formula, Delta=bd/2.

CITE THIS AS:

Weisstein, Eric W. "Point-Line Distance--3-Dimensional." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html


3. 선과 선의 거리 (당연하지만 3D)

http://mathworld.wolfram.com/Line-LineDistance.html

Line-Line Distance

The distance between two skew lines with equations

x = x_1+(x_2-x_1)s
(1)
x = x_3+(x_4-x_3)t
(2)

is given by

 D=(|(x_3-x_1)·[(x_2-x_1)x(x_4-x_3)]|)/(|(x_2-x_1)x(x_4-x_3)|)
(3)

(Gellert et al. 1989, p. 538). This can be written in the concise form

 D=(|c·(axb)|)/(|axb|)
(4)

by defining

a = x_2-x_1
(5)
b = x_4-x_3
(6)
c = x_3-x_1.
(7)

SEE ALSO: Skew Lines, Line-Line Angle, Line-Line Intersection

REFERENCES:

Gellert, W.; Gottwald, S.; Hellwich, M.; Kästner, H.; and Künstner, H. (Eds.). VNR Concise Encyclopedia of Mathematics, 2nd ed. New York: Van Nostrand Reinhold, 1989.

Hill, F. S. Jr. "The Pleasures of 'Perp Dot' Products." Ch. II.5 in Graphics Gems IV (Ed. P. S. Heckbert). San Diego: Academic Press, pp. 138-148, 1994.




CITE THIS AS:

Weisstein, Eric W. "Line-Line Distance." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/Line-LineDistance.html



[2011.10.26 즈음에 한 짓]

두 선 사이의 거리가 최소가 되는 점 X를 찾자.

syms x y z a1 b1 c1 a2 b2 c2 a3 b3 c3 a4 b4 c4;
X = [x y z];
X1 = [a1 b1 c1];
X2 = [a2 b2 c2];
X3 = [a3 b3 c3];
X4 = [a4 b4 c4];
d12 = sum((cross(X2-X1,X1-X)).^2)/sum((X2-X1).^2);
d34 = sum((cross(X4-X3,X3-X)).^2)/sum((X4-X3).^2);
d = d12 + d34;
dx = diff(d,x);
dy = diff(d,y);
dz = diff(d,z);

[x,y,z] = solve(dx,dy,dz, x,y,z)