comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Point/Polygon Routine
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Point/Polygon Routine [message #5596 is a reply to message #5401] Wed, 03 January 1996 00:00 Go to previous message
jlaw is currently offline  jlaw
Messages: 11
Registered: November 1995
Junior Member
In article 760@ncar.ucar.edu, cavanaug@uars1.acd.ucar.edu (Charles Cavanaugh) writes:
>
> Does anyone have a routine that determines if a given 2-D point is inside a
> given 2-D polygon?

I did have, but I left it behind when I changed jobs.

Are you any good at finite elements??( This is where I looked this up)

Consider a triangle of points I,J,K with coordinates
( Xi,Yi) , (Xj,Yj ) , (Xk,Yk).

the Area of the triangle is then

( 1 Xi Yi )
0.5 * det ( 1 Xj Yj )
( 1 Xk Yk )

Now take the point P at ( Xp, Yp ).

( Strictly, if P is inside the triangle) we can define "Area coordinates"
as follows:

Li = area(pjk) / area(ijk)

Lj = area(pki) / area(ijk)

Lk = area(pij) / area(ijk)

If P is indeed inside the triangle, all the area coordinates are positive.
But if P is outside the triangle, one or more is negative.

For a polygon, split it into a set of triangles. If the point is inside one
of the triangles, it must be inside the polygon.

I think this all depends on the points being placed in the correct sense
around the triangle ( ie clockwise or anticlockwise.)You had better experiment
a little, but that is the basic principle.

It is not actually many lines of code.

all the best

f.
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: map_continents, /fill (Ugh!!!)
Next Topic: Problems with draw_xsize keyword in widget_control

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 18:17:52 PDT 2025

Total time taken to generate the page: 0.40261 seconds