Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Its not just for fun that most game programmers work strictly in triangles.. problems such as the one you mentioning becomes so much faster to calculate...

Simple solution: Make sure you are only dealing with triangles.. create a static point for each triangle, which you know is within it.. now make a line from that point to your point, check if it intersects with any of the lines in your triangle... if true, its outside, false, inside.

Most general solution: I believe this was allready mentioned, but create a line between your point and any point which you know is outside of the polygon.. now count the number of intersections between this line, and edges in your polygon.. if its odd, your point is inside, otherwise outside.. (note: do not count intersections with edges, just ignore them... and this solution does not only work with triangles, but any polygon)

Alternative solution: This one will also only work with triangles.. project your point onto two of the edges in the polygon. Yous should now have two fractions t1 and t2 telling you where your point projected onto the two edges.. if both t1 and t2 are between 0 and 1, and t1+t2<1 then your point lies within..

Anyways, have fun... if you need more solutions, search for pages about the nonzero winding number rule... I'm too tired to explain it now, but it should be easy to find a good page on it... (Note: this method will also work well with polygons that intersect with temselves to generate hollow areas within.. )


In reply to Re: Points, Lines. Polygons OO my by kapper
in thread Points, Lines. Polygons OO my by mitd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (8)
As of 2024-04-18 17:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found