I would like to implement a program where OpenGL cuts the figure in a straight line drawn by the mouse.
The OpenGL version is 4.6, but I'm studying a tutorial based on ver1.1 here (http://wisdom.sakura.ne.jp/system/opengl/).
We assume that the initial situation in which the user did nothing is that there is only one white figure drawn in a black background.A line segment drawn by a user by a mouse is repeatedly cut, and each figure is separated a little so as to be easy to see, so as not to overlap.I'd like to implement this.
I am thinking of implementing this by following these steps:
1. First, the point where the left click is pressed is acquired as the starting point of the line segment, and then the point where the left click is released is acquired as the ending point of the line segment.
2. If the starting point and the ending point of the line segment are outside the figure, and the line segment intersects the figure, and the number of the line segment increases due to the cut by the line segment, the figure is cut.A plurality of cases may be cut at once.In the figure, the doughnut does not meet the condition that the number of figures increases.
3. Make sure that the distance between the nearest two figures is equal to or greater than the constant c (more formally, min d(p,q)>=c is established for points p of figure A and q of figure B that are closed)
I tried to implement an algorithm to do this, but I couldn't think of the right one.
Step 2 does not understand the part of dividing a figure by a line segment and the algorithm for determining that the figure does not increase (only when the line segment crosses the figure but does not increase).
In step 3, I don't know how to find the distance between the nearest parts of the two figures, and in a simple implementation, I have to find the distance between all two pairs of figures, which makes me feel useless.Also, even if the distance between two pairs of figures is properly released, the distance from the other figures may be within c.
I would appreciate it if you could tell me the algorithms that can implement them properly.
As for step 3, it seems unnecessary to take a policy of keeping the distance above c as long as you know that the figures are not duplicated and the figures are cut and separated.
I would like to change the policy especially in step 3, but I would appreciate it if you could let me know if there is anyone who knows a better policy for other procedures.
algorithm opengl
About Step 2 (with or without splitting):
Simply put, if you look at it in terms of image processing, you can make a decision by drawing a line and then labeling it.
Here, you may not be interested in the inside of the figure, so it seems that similar decisions can be made by "following the outline."
(Graphs are divided = contours of the figure are divided into several loops)
About Step 3 (Graphics Placement):
As an idea that seems easy to process, would you consider the circumscribed circle group of each figure and adjust it like a bun?
(To secure space between figures, for example, increase the radius of each circle by about c/2.)
© 2024 OneMinuteCode. All rights reserved.