Original article: w:Line–sphere intersection
해석 기하학(analytic geometry)에서, 직선(line)과 구(sphere)는 세 방법에서 교차(intersect)할 수 있습니다:
- 전혀 교차하지 않습니다.
- 정확히 한 점에서 교차합니다.
- 두 점에서 교차합니다.
이들 경우를 구별하고, 후자의 경우에서 점에 대한 좌표(coordinates)를 결정하는 방법은 여러 상황에서 유용합니다. 예를 들어, 그것은 반직선 추적(ray tracing) 동안 수행하기 위한 공통 계산입니다.
Calculation using vectors in 3D
벡터 표기법(vector notation)에서, 방정식은 다음과 같습니다:
구(sphere)에 대해 방정식:
- \(\left\Vert \mathbf{x} - \mathbf{c} \right\Vert^2=r^2\)
- \(\mathbf{c}\) - 중심 점
- \(r\) - 반지름
- \(\mathbf{x}\) - 구 위의 점
\(\mathbf{o}\)에서 시작하는 직선에 대해 방정식:
- \(\mathbf{x}=\mathbf{o} + d\mathbf{u}\)
- \(d\) - 시작하는 점으로부터 직선을 따라 거리
- \(\mathbf{u}\) - 직선의 방향 (단위 벡터(unit vector))
- \(\mathbf{o}\) - 직선의 원점
- \(\mathbf{x}\) - 직선 위의 점
직선과 구 위에 있는 점을 찾는 것은 벡터의 점 곱(dot product)을 포함하여 방정식을 결합하고 \(d\)에 대해 푸는 것을 의미합니다:
- 결합된 방정식
- \(\left\Vert \mathbf{o} + d\mathbf{u} - \mathbf{c} \right\Vert^2=r^2 \Leftrightarrow (\mathbf{o} + d\mathbf{u} - \mathbf{c}) \cdot (\mathbf{o} + d\mathbf{u} - \mathbf{c}) = r^2\)
- 전개합니다
- \(d^2(\mathbf{u}\cdot\mathbf{u})+2d(\mathbf{u}\cdot(\mathbf{o}-\mathbf{c}))+(\mathbf{o}-\mathbf{c})\cdot(\mathbf{o}-\mathbf{c})=r^2\)
- 다시-정렬합니다
- \(d^2(\mathbf{u}\cdot\mathbf{u})+2d(\mathbf{u}\cdot(\mathbf{o}-\mathbf{c}))+(\mathbf{o}-\mathbf{c})\cdot(\mathbf{o}-\mathbf{c})-r^2=0\)
- 이차 공식(quadratic formula)의 형식이 이제 관찰될 수 있습니다. (이 이차 방정식은 요아힘스탈(Joachimsthal) 방정식의 한 예제입니다.)
- \(a d^2 + b d + c = 0\)
- 여기서
- \(a=\mathbf{u}\cdot\mathbf{u}=\left\Vert\mathbf{u}\right\Vert^2\)
- \(b=2(\mathbf{u}\cdot(\mathbf{o}-\mathbf{c}))\)
- \(c=(\mathbf{o}-\mathbf{c})\cdot(\mathbf{o}-\mathbf{c})-r^2=\left\Vert\mathbf{o}-\mathbf{c}\right\Vert^2-r^2\)
- 단순화합니다
- \(d=\frac{-2(\mathbf{u}\cdot(\mathbf{o}-\mathbf{c})) \pm \sqrt{(2(\mathbf{u}\cdot(\mathbf{o}-\mathbf{c})))^2-4\left\Vert\mathbf{u}\right\Vert^2(\left\Vert\mathbf{o}-\mathbf{c}\right\Vert^2-r^2)}}{2 \left\Vert\mathbf{u}\right\Vert^2}\)
- \(\mathbf{u}\)가 단위 벡터이고, 따라서 \(\left\Vert\mathbf{u}\right\Vert^2=1\)임에 주목하십시오. 따라서, 우리는 이것을 다음으로 더욱이 단순화할 수 있습니다:
- \(d=-(\mathbf{u}\cdot(\mathbf{o}-\mathbf{c})) \pm \sqrt{\nabla}\)
- \(\nabla=(\mathbf{u}\cdot(\mathbf{o}-\mathbf{c}))^2-(\left\Vert\mathbf{o}-\mathbf{c}\right\Vert^2-r^2)\)
- 만약 \(\nabla < 0\)이면, 해가 존재하지 않음, 즉, 직선이 구와 교차하지 않음이 분명합니다 (경우 1).
- 만약 \(\nabla = 0\)이면, 정확하게 하나의 해가 존재합니다, 즉, 직선은 단지 구와 하나의 점에서 접촉합니다 (경우 2).
- 만약 \(\nabla > 0\)이면, 두 해가 존재하고, 따라서 직선은 두 점에서 구와 접촉합니다 (경우 3).
See also
References
- Eberly, David H. (2006). 3D game engine design: a practical approach to real-time computer graphics, 2nd edition. Morgan Kaufmann. p. 698. ISBN 0-12-229063-1.
- [1]