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

    Find nearest position on a geometry

    Cinema 4D SDK
    r21 python
    3
    6
    638
    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.
    • fwilleke80F
      fwilleke80
      last edited by

      Hello,

      is there a handy API function to find the nearest position on a geometry to a given point position?

      I would like to be able to specify a position in space and get the nearest position on the surface of a polygon object.

      Thanks & greetings,
      Frank

      www.frankwilleke.de
      Only asking personal code questions here.

      1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand
        last edited by ferdinand

        Hi,

        I am not quite sure what you would consider handy, but the C++ API exposes a KD-Tree type. Read its manual here. The closest point lies then on one of the polygons associated with that vertex. One way to calculate it, could be to calculate the orthogonal projection of the point onto the plane of the polygon, convert that result into barycentric coordinates of that polygon and then zero out any component, that is smaller than zero.

        Cheers
        zipit

        MAXON SDK Specialist
        developers.maxon.net

        1 Reply Last reply Reply Quote 0
        • fwilleke80F
          fwilleke80
          last edited by

          Right, that would be a way, thanks.

          I was hoping to be able to do it in Python for now, because it makes prototyping so much easier. Just to see if my idea is working at all. But since it's a shader project, I'd have to move to C++ anyway, for performance reasons.

          I guess I'll try that.

          www.frankwilleke.de
          Only asking personal code questions here.

          ferdinandF 1 Reply Last reply Reply Quote 0
          • ferdinandF
            ferdinand @fwilleke80
            last edited by

            @fwilleke80 said in Find nearest position on a geometry:

            Right, that would be a way, thanks.

            I was hoping to be able to do it in Python for now, because it makes prototyping so much easier. Just to see if my idea is working at all. But since it's a shader project, I'd have to move to C++ anyway, for performance reasons.

            I guess I'll try that.

            You do not have to tell me that 😉 Not a big fan of C++ here 😉

            MAXON SDK Specialist
            developers.maxon.net

            1 Reply Last reply Reply Quote 0
            • fwilleke80F
              fwilleke80
              last edited by

              I personally love C++ and wouldn't change my main programming language to anything else. But I have to admit that Python is quite handy for quick prototyping (though the missing debugging capabilities in Cinema really suck for bigger Python projects).

              www.frankwilleke.de
              Only asking personal code questions here.

              1 Reply Last reply Reply Quote 0
              • r_giganteR
                r_gigante
                last edited by

                Hi Frank, thanks for reaching out us.

                With regard to your request, aside from confirming that nothing comes with Python API for obvious performance reasons, in C++ the nearest thing you can find is KDtree - as already pointed out by @zipit - or other similar accelerating structures.
                On top of these notes, I would consider this topic more a general programming / algorithm-related topic which could find, based on the contour conditions, different "better" solutions.

                Best, R

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