Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Check if a point is inside a polygon

    Scheduled Pinned Locked Moved PYTHON Development
    2 Posts 0 Posters 859 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

      On 07/08/2018 at 07:02, xxxxxxxx wrote:

      I have a closed polygon defined by a list of coordinates (x and y, 2D coordinates).

      The last point connects to the first point.
      I want to check if a point px,py is inside or outside of the polygon.
      The scan line implementation that I have so far, is a bit too slow as it has to go through all the coordinates list.
      Is there a faster way?
      Any internal code that Cinema 4D already has for that?

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        On 08/08/2018 at 02:52, xxxxxxxx wrote:

        Hi rui_mac, thanks for writing us.

        With regard to your request, beside mentioning that, to my knowledge, there's no directly usable function available in the API, I'd consider to google for "testing point in triangle". You'll end mostly with pages pointing to  the Baricentric technique or the "Same-side" technique. Among those, I found them to be  well explained in this "Point in triangle test" page and the idea described can be extended to n-vertices polygons.

        Best, Riccardo

        1 Reply Last reply Reply Quote 0
        • First post
          Last post