Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QPoint overlap
Qt 6.12 LTS is out! See what's new in the release blog

QPoint overlap

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 4 Posters 1.5k Views 2 Watching
  • 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.
  • D Offline
    D Offline
    Davide00
    wrote on last edited by
    #1

    Hi, i have a question.
    I have a function that creates many QPoint with random coordinates. My question is, how can i prevent that they overlap?

    JKSHJ 1 Reply Last reply
    0
    • D Davide00

      Hi, i have a question.
      I have a function that creates many QPoint with random coordinates. My question is, how can i prevent that they overlap?

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      @Davide00 said in QPoint overlap:

      how can i prevent that they overlap?

      Put all your points in a QSet (or a std::set). This will ensure that there are no duplicates.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      2
      • D Offline
        D Offline
        Davide00
        wrote on last edited by
        #3

        Maybe i explained not in the best way, i already have a function that checks if 2 QPoint have the same centre, what i wanto to avoid is a situation like the one in the figureintersec.jpg

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by Christian Ehrlicher
          #4

          These are not two points but two circles. You asked about two points being the same. So what's your real question?

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          D 1 Reply Last reply
          2
          • Christian EhrlicherC Christian Ehrlicher

            These are not two points but two circles. You asked about two points being the same. So what's your real question?

            D Offline
            D Offline
            Davide00
            wrote on last edited by
            #5

            @Christian-Ehrlicher ok let me explain better. My function (namend very surprisingly paint() ) creates randomly a QPoint and then draws a circle of radius 5 with the center in the QPoint. I want to avoid the situation described in the figure.

            1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Then rember all your points and check if your new circle is not inside another circle - simple math.

              vector = Point1 - Point2
              distance = sqrt(vector.x * vector.x + vector.y * vector.y)

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              M 1 Reply Last reply
              2
              • Christian EhrlicherC Christian Ehrlicher

                Then rember all your points and check if your new circle is not inside another circle - simple math.

                vector = Point1 - Point2
                distance = sqrt(vector.x * vector.x + vector.y * vector.y)

                M Offline
                M Offline
                mchinand
                wrote on last edited by
                #7

                To add to what @Christian-Ehrlicher wrote, you have to check that the distance between a new point (center of circle) and every other point (circle centers) is greater than 2*radius (assuming they all have the same radius).

                1 Reply Last reply
                1

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt
                • Unsolved