线条与球体之间的交点 [英] Intersection between a line and a sphere

查看:190
本文介绍了线条与球体之间的交点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出一个球体和一条线之间的交点,但老实说,我不知道如何去做。
任何人都可以帮我解决这个问题吗?

解决方案

(t)= x0 *(1-t)+ t * x1(t):

  
{y(t)= y0 *(1-t)+ t * y1
{z(t)= z0 *(1-t)+ t * z1

t = 0 时,它将在一个终点(X0,Y0,Z0)。当 t = 1 时,它将位于另一个终点(x1,y1,z1) p>

t (其中(xc,yc,zc)是球体的中心):

  f(t )=(x(t)-xc)^ 2 +(y(t)-yc)^ 2 +(z(t)-zc)^ 2 

f(t)等于<$时解决 t c $ c> R ^ 2 ( R 是球体的半径):

< (x(t)-xc)^ 2 +(y(t)-yc)^ 2 +(z(t)-zc)^ 2 = R ^ 2

A =(x0-xc)^ 2 +(y0-yc)^ 2 +(z0-zc)^ 2 - R ^ 2
B =(x1-xc)^ 2 +(y1 (x 0 -x 1)^ 2 +(y 0 -y 1)^ 2 +(z 0 -z 1)^ 2(z 1 -zc)^ 2-ΔC-R ^ 2

求解 A + B * t + C * t ^ 2 = 0 t 。这是一个正常的二次方程式



您可以起床到两个解决方案。 t 介于0和1之间的任何解决方案都是有效的。



如果您获得<$ c

我假设你的意思是一个线段(两端-points)。如果你想要一整行(无限长),那么你可以选择沿线的两个点(不要太靠近),并使用它们。另外,让 t 成为任何实际值,而不仅仅是在0和1之间。

编辑:我修正了 B 的公式。我正在混合的迹象。谢谢M Katz,提到它没有用。


I'm trying to find the point of intersection between a sphere and a line but honestly, I don't have any idea of how to do so. Could anyone help me on this one ?

解决方案

Express the line as an function of t:

{ x(t) = x0*(1-t) + t*x1
{ y(t) = y0*(1-t) + t*y1
{ z(t) = z0*(1-t) + t*z1

When t = 0, it will be at one end-point (x0,y0,z0). When t = 1, it will be at the other end-point (x1,y1,z1).

Write a formula for the distance to the center of the sphere (squared) in t (where (xc,yc,zc) is the center of the sphere):

f(t) = (x(t) - xc)^2 + (y(t) - yc)^2 + (z(t) - zc)^2

Solve for t when f(t) equals R^2 (R being the radius of the sphere):

(x(t) - xc)^2 + (y(t) - yc)^2 + (z(t) - zc)^2 = R^2

A = (x0-xc)^2 + (y0-yc)^2 + (z0-zc)^2 - R^2
B = (x1-xc)^2 + (y1-yc)^2 + (z1-zc)^2 - A - C - R^2
C = (x0-x1)^2 + (y0-y1)^2 + (z0-z1)^2

Solve A + B*t + C*t^2 = 0 for t. This is a normal quadratic equation.

You can get up to two solutions. Any solution where t lies between 0 and 1 are valid.

If you got a valid solution for t, plug it in the first equations to get the point of intersection.

I assumed you meant a line segment (two end-points). If you instead want a full line (infinite length), then you could pick two points along the line (not too close), and use them. Also let t be any real value, not just between 0 and 1.

Edit: I fixed the formula for B. I was mixing up the signs. Thanks M Katz, for mentioning that it didn't work.

这篇关于线条与球体之间的交点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆