【发布时间】:2016-03-12 14:57:25
【问题描述】:
我正在尝试编写一个函数,如果光线与球体相交并且我引用的代码如下所示,则返回 true:
// 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) 的参数方程结合起来,但我不知道该怎么做。
【问题讨论】:
-
见ray and ellipsoid intersection accuracy improvement如果你有球体那么不需要转换......
标签: math 3d raytracing