I am looking for algorithm name and could not identify which algorithm is it. My task is,
Given: 1.Size(Width,Height) of a parent container 2.Position (X,Y) and size(Width,Height) for a number of rectangular and square particles which cannot overlap each other and can fit inside the container
Task: Find the empty polygon points in either counter-clockwise or clockwise when the user clicks on an empty spot
What I have tried is,
1.I took a starting point around the empty spot
2.Start with left direction
3.I checked for nearest particle to the left side of the point's Y-axis and above the point's X-axis. If found add the right bottom point of the found particle (x,particle_Y+particle_Height) and turn downwards
4.get particle to the left of the point. If found add the left bottom point of the particle (particle_X.y) and continue left.
5.if left has reached zero find nearest downward particle and add the top left point (x,particle_Y) and continue right.
6.if there is an upward particle next to it, add the top left (x particle_Y) and continue up.
7.1f not found, another if: find the top particle adjacent to the point which ends farther but has next point in between, add the top right (particle_X+particle_Width,y) of the particle and continue up.
8.If none of the above, turn down and continue downward search.
My code
while ((islandCurrentX != islandStartX || islandCurrentY != islandStartY) && count < 500)
{
int tempIslandX = (islandCurrentX == -1 ? islandStartX : islandCurrentX);
int tempIslandY = (islandCurrentY == -1 ? islandStartY : islandCurrentY);
//break;
count++;
But if I follow this, after I reach bottom part of the empty part, it again goes counterclockwise rather than clockwise. What algorithm should I search the internet? One more thing, I looked for connected components algorithm which is for pixel wise datatable. But I have position and size datatable. If I convert it to pixel wise, my windows form (C#) will become slow during search. (need to search on each click). Thanks in advance
Thanks for spending your valuable times. I have made it by changing the successive directions after each movement. https://pastebin.com/dNrHFn5W
(starts with)
List<Point> points = new List<Point>();
DataRow[] drNearestTop = dtCurrentPattern.Select("Starting_Y+Image_Length<" + controlRelatedCoords.Y + " and Starting_X<=" + controlRelatedCoords.X + " and Starting_X+Image_Width>=" + controlRelatedCoords.X + "");
Regards