plot a square which has circles inside it

4 vues (au cours des 30 derniers jours)
BHAIRAVI
BHAIRAVI le 19 Jan 2024
i have a square of 1*1 and has a cicle whose diameter is 0.1 . i need to add as many circles as i can without overlappling semicircles are also allowed.
  3 commentaires
Sam Chak
Sam Chak le 19 Jan 2024
Can you sketch and at least show the code that plots a square?
Feel free to weave the 'stitching' concept from the plot() function to connect those coordinates.
plot([1 3], [2 4]), hold on
plot([3 5], [4 2]), hold off
grid on, xlabel x-cor, ylabel y-cor
John D'Errico
John D'Errico le 19 Jan 2024
This is just a variant of the circle packing problem, which is not trivially solved. If the circles may be partial circles, then you just use a hexagonal close-packed lattice to define the circle centers, and then there are infinitely many solutions, since you can translate that lattice anywhere.
If any partial circles may only be purely semi-circles, so only a half circle, then it would still seem you want to start with a hexagonal close-packed solution to start with, but now you might be able to fit in a few additional semi-circles around the perimeter, by perturbing the arrangement. This will be a difficlut task to perform optimally of course.

Connectez-vous pour commenter.

Réponses (1)

Image Analyst
Image Analyst le 19 Jan 2024
One way is to just have a matrix of (x,y) location of the centers that got placed. Then have a loop of, say, a million iterations - I doubt there would be a million circles in it. Then just loop over getting a prospective new (x,y). Then use the Pythagorean theorem (sqrt) to find the distances of that new circle to all the ones you've placed already
distances = sqrt((xNew - xPlaced) .^ 2 + (yNew - yPlaced) .^ 2);
Then use any or min to find out if any of those distances are less than twice the radius. If any are, then don't add that point and go on to try the next one. If you don't want partial circles, you can also check if the center plus the radius would put it outside your box if you want, and then don't add that circle.
This looks like a homework problem. If you have any questions ask your instructor or read the link below to get started:
Obviously we can't give you the full solution because you're not allowed to turn in our code as your own.
If it's not homework, say so, and if you really can't do it from my explanation, I can supply more code.

Catégories

En savoir plus sur Detection, Range and Doppler Estimation dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by