PDA

View Full Version : VBA to check if object is inside or outside of freeform area



platypus007
10-24-2019, 10:37 AM
Hi, I need help with this : I have Freeform area and shapes in form of circles named from A to G. Some of this points are inside of Freeform area and some of them no. I need macro which will check each of this points - if this point is inside/ outside of freeform area. How can i get result in form of table where in Column A are Names of shapes (circles-points) and in column B result (if point is inside/outside of freeform).
Thanks
Victor

Picture of what I need is here:
https://pasteboard.co/IDtXBAc.jpg

p45cal
10-24-2019, 01:58 PM
While it's dead simple for us humans to look at your diagram say very quickly that objects A, F and G are completely outwith your blue freeform, and that all the other objects are completely within it, asking a computer to do it is by no means as easy; however, once done it should be as fast!
When I've looked at this before (and I'm no expert in this) the question has been about points in polygons, that is, the answer to whether a point (not an object) is completely within a polygon (made up of vertices and the straight lines between them).
So my feeling is that you'll need to have an approximation of your freeform shape made up of vertices and the straight lines between them and an approximation of your object's shape in the same way, and test that each vertex of your object is within the freeform approximation (to check that all vertices of your object are within the freeform).

For VBA code to get you started, take a look at http://www.excelfox.com/forum/showthread.php/1579-Test-Whether-A-Point-Is-In-A-Polygon-Or-Not

If you can reduce your objects to a single point (the centre?) it would simplify things a lot, as would reducing your freeform to a polygon (it looks that there might be spline curves in your freeform), otherwise it's a case of testing each point of your objects to ensure that all vertices are inside/ouside of you freeform, and only if they're all in (or out) can you count the object as being completely in (or out) of your freefrom.

platypus007
10-24-2019, 02:26 PM
Thanks for answering my question. Reducing objects to single point is possible, but in case of freeform it will always remain freeform not polygon. More info about my task - The points are in reality related to grid (known GPS cordinates in small local area) and freeform is area with or without covering this points inside.

p45cal
10-25-2019, 08:47 AM
I know only how to deal with the polygons, so without converting the freeform to a polygon I have nothing more to suggest.

Aussiebear
10-25-2019, 11:36 PM
Hmmm.... seems I’ve seen this question before... within the last few hours actually

Fluff
10-26-2019, 07:47 AM
Hmmm.... seems I’ve seen this question before... within the last few hours actually
Possibly here https://www.mrexcel.com/forum/excel-questions/1113267-vba-check-if-circles-inside-freeform-area-not.html

p45cal
10-26-2019, 01:55 PM
…and here:
https://stackoverflow.com/questions/58546675/vba-to-check-if-object-is-inside-or-outside-of-freeform-area