Consulting

Results 1 to 7 of 7

Thread: VBA to check if object is inside or outside of freeform area

  1. #1

    VBA to check if object is inside or outside of freeform area

    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
    Attached Images Attached Images

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,959
    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/showth...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.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    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.

  4. #4
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,959
    I know only how to deal with the polygons, so without converting the freeform to a polygon I have nothing more to suggest.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  5. #5
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,405
    Location
    Hmmm.... seems I’ve seen this question before... within the last few hours actually
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  6. #6
    Quote Originally Posted by Aussiebear View Post
    Hmmm.... seems I’ve seen this question before... within the last few hours actually
    Possibly here https://www.mrexcel.com/forum/excel-...-area-not.html

  7. #7
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,959
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •