首页 > 其他 > 详细

求直线与三角形的交点

时间:2014-03-07 16:29:15      阅读:585      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
//求直线 s1 s2 与三角形v0,v1,v2的交点
e1 = v1 - v0;
e2 = v2 - v0;
dir = s2 - s1;
p = cross_product(dir, e2);
tmp = (num_type)1/(p*e1);
s = s1 - v0;
u = tmp * s * p;
if(u < 0 || u > 1)
{
    //the intersection is not in the triangle
    return;
}
q = cross_product(s, e1);
v = tmp * dir * q;
if(v < 0 || v > 1)
{
    //the intersection is not in the triangle
    return;
}
if(u + v > 1)
{
    //the intersection is not in the triangle
    return;
}

//the result is stored in inter->pt
pt = s1+(tmp*e2*q)*dir;
bubuko.com,布布扣

求直线与三角形的交点,布布扣,bubuko.com

求直线与三角形的交点

原文:http://www.cnblogs.com/soulgon/p/3584800.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!