[Gambas-user] gb3: 2D ray-casting algorithm

Benoît Minisini gambas at ...1...
Sun Aug 12 13:53:54 CEST 2012


Le 12/08/2012 08:27, Kevin Fishburne a écrit :
> I need to know if a point lies within a three-sided polygon (triangle)
> on a 2D plane for combat hit detection in my game. Raw speed, not
> mathematical purity is extremely important. I've read this:
>
> http://en.wikipedia.org/wiki/Point_in_polygon
>
> and many more articles and posts and have come to the conclusion that my
> brain is not wired to solve this sort of problem independently in a
> reasonable time frame. I somewhat understand the concept, but not the
> mathematical implementation.
>
>   From what I understand, you take the point and create a ray from it (a
> line with a beginning but no end), then do an intersection calculation
> between the ray and each line segment of the triangle. If the number of
> intersections is odd then the point is inside the triangle. If the
> number of intersections is even then the point is outside the triangle.
> So I guess what I'm asking is how do you define a ray (even a "fake" one
> like a line segment with one point REALLY far away for speed) and how do
> you calculate if a ray intersects a line segment? Stuff like this
> humbles me because I know it must be simple mathematically but I'm just
> too damn stupid to grok it. Thanks, as always.
>

Why don't you ask Google ?

http://www.blackpawn.com/texts/pointinpoly/default.html

-- 
Benoît Minisini




More information about the User mailing list