Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] Problem about Intersection

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] Problem about Intersection


Chronological Thread 
  • From: "Wesley Smith" <>
  • To:
  • Subject: Re: [cgal-discuss] Problem about Intersection
  • Date: Sun, 21 Oct 2007 00:42:43 -0700
  • Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=LVce1Z1XU7vNol9CIG3/udSmN2BuhuTzcDAotwehRv9TR0EU82OZ0mFeUjlOK0sCQzme3mpg1EN4VN+kBDJndb70dPVln9+ecyfOvd59xhcFG8krARzQhv2MqOJy7jgooQJX1E4WGKgkyCiWR7n9joV2fCq4pd5rL5dR7nRBOzw=

I peresonally found this operation in CGAL a bit lacking, so I use the
code from Tomas Moller:
http://www.cs.lth.se/home/Tomas_Akenine_Moller/raytri/raytri.c

You can google their paper describing the method. It gives values (t,
u, v) where t is the distance along the ray to the intersection point
and u and v are barycentric coordinates of the intersection on the
triangle.

Sample usage:

void ray_mesh_intersction(vector<Facet> &facets, const Ray &r)
{
Point o = r.source();
Direction d = r.direction();

double orig[] = {o.x(), o.y(), o.z()};
double dir[] = {d.dx(), d.dy(), d.dz()};

for(int f = 0; f < facets.size(); f++) {
Triangle tri = V->dual().triangle(facets[f]);

double vert0[] = {tri.vertex(0).x(), tri.vertex(0).y(),
tri.vertex(0).z()};
double vert1[] = {tri.vertex(1).x(), tri.vertex(1).y(),
tri.vertex(1).z()};
double vert2[] = {tri.vertex(2).x(), tri.vertex(2).y(),
tri.vertex(2).z()};
double t, u, v;

if(intersect_triangle2(orig, dir, vert0, vert1, vert2, &t,
&u, &v)) {
if(t > 0) {
//printf("intersect: %f %f %f\n", t, u, v);
//intersect point is Point(t*dir[0]+orig[0],
t*dir[1]+orig[1],
t*dir[2]+orig[2]);
}
}
}
}



Archive powered by MHonArc 2.6.16.

Top of Page