青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

Intersections of Rays, Segments,


http://softsurfer.com/Archive/algorithm_0105/algorithm_0105.htm

Intersections of Rays, Segments, Planes and Triangles in 3D

by Dan Sunday

Ray/Segment-Plane Intersection
Ray/Segment-Triangle Intersection
Triangle-Plane Intersection
Triangle-Triangle Intersection
Implementations
intersect_RayTriangle()
References

The intersection of the most basic geometric primitives was presented in the Algorithm 5 about Intersections of Lines, Segments and Planes (2D and 3D).  We will now extend those algorithms to include 3D triangles which are common elements of 3D surface and polyhedron models.  We only consider transversal intersections where the two intersecting objects do not lie in the same plane.  Ray and triangle intersection computation is perhaps the most frequent nontrivial operation in computer graphics rendering using ray tracing.  Because of its importance, there are several published algorithms for this problem (see: [Badouel, 1990], [Moller & Trumbore, 1997], [O'Rourke, 1998], [Moller & Haines, 1999]).  We present an improvement of these algorithms for ray (or segment) and triangle intersection.  We also give algorithms for triangle-plane and triangle-triangle intersection.

Objects are represented by vertices: a segment by it's endpoints, a ray as an extended segment, and a triangle by its three vertices.  Lines will be given the parametric equation: P(r) = P0 + r(P1-P0), which is also used for the ray starting at P0 going in the direction (P1-P0), and for the segment from P0 to P1.   A plane will be given by a point V0 on it and a normal vector n.

Ray/Segment-Plane Intersection

This topic was treated in Algorithm 5 (see: Line-Plane Intersection).  We recall the result here for a a ray R (or segment S) from P0 to P1, and a plane p through V0 with normal n.  The intersection of the parametric line L: P(r) = P0 + r(P1-P0) and the plane p occurs at the point P(rI) with parameter value:

When the denominator (P1-P0) = 0, the line L is parallel to the plane p, and thus either does not intersect it or else lies completely in the plane (whenever either P0 or P1 is in p).  Otherwise, when the denominator is nonzero and rI is a real number, then the ray R intersects the plane p only when rI>=0.  A segment S intersects p only if 0<=rI<=1.  In all algorithms, the additional test rI<=1 is the only difference for a segment instead of a ray.

Ray/Segment-Triangle Intersection

Consider a ray R (or a segment S) from P0 to P1, and a triangle T with vertices V0, V1 and V2.  The triangle T lies in the plane p through V0 with normal vector n = (V1-V0)×(V2-V0).  To get the intersection of R (or S) and T, one first determines the intersection of R (or S) and p.  If they do not intersect, then the ray (or segment) also does not intersect T and we are done.  However, if they intersect in the point PI=P(rI), we need to determine if this point is in the triangle T for there to be a valid intersection.

There are a number of ways to test for the inclusion of a point inside a 3D planar triangle.  The algorithms given by [Badouel, 1990] and [O'Rourke, 1998] project the point and triangle onto a 2D coordinate plane where inclusion is tested.  To implement these algorithms, one must choose a projection coordinate plane which avoids a degenerate projection.  This is done by excluding the coordinate which has the largest component in the plane normal vector n [Synder & Barr, 1987].  The intent is to reduce the 3D problem to a simpler 2D problem which has an efficient solution.  However, there is a small overhead involved in selecting and applying the projection function.  The algorithm of [Moller-Trumbore, 1997] (MT) does not project into 2D, and finds a solution using direct 3D computations.  Testing with some complex models shows that the MT algorithm is faster than the one by Badouel.

We present an alternate method which also uses direct 3D computations to determine inclusion, avoiding projection onto a 2D coordinate plane.  As a result, the code is cleaner and more compact.  Like [Moller-Trumbore, 1997], we use the parametric equation of p relative to T, but derive a different method of solution which computes the parametric coordinates of the intersection point in the plane.  The parametric plane equation (see: Planes in Algorithm 4) is given by:

where s and t are real numbers, and u = (V1-V0) and v = (V2-V0) are edge vectors of T.  A point P = V(s,t) is in the triangle T when s>=0, t>=0, and s+t<=1.  So, given PI, one just has to find the (sI,tI)-coordinate for it, and then check these inequalities to verify inclusion in T.  Further, a point P = V(s,t) is on an edge of T if one of the conditions s=0, t=0, or s+t=1 is true (each condition corresponds to one edge).  Also, the three vertices are given by: V0=V(0,0), V1=V(1,0), and V2=V(0,1).

To solve for sI and tI, we define a 3D generalization of Hill's "perp-dot" product [Hill, 1994].  For an embedded 2D plane p with a normal vector n, and any vector a in the plane (that is, a satisfies n·a = 0), define the "generalized perp operator on p" by: a^ = n×a.  Then, a^ is another vector in the plane p (since n·a^ = 0), and it is perpendicular to a (since a·a^ = 0).  Further, this perp operator is linear on vectors in p; that is, (Aa + Bb)^ = Aa^ + Bb^ where a and b are vectors in p, and A and B are scalars.  Note that if p is the 2D xy-plane (z=0) with n = (0,0,1), then this is exactly the same 2D perp operator given by [Hill, 1994].

We can now use this generalized perp operator to solve the plane's parametric equation for the intersection point PI.  Put w = (PI-V0) which is another vector in p.  Then, we want to solve the equation: w = su + tv for s and t.  Take the dot product of both sides with v^ to get: w · v^ = su · v^ + tv · v^ = su · v^, and solve for sI.  Similarly, taking the dot product with u^, we get: w · u^ = su · u^ + tv · u^ = tv · u^, and solve for tI.  We get:

and

The denominators are nonzero whenever the triangle T is nondegenerate (that is, has a nonzero area).  When T is degenerate, it is either a segment or a point, and in either case does not uniquely define a plane and the computed normal vector is (0,0,0).  So, this case must be treated separately as a 3D segment-segment intersection which was treated in Algorithm 5 (see: Lines and Segments).

Altogether we have used 3 cross products which is a lot of computation.  However, for any three vectors a b c, the following identity holds for left association of the cross product:  (a × b) × c = (a · c) b - (b · c) a.  [Note: the cross product is not associative, and so there is a different (but similar) identity for right association].  Applying the left association identity results in the simplifications:

And we can now compute sI and tI using only dot products as:

with 5 distinct dot products.  We have arranged terms so that the two denominators are the same and only need to be calculated once.

This solution yields a straightforward ray/segment-triangle intersection algorithm (see our implementation: intersect_RayTriangle() ).  Based on a count of the operations done up to the first reject test, this algorithm is not as efficient as the [Moller-Trumbore, 1997] (MT) algorithm, although we have not yet done any runtime performance tests.  However, the MT algorithm uses two cross products whereas our algorithm uses only one, and the one we use computes the normal vector of the triangle's plane.  Thus, when the normal vectors have been precomputed and stored for all triangles in a scene (which is often the case), our algorithm would not compute a cross product at all, making it even more efficient.  On the other hand, in this case, the MT algorithm would still compute two cross products, and be less efficient than our algorithm.

Triangle-Plane Intersection

Consider a triangle T with vertices P0, P1 and P2 lying in a plane p1 with normal n1.  Let p2 be a second plane through the point V0 with the normal vector n2.  Unless they are parallel, the two planes p1 and p2 intersect in a line L, and when T intersects p2 it will be a segment contained in L.  When T does not intersect p2 all three of its vertices lie on the same side of the p2 plane.  Otherwise, when T does intersect p2, one point of T must be on one side of p2 and the other two be on the other side.  A test for which side of a plane a point is on (by using the signed distance from the point to the plane) was given in Algorithm 4 (see: Distance of a Point to a Plane). 

Suppose that P0 is on one side of p2 and that P1 and P2 are on the other side.  Then the two segments P0P1 and P0P2 intersect p2 in two points I1 and I2 which are on the intersection line of p1 and p2.  The segment I1I2 is the intersection of triangle T and the plane p2.

Triangle-Triangle Intersection

Consider two triangles T1 and T2.  They each lie a plane, p1 and p2, and their intersection must be on the line of intersection L for the two planes.  Let the intersection of T1 and p2 be S1 = I11I12, and the intersection of T2 and p1 be S2 = I21I22.  If either S1 or S2 is empty (that is, one triangle does not intersect the plane of the other), then T1 and T2 do not intersect.  Otherwise their intersection is equal to the intersection of the two segments S1 and S2 on the line L.  This can be easily computed by projecting them onto an appropriate coordinate axis, and determining their intersection on it.


Implementations

Here are some sample "C++" implementations of these algorithms. 

// Copyright 2001, softSurfer (www.softsurfer.com)
// This code may be freely used and modified for any purpose
// providing that this copyright notice is included with it.
// SoftSurfer makes no warranty for this code, and cannot be held
// liable for any real or imagined damage resulting from its use.
// Users of this code must verify correctness for their application.

// Assume that classes are already given for the objects:
//    Point and Vector with
//        coordinates {float x, y, z;}
//        operators for:
//            == to test equality
//            != to test inequality
//            (Vector)0 = (0,0,0)         (null vector)
//            Point  = Point ± Vector
//            Vector = Point - Point
//            Vector = Scalar * Vector    (scalar product)
//            Vector = Vector * Vector    (cross product)
//    Line and Ray and Segment with defining points {Point P0, P1;}
//        (a Line is infinite, Rays and Segments start at P0)
//        (a Ray extends beyond P1, but a Segment ends at P1)
//    Plane with a point and a normal {Point V0; Vector n;}
//    Triangle with defining vertices {Point V0, V1, V2;}
//    Polyline and Polygon with n vertices {int n; Point *V;}
//        (a Polygon has V[n]=V[0])
//===================================================================

#define SMALL_NUM  0.00000001 // anything that avoids division overflow
// dot product (3D) which allows vector operations in arguments
#define dot(u,v)   ((u).x * (v).x + (u).y * (v).y + (u).z * (v).z)

// intersect_RayTriangle(): intersect a ray with a 3D triangle
//    Input:  a ray R, and a triangle T
//    Output: *I = intersection point (when it exists)
//    Return: -1 = triangle is degenerate (a segment or point)
//             0 = disjoint (no intersect)
//             1 = intersect in unique point I1
//             2 = are in the same plane
int
intersect_RayTriangle( Ray R, Triangle T, Point* I )
{
    Vector    u, v, n;             // triangle vectors
    Vector    dir, w0, w;          // ray vectors
    float     r, a, b;             // params to calc ray-plane intersect

    // get triangle edge vectors and plane normal
    u = T.V1 - T.V0;
    v = T.V2 - T.V0;
    n = u * v;             // cross product
    if (n == (Vector)0)            // triangle is degenerate
        return -1;                 // do not deal with this case

    dir = R.P1 - R.P0;             // ray direction vector
    w0 = R.P0 - T.V0;
    a = -dot(n,w0);
    b = dot(n,dir);
    if (fabs(b) < SMALL_NUM) {     // ray is parallel to triangle plane
        if (a == 0)                // ray lies in triangle plane
            return 2;
        else return 0;             // ray disjoint from plane
    }

    // get intersect point of ray with triangle plane
    r = a / b;
    if (r < 0.0)                   // ray goes away from triangle
        return 0;                  // => no intersect
    // for a segment, also test if (r > 1.0) => no intersect

    *I = R.P0 + r * dir;           // intersect point of ray and plane

    // is I inside T?
    float    uu, uv, vv, wu, wv, D;
    uu = dot(u,u);
    uv = dot(u,v);
    vv = dot(v,v);
    w = *I - T.V0;
    wu = dot(w,u);
    wv = dot(w,v);
    D = uv * uv - uu * vv;

    // get and test parametric coords
    float s, t;
    s = (uv * wv - vv * wu) / D;
    if (s < 0.0 || s > 1.0)        // I is outside T
        return 0;
    t = (uv * wu - uu * wv) / D;
    if (t < 0.0 || (s + t) > 1.0)  // I is outside T
        return 0;

    return 1;                      // I is in T
}


References

Didier Badouel, "An Efficient Ray-Polygon Intersection" in Graphics Gems (1990)

Francis Hill, "The Pleasures of 'Perp Dot' Products" in Graphics Gems IV (1994)
[Note: the first critical definition has a typo, and should be: a^ = (-ay, ax).]

Tomas Moller & Eric Haines, Real-Time Rendering, Chapter 10 "Intersection Test Methods" (1999)

Tomas Moller & Ben Trumbore, "Fast, Minimum Storage Ray-Triangle Intersection"J. Graphics Tools 2(1), 21-28 (1997)

Joseph O'Rourke, Computational Geometry in C (2nd Edition), Section 7.3 "Segment-Triangle Intersection" (1998)

J.P. Snyder and A.H. Barr, "Ray Tracing Complex Models Containing Surface Tessellations", ACM Comp Graphics 21, (1987)

posted on 2008-08-26 15:18 zmj 閱讀(1119) 評論(0)  編輯 收藏 引用


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            在线欧美视频| 一本色道久久88精品综合| 亚洲日产国产精品| 亚洲第一区在线| 欧美精品成人91久久久久久久| 含羞草久久爱69一区| 欧美91大片| 国产精品剧情在线亚洲| 久久精品国产久精国产一老狼| 老牛嫩草一区二区三区日本| 亚洲精品一区二区三区婷婷月| 亚洲精品一区二区在线| 国内揄拍国内精品久久 | 一区二区三区国产精品| 国产精品地址| 久久综合给合久久狠狠狠97色69| 欧美 日韩 国产一区二区在线视频 | 欧美粗暴jizz性欧美20| 亚洲欧美日韩中文在线制服| 久久国产精品99国产精| 在线视频国内自拍亚洲视频| 亚洲神马久久| 99在线|亚洲一区二区| 久久久91精品国产一区二区三区 | 久久经典综合| 国产精品狠色婷| 日韩午夜三级在线| 一区二区三区波多野结衣在线观看| 性久久久久久久久久久久| 亚洲免费精品| 欧美激情视频一区二区三区不卡| 久色婷婷小香蕉久久| 国产日韩欧美一区| 亚洲综合国产精品| 午夜精品短视频| 国产精品免费一区二区三区观看 | 欧美精品一区在线观看| 欧美成人一区二区三区片免费| 激情久久久久久| 久久久夜精品| 91久久精品日日躁夜夜躁欧美| 亚洲国产二区| 欧美激情视频网站| 亚洲视频在线观看网站| 久久综合给合| 亚洲精品久久久久久久久久久久久 | 9l国产精品久久久久麻豆| 亚洲乱码久久| 国产精品久久久久久久电影 | 亚洲大片精品永久免费| 欧美护士18xxxxhd| 亚洲香蕉伊综合在人在线视看| 欧美一区三区二区在线观看| 伊人久久噜噜噜躁狠狠躁| 免费不卡视频| 欧美诱惑福利视频| 亚洲精品视频一区二区三区| 久久国产精品一区二区三区| 亚洲国产精品视频一区| 欧美日韩一区二区国产| 久久久噜噜噜久久中文字免| 亚洲美女在线视频| 久久在线免费| 久久久久国产精品一区三寸| 日韩视频在线观看国产| 伊人夜夜躁av伊人久久| 国产精品xxx在线观看www| 麻豆精品网站| 久久人人爽人人爽爽久久| 亚洲影视综合| 亚洲午夜性刺激影院| 日韩视频一区二区在线观看 | 欧美一区二区性| 午夜精品网站| 亚洲欧美在线磁力| 亚洲一区二区精品视频| 99国产精品久久久久久久久久| 伊人激情综合| 亚洲电影有码| 亚洲国产网站| 国产精品99久久久久久久久久久久| 亚洲东热激情| 亚洲精品极品| 亚洲综合视频1区| 午夜精品久久久久久久白皮肤 | 精品99一区二区| 亚洲免费观看| 亚洲欧美日韩国产成人| 亚洲网址在线| 久热精品视频在线观看一区| 欧美大片在线观看一区二区| 91久久夜色精品国产网站| 99天天综合性| 欧美一区二视频| 欧美激情一区二区三区不卡| 国产精品www网站| 亚洲成色www久久网站| 一区二区不卡在线视频 午夜欧美不卡'| 一本不卡影院| 欧美激情视频在线免费观看 欧美视频免费一 | 久久精品免费观看| 亚洲电影成人| 欧美中文在线字幕| 99re视频这里只有精品| 欧美亚洲午夜视频在线观看| 欧美精品一区二区三区四区| 一区二区视频欧美| 亚洲欧美中文日韩v在线观看| 女主播福利一区| 欧美在线一区二区| 国产精品日韩一区二区| 亚洲精品视频二区| 免费观看亚洲视频大全| 亚洲女同性videos| 国产伦精品一区| 亚洲一区二区三区乱码aⅴ蜜桃女| 久久午夜国产精品| 亚洲国产日韩精品| 欧美电影免费观看网站| 久久天天综合| 亚洲高清网站| 欧美激情一区二区三区在线视频| 久久国产视频网| 在线观看成人av| 欧美a级一区| 欧美精品成人| 欧美一区二区成人6969| 亚洲欧美日韩精品久久亚洲区 | 久久免费一区| 日韩视频欧美视频| 一区二区动漫| 极品少妇一区二区三区精品视频| 久久一区二区三区四区五区| 久久夜精品va视频免费观看| 亚洲人成网站在线观看播放| 一区二区三区成人| 国内欧美视频一区二区| 亚洲欧洲日韩在线| 国产免费成人av| 欧美国产一区视频在线观看| 欧美日韩在线不卡| 久久综合久久综合久久综合| 欧美—级高清免费播放| 欧美在线播放| 欧美视频成人| 亚洲视频电影在线| 久久人体大胆视频| 亚洲一区二区三区视频播放| 蜜臀va亚洲va欧美va天堂 | 亚洲第一精品在线| 国产日韩精品入口| 一本色道久久综合亚洲精品婷婷 | 欧美大色视频| 国产一区二区三区日韩| 99精品免费| 一区二区三区www| 欧美日本三级| 亚洲精品少妇| 99天天综合性| 国产精品美女999| 亚洲无线一线二线三线区别av| 99热在这里有精品免费| 欧美成人午夜剧场免费观看| 麻豆9191精品国产| 亚洲高清电影| 欧美国产亚洲精品久久久8v| 欧美高清在线播放| 亚洲精品美女久久7777777| 久久人人爽人人| 欧美激情精品久久久久久久变态| 91久久精品国产| 欧美激情一区二区三区在线视频| 男女激情久久| 亚洲一区在线免费观看| 国产欧美日韩免费看aⅴ视频| 亚洲欧洲av一区二区| 久久亚洲综合色| 一本大道久久a久久精品综合| 国产精品va在线播放| 亚洲欧美在线视频观看| 欧美国产日韩视频| 亚洲专区在线| 亚洲激情第一页| 国产精品女人网站| 另类酷文…触手系列精品集v1小说| 亚洲免费成人av电影| 久久婷婷国产麻豆91天堂| 亚洲精选久久| 在线欧美亚洲| 国产日韩av高清| 国产精品视频久久| 欧美男人的天堂| 亚洲一区在线观看免费观看电影高清| 国产日韩亚洲欧美精品| 欧美国产日韩精品| 久久久久久久一区二区| 午夜精品www| 亚洲一区亚洲二区| 一本大道久久a久久综合婷婷 | 久久米奇亚洲|