Okay, my two cents:
In your problem, I would try with a heavily modified Poisson-Disk-Sampling.
This method will first Poisson-Sample a Sector, and, after sampling enough Sectors, will sample a universe. This means the algorithm runs in two phases. This may be costintensive!
Some thoughts to it. Consider a Sector being a disk with radius
sec, and a System a disk with radius
How big have the radii to be too fullfill your criterias?
sys has to be at least
1.5. This way, if two disks are placed next to each other, the center-points of the two disks are
3.0 appart, your minimum distance. Additionally,
sys may not be larger than
5.0, otherwise Systems would be more than
So when generating your disks, you can evenly give them a
1.5 and allow gaps, or assign a randomvalue in the range of
5.0 to the discs. In the second case a newly placed disc should always touch at least one already existing disc to keep the Sector small.
sec is a bit more difficult to compute. What is the (approximate) minimal radius? Well, the minimal radius is achieved when all for systems in the sector are placed in a square with
1.5 for each System. This means that the minimal
sec is the diagonale between two Systems + a safety margin around the outermost Systems.
I happenend to draw a picture of this in paint:
I rounded a bit and came to the conclusion that the smallest possible
≈6.0. This is because the light-blue-lines count full, the diagonale (dark red) only counts half (as it goes through the center).
The computation of the maximum
sec proved to be very difficult, so I will only make assumptions here (though detailed ones in my opinion).
First: When we leave your second rule out, the maximum
4 + 10 + 10 + 10 + 4 = 38
This is your solution when you place all four Systems in one line. THIS IS OBVIOUSLY NOT THE DESIRED SOLUTION, as you could not guarantee that if you placed a similar Sector next to it, any System would have a non-Sector-System in range.
We can however make an assumption (which is just that, it does not have to be true). We can assume that the Systems are more or less evenly distributed. This means that if a System covers
50% of anothers Sectors Area, it will most likely have also a System from the other Sector in Range. Time to Math!
a*a + b*b = c*c
a = sec
b = sec + sec + (sec-4)
c = 20
sec^2 + (3*sec - 4)^2 = 20^2 ==> sec ≈ 7.5
As you can see, to nearly guarantee all conditions your
sec has to be in the range of
7.5. Pretty small Sectors, huh? If you weaken the conditions, your sectors will grow in size, but so will the average spacing between Non-Sector-Systems. Your call.
One note. This also limits the distance of a System from the Sector-Midpoint. Satisfying all conditions, a System is between
3.5 units away from the Midpoint. Use this in your calculations!
sys is in the range of
sec is in the range of
I must admit, I actually never generated a star field with this method, only draw a lot of circles on a lot of paper and it looked nice and stuff. The actual result can (and probably will) be ... interesting. You will have to play alot with
sec to produce nice looking results, but I hope I could help you.