Re: [algogeeks] Re: plz give some efficient method to find out if a point lies inside or outside the triangle?

2011-07-29 Thread Arun Vishwanathan
@don: is what I have mentioned above almost the same as the method u r saying? On Fri, Jul 29, 2011 at 9:16 PM, Don wrote: > You just need some comparison which determines if they are very close > to equal. You can't expect them to be exactly equal in all 64 bits. > Something like this should be

[algogeeks] Re: plz give some efficient method to find out if a point lies inside or outside the triangle?

2011-07-29 Thread Don
You just need some comparison which determines if they are very close to equal. You can't expect them to be exactly equal in all 64 bits. Something like this should be fine: bool isClose(double a, double b) { const double epsilon = 1.001; return (a < b*epsilon) && (b < a*epsilon); } (Note

Re: [algogeeks] Re: plz give some efficient method to find out if a point lies inside or outside the triangle?

2011-07-29 Thread prashant bhutani
Yeah, the comparison of two floats will be a problem as the behaviour is undefined and depends on the machine architecture and compiler. Thanks & Regards, Prashant Bhutani Senior Undergraduate Computer Science & Engineering (B.Tech) Institute of Technology - BHU (IT-BHU) Varanasi-221005 On Fri,

Re: [algogeeks] Re: plz give some efficient method to find out if a point lies inside or outside the triangle?

2011-07-29 Thread tech rascal
area of 3 triangles being formed by joining the point to 3 vertices can be float n when we add the 3 areas, the sum wud also be float. and this is to b compared with original area don't u think the problem wud arise in comparing the floats? wud that give right ans?? On Fri, Jul 29, 2011 at 9:06 PM

[algogeeks] Re: plz give some efficient method to find out if a point lies inside or outside the triangle?

2011-07-29 Thread Don
That should work, but I'd bet that my method is faster. Don On Jul 29, 6:02 am, Udit Gupta wrote: > Join the given point with all the vertices of the triangle and calculate the > area of each of the three sub-triangles thus formed > now compare the area of original triangle with the sum of the ar

Re: [algogeeks] Re: plz give some efficient method to find out if a point lies inside or outside the triangle?

2011-07-29 Thread Udit Gupta
Join the given point with all the vertices of the triangle and calculate the area of each of the three sub-triangles thus formed now compare the area of original triangle with the sum of the area of those 3 triangles if that comes out to be equal, then the point lies inside otherwise not. On Fri,

[algogeeks] Re: plz give some efficient method to find out if a point lies inside or outside the triangle?

2011-07-28 Thread Don
// True if point (x,y) is above line defined by two points // If line is vertical, "above" is defined as to the right bool above(double lx1, double ly1, double lx2, double ly2, double x, double y) { return (lx1 != lx2) ? (y > (ly1+(x-lx1)*(ly2-ly1)/(lx2-lx1))) : (x > lx1); } // True if point 1

[algogeeks] Re: plz give some efficient method to find out if a point lies inside or outside the triangle?

2011-07-28 Thread Don
A point is inside a triangle iff: for each pair of vertices of the triangle, the point is on the same side of the line defined by those points as the third vertex of the triangle. Don On Jul 28, 1:47 pm, tech rascal wrote: > -- You received this message because you are subscribed to the Google