【发布时间】:2012-11-11 03:45:55
【问题描述】:
我的 Plane 类有两个字段:
public Vector3 Norm; //normal vector
public double Offset; //signed distance to origin
这是我用于交集的代码,不知道是否正确。我加倍 检查了我的方程式和所有内容,但我想从人们那里获得反馈 对此更有经验。
public override Intersection Intersect(Ray ray)
{
// Create Intersection.
Intersection result = new Intersection();
// Find t.
double t = - (Vector3.Dot(Norm,ray.Start) + Offset) / (Vector3.Dot(Norm, ray.Dir));
if (t < 0) // the ray does not hit the surface, that is, the surface is "behind" the ray
return null;
// Get a point on the plane.
Vector3 p = ray.Start + t * ray.Dir;
// Does the ray intersect the plane inside or outside?
Vector3 planeToRayStart = ray.Start - p;
double dot = Vector3.Dot (planeToRayStart, Norm);
if (dot > 0) {
result.Inside = false;
} else {
result.Inside = true;
}
result.Dist = t;
return result;
}
另外,如果 t 接近 0,我不确定该怎么办?我应该检查 epsilon 和有多大 epsilon 应该是什么?另外我不确定我是否正确检查光线是否与平面相交 从内到外?
谢谢
【问题讨论】: