Skip to main content
12-Amethyst
Jun 10, 2014 5:51 AM UTC
Solved

Finding if a point is inside of an drawn area or not

Hi

I try to make a relatively simple program how to find if a point is inside an drawn area or not.

The problem is illustrated in the attached calculation sheet.

Thank you for your advices in advance.

RichardJAnswer
19-Tanzanite
Jun 10, 2014 12:37 PM UTC

Here's one that works for both points. This was written by Stuart, not by me. I just pulled it from my collection.

23 replies

19-Tanzanite
Jun 10, 2014 8:42 AM UTC

The attached has a simple routine to do what you want (I hope!).

It needs to be tested more extensively and should probably be vectorised, but I'll leave that to you.

Alan

Translate
1-Visitor
Jun 10, 2014 8:57 AM UTC

Nice work Alan. I started to write a routine going down a similar route to what you have and then realised I have actual work to do

Translate
12-Amethyst
Jun 10, 2014 9:47 AM UTC

Hi Alan

Thanks for your programmin work.

I tested your code a bit, but unfortunately at least one point resulted into incorrect answer,

see attached.

Translate
Werner_E
25-Diamond I
Jun 10, 2014 9:00 PM UTC

Here is a testsheet to compare different algorithms with different data sets. I included Alan's second approach and Stuart's algorithm and hope I moved them over correctly. I also added one where I count how often a point is orbited by the polygon. This number should be zero for points outside the polygon. The algorithm seems to work pretty well also with non well behaved polygons, but still would need some work as some vertices are counted as in and some as out. The same goes for points lying on a polygon side. This is sure not an issue for the problem under discussion here, though.

Translate
Werner_E
25-Diamond I
Jun 11, 2014 1:24 AM UTC

Here is my second try. It seems that omitting the polygon sides which contain the point to be checked from building the angle sum and adding a tolerance to copy with roundoff error does the job. Now all points of the polygon (vertices and sides) are considered being inside.

EDIT: Only exception seems to be the point of intersection of the self crossing "infinity" (dataset 4).

Translate
12-Amethyst
Jun 11, 2014 10:27 AM UTC

Hi all,

It is nice to see that this problem has generated discussion.

The situation for which I need this inside/outside -test, was illustrated in the last section of the attachment in my original question (, but not very clearly, my apologizes for that...)

In principle, from a CPT (Cone penetration test) which is used for soil investigations, we get a large number of

sleeve resistance values fs and tip resistance values qt. Typical CPT test result is shown in attachment.

With these two values, the soil type can be defined using the charts presented in the second attached picture.

The main issue is to find, that in which area each fs/qt - qt -point hit.

My intention was that after this issue with one polygon is solved, I'll make a program that checks all the areas and defines in which area each point has hit. From those evaluations soil layers could be defined for all depths.

Translate