Graphics Reference
In-Depth Information
if (u < 0.0f || u > 1.0f) return 0;
// Compute the barycentric coordinate v; exit if negative
v = Dot(s, tri.edgePlaneCA.n) - tri.edgePlaneCA.d;
if (v < 0.0f) return 0;
// Compute the barycentric coordinate w; exit if negative
w=1.0f-u-v;
if (w < 0.0f) return 0;
// Segment intersects tri at distance t in position s (s = u*A + v*B + w*C)
return 1;
}
By multiplying with denom throughout, it is possible to defer the (often expensive)
division until the segment has been found actually intersecting the triangle.
For a triangle ABC , the triangle structure tri can be initialized as follows.
Triangle tri;
Vector n = Cross(b - a,c-a);
tri.p = Plane(n, a);
tri.edgePlaneBC = Plane(Cross(n, c - b), b);
tri.edgePlaneCA = Plane(Cross(n, a - c), c);
To have the edge planes compute the barycentric coordinates of the point for
which they are evaluated, they must be scaled to return a distance of one for the
opposing triangle vertex (not on the plane).
tri.edgePlaneBC *= 1.0f / (Dot(a, tri.edgePlaneBC.n) - tri.edgePlaneBC.d);
tri.edgePlaneCA *= 1.0f / (Dot(b, tri.edgePlaneCA.n) - tri.edgePlaneCA.d);
The triangle record is now completely initialized and can be stored. Note that
no triangle vertices are required for performing the intersection test. This triangle
record requires 12 floating-point components, compared to the nine floating-point
components required for storing the three vertices of the triangle as used by the initial
method.
5.3.7 Intersecting Ray or Segment Against Cylinder
An infinite cylinder of any orientation can be specified by a line, defined by two points
P and Q and by a radius r .If X denotes a point on the surface of the cylinder, the
 
Search WWH ::




Custom Search