How can I know how many red circles got surrounded by the blue circles?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    I want to know how many red circles got surrounded by the blue circles, but I do not know how

  2. What is the issue?
    image

  3. What solutions have you tried so far?
    I cant find a post about this on devforum

I just need a solution on how to do this, you do not have to write an entire script about this. Thank you for replying!

Its pretty hard to achieve using roblox, because of engine limitations. I would recommend trying to use Region3, no more ideas.

1 Like

You should better elaborate your statement to get better help.
However, from the image you provided, I understand that you are trying to identify whether certain parts (red) are surrounded by other parts (blue).
And apparently, this will only happen in a 2D view (although you’re in 3D space), ie you don’t care about the Y axis, right?
In this case, it is first necessary to know: Will the blue parts be movable? That is, will the player be able to “close” a circle? Or will the blue parts always be static? Because if the blue parts don’t change, it’s easier to create logic.

1 Like

so the parts are clearly blue, are you colorblind?

I totally agree with this, but how exactly will this be possible from within the engine?

1 Like

Could you define “surrounded”? To me that would suggest finding red points enclosed by a region created by blue points.

If so, this is actually a relatively tricky problem mathematically.

The first thing you’d need to do would be to find the region itself. The only way I currently see you achieving this is using a kind of tree-like structure. Move from point to point based on magnitude from the previous point, storing each point in a list. The loop would end when the next point is a point already in the list. You could then back-track to find the point of the next lowest magnitude for each variation and so on.

Following each creation of a region you could then check if the red points lie within the region enclosed. There are a few methods you could use to do this. The best (mathematically) would probably be the Inside / Outside Problem. Alternatively you could do it procedurally, checking incrementally smaller regions surrounding the points. If you know how many red points there are you could have an ending clause for if all the red points are known to be enclosed.

The biggest issue with this kind of approach or similar is that it has at the very least an O(n^2) time complexity, meaning the computational power would go up very quickly.

Edit: The method I just listed is probably better, but I just realised you could probably just check if a red point lies on a line between two blue points. Then (again, depending on how you define “surrounded”) check if there are one or two blue points lying on either side.

This is actually probably the most computationally effective solution, since it doesn’t require you to build any regions.

1 Like