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, Jul 29, 2011 at 11:43 PM, tech rascal <[email protected]>wrote:

> 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, Don <[email protected]> wrote:
>
>> That should work, but I'd bet that my method is faster.
>> Don
>>
>> On Jul 29, 6:02 am, Udit Gupta <[email protected]> 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 area of
>> those
>> > 3 triangles
>> > if that comes out to be equal, then the point lies inside
>> > otherwise not.
>> >
>> > On Fri, Jul 29, 2011 at 1:34 AM, Don <[email protected]> wrote:
>> > > // 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 and point 2 are on the same side of the line
>> > > defined by l1 and l2
>> > > bool sameSide(double lx1, double ly1, double lx2, double ly2, double
>> > > px1, double py1, double px2, double py2)
>> > > {
>> > >    return above(lx1, ly1, lx2, ly2, px1, py1) == above(lx1, ly1, lx2,
>> > > ly2, px2, py2);
>> > > }
>> >
>> > > // True if point (x,y) is inside triangle
>> > > bool pointInTriangle(double x1, double y1, double x2, double y2,
>> > > double x3, double y3, double x, double y)
>> > > {
>> > >    return sameSide(x1,y1,x2,y2,x,y,x3,y3) &&
>> > >           sameSide(x1,y1,x3,y3,x,y,x2,y2) &&
>> > >           sameSide(x2,y2,x3,y3,x,y,x1,y1);
>> > > }
>> >
>> > > --
>> > > You received this message because you are subscribed to the Google
>> Groups
>> > > "Algorithm Geeks" group.
>> > > To post to this group, send email to [email protected].
>> > > To unsubscribe from this group, send email to
>> > > [email protected].
>> > > For more options, visit this group at
>> > >http://groups.google.com/group/algogeeks?hl=en.
>> >
>> >
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to