Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] z values of an alpha shape

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] z values of an alpha shape


Chronological Thread 
  • From: Daniel Duque Campayo <>
  • To:
  • Subject: Re: [cgal-discuss] z values of an alpha shape
  • Date: Fri, 7 Mar 2008 11:40:01 +0100

Hello again,

From the lack of answers to my question, I gather there is no function to
tell
if a point is inside a triangle. For the record, I enclose a function I have
written which seems to do the trick. The method is based on projecting a
vector onto two of the sides of the triangle.

Best,

Daniel


// Check whether a point P is inside the (P0,P1,P2) triangle
// P should be coplanar to the triangle
bool is_in_triangle(
const Point& P0, const Point& P1, const Point& P2,
const Point& P) {
Vector v1(P1,P0);
Vector v2(P2,P0);
Vector v(P,P0);

double v1v1=v1.squared_length();
double v2v2=v2.squared_length();
double v1v2=v1*v2;
double vv1=v*v1;
double vv2=v*v2;

double det=v1v1*v2v2-v1v2*v1v2;
if(det==0) return false; // degenerate triangle
double a=vv1*v2v2-vv2*v1v2;
double b=vv2*v1v1-vv1*v1v2;

if ((a<0) || (b<0)) return false;

a/=det;
b/=det;

return (a+b) <= 1;

}

--
Daniel Duque
http://rincon.uam.es/dir?cw=950067138671875



  • z values of an alpha shape, Daniel Duque Campayo, 03/04/2008
    • Re: [cgal-discuss] z values of an alpha shape, Daniel Duque Campayo, 03/07/2008

Archive powered by MHonArc 2.6.16.

Top of Page