- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在这里问是否有人可以检查我的Ray-Triangle交集代码是否正确,或者我有一些错误,因为它似乎无法正常工作。
Vector3f:
struct Vector3f
{
Vector3f(): x(0), y(0), z(0) { }
Vector3f(GLfloat a, GLfloat b, GLfloat c): x(a), y(b), z(c) { }
GLfloat x, y, z;
};
Vector3f CMath::CrossProduct(Vector3f a, Vector3f b)
{
Vector3f result;
result.x = (a.y * b.z) - (a.z * b.y);
result.y = (a.z * b.x) - (a.x * b.z);
result.z = (a.x * b.y) - (a.y * b.x);
return result;
}
GLfloat CMath::InnerProduct(Vector3f a, Vector3f b)
{
return (a.x * b.x) + (a.y * b.y) + (a.z * b.z);
}
bool CMath::RayIntersectsTriangle(Vector3f p, Vector3f d, Vector3f v0, Vector3f v1, Vector3f v2, Vector3f &hitLocation)
{
Vector3f e1, e2, h, s, q;
GLfloat a, f, u, v, t;
e1.x = v1.x - v0.x;
e1.y = v1.y - v0.y;
e1.z = v1.z - v0.z;
e2.x = v2.x - v0.x;
e2.y = v2.y - v0.y;
e2.z = v2.z - v0.z;
h = CrossProduct(d,e2);
a = InnerProduct(e1,h);
if(a > -0.00001 && a < 0.00001)
return false;
f = 1 / a;
s.x = p.x - v0.x;
s.y = p.y - v0.y;
s.z = p.z - v0.z;
u = f * InnerProduct(s,h);
if(u < 0.0 || u > 1.0)
return false;
q = CrossProduct(s,e1);
v = f * InnerProduct(d,q);
if(v < 0.0 || u + v > 1.0)
return false;
t = f * InnerProduct(e2,d);
if(t > 0.00001)
{
hitLocation.x = p.x + t * d.x;
hitLocation.y = p.y + t * d.y;
hitLocation.z = p.z + t * d.z;
return true;
}
else
return false;
}
最佳答案
首先,我建议将InnerProduct
重命名为DotProduct
(请参阅Dot product)。
您有一个由3个点v0
,v1
和v2
定义的平面,以及一个由点p
和方向d
定义的射线。
在伪代码中,平面图与射线的交点为:
n = cross(v1-v0, v2-v0) // normal vector of the plane
t = dot(v0 - p, n) / dot(d, n) // t scale d to the distance along d between p and the plane
hitLocation = p + d * t
Vector3f n = CrossProduct(e1, e2);
s
是
p - v0
(而不是
v0 - p
),因此必须反转射线方向的比例:
t = - InnerProduct(s, n) / InnerProduct(d, n)
关于c++ - 我的射线三角形交叉点代码正确吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59912638/
我正在准备数据库关系的自动文档。该工具是graphviz。我的问题是输出图像上节点的放置不是最佳的,并且有许多不必要的边缘交叉。 是否有任何方法可以执行图形的优化,以便结果将具有最小边交叉(交叉)?
如何判断圆和矩形在二维欧几里得空间中是否相交? (即经典的二维几何) 最佳答案 这是我的做法: bool intersects(CircleType circle, RectType rect) {
切换到 Aframe 的主版本后,光线转换器相交事件似乎变为空,尽管我保留了完全相同的代码: 使用注册组件: AFRAME.registerComponent('collider-check', {
就效率而言,Strassen 算法应该停止递归并应用乘法的最佳交叉点是多少? 我知道这与具体的实现和硬件密切相关,但对于一般情况应该有某种指南或某人的一些实验结果。 在网上搜索了一下,问了一些他们认为
我正在尝试使用 jquery 来切换某些类的显示属性(打开和关闭)。 我正在尝试在图像和下面的文本之间切换,以在点击时切换 Charity Run
我创建了一张 map ,其中每 1/4 分钟绘制一次纬度和经度线。生成的框称为“刻钟分钟”。我需要给每个刻钟框贴上标签。标签应该是盒子内西南 Angular 的纬度/经度。由于我先绘制可视区域内的所有
我只需要一种方法来告诉我轴对齐的 3D 边界框是否与线段(不是射线)相交。我不需要交点。 盒子由两个对角定义,线段由起点和终点定义,如下所示: Boolean intersection(Vector3
我是一名优秀的程序员,十分优秀!