射线球相交推导
Ray-Sphere Intersection Derivation
我正在尝试编写一个函数,如果光线与球体相交并且我引用的代码如下所示,returns 为真:
// given Sphere and Ray as arguments
invert the Sphere matrix
make new Ray object
origin of this object = old Ray origin * inverted Sphere matrix
direction = old Ray direction * inverted Sphere matrix
a = |new direction| ^ 2
b = dot product of new origin and new direction
c = |new origin| ^ 2 - 1
det = b*b - a*c
if det > 0 there is an intersection
我一直在理解为什么我们需要先反转 Sphere 矩阵,然后将其乘以 Ray 的原点和方向。我也很困惑如何推导二次方程变量 a、b 和 c 以及结尾。我知道我必须结合射线 (p + td) 和圆 (x dot x - 1 = 0) 的参数方程,但我不知道该怎么做。
您需要反转球体矩阵以使光线在球体的坐标系中,如果球体未缩放,则与简单设置 new_origin = 原点 - sphere_center 相同(并使用原来的方向)
该等式由以下公式构成:
|new_dir*t + new_origin|^2 = r^2 (presumably r is 1)
展开后得到:
|new_dir|^2*t^2 + 2*(new_origin·new_dir)*t + |new_origin|^2-r^2 = 0
我正在尝试编写一个函数,如果光线与球体相交并且我引用的代码如下所示,returns 为真:
// given Sphere and Ray as arguments
invert the Sphere matrix
make new Ray object
origin of this object = old Ray origin * inverted Sphere matrix
direction = old Ray direction * inverted Sphere matrix
a = |new direction| ^ 2
b = dot product of new origin and new direction
c = |new origin| ^ 2 - 1
det = b*b - a*c
if det > 0 there is an intersection
我一直在理解为什么我们需要先反转 Sphere 矩阵,然后将其乘以 Ray 的原点和方向。我也很困惑如何推导二次方程变量 a、b 和 c 以及结尾。我知道我必须结合射线 (p + td) 和圆 (x dot x - 1 = 0) 的参数方程,但我不知道该怎么做。
您需要反转球体矩阵以使光线在球体的坐标系中,如果球体未缩放,则与简单设置 new_origin = 原点 - sphere_center 相同(并使用原来的方向) 该等式由以下公式构成:
|new_dir*t + new_origin|^2 = r^2 (presumably r is 1)
展开后得到:
|new_dir|^2*t^2 + 2*(new_origin·new_dir)*t + |new_origin|^2-r^2 = 0