QPoint overlap
-
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?@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.
-
These are not two points but two circles. You asked about two points being the same. So what's your real question?
-
These are not two points but two circles. You asked about two points being the same. So what's your real question?
@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.
-
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) -
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)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).
