How to Generate Perfect Circles for Minecraft Builds in MATLAB
17 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello MATLAB Community,
I am currently working on a project related to Minecraft, where I need to create perfect circles as a guide for building structures within the game. Given the blocky nature of Minecraft, creating smooth circles can be challenging. I am looking to utilize MATLAB to generate these circle templates.
My goal is to create a MATLAB script that can output a matrix representing a circle, where the matrix elements indicate whether a block should be placed at that position (1 for a block, 0 for no block). This output can then be used as a guide for building the circles in Minecraft.
Here's what I have tried so far:
function circleMatrix = generateMinecraftCircle(radius)
circleMatrix = zeros(2*radius+1, 2*radius+1);
for x = -radius:radius
for y = -radius:radius
if round(sqrt(x^2 + y^2)) == radius
circleMatrix(x+radius+1, y+radius+1) = 1;
end
end
end
end
This function takes a radius as input and is supposed to output a matrix with ones representing the circle's perimeter. However, I am facing some issues:
- The circles generated are not as smooth as I would like. They often have jagged edges which don't look great in Minecraft. I'm aiming for a level of smoothness similar to what's achieved by online tools like the Minecraft Circle Generator https://minecraftcirclegenerate.com/, but I'm struggling to replicate this in MATLAB.
- I am unsure how to optimize this code for larger circles as it gets quite slow.
I would greatly appreciate any suggestions for improving the circle's smoothness and the efficiency of the code. Also, if there's a better approach to achieving this in MATLAB, I am open to trying new methods.
Thank you for your help!
0 commentaires
Réponses (1)
Florian Bidaud
le 15 Jan 2024
Modifié(e) : Florian Bidaud
le 15 Jan 2024
You need a bit more resolution in your circle, and I would go for finding the minimum of the equation rather than rounding the result. However, I am not familiar with minecraft, I am not sure that you can split the radius and the resolution as I just did as you might be limited be the number of squares if you really want a explicit radius rather than a shape.
resolution = 10; % Higher resolution
circleMatrix = generateMinecraftCircle(10,resolution);
[r,c] = find(circleMatrix);
scatter(c/resolution,r/resolution)
xlim([0 20])
ylim([0 20])
resolution = 1; % Lower resolution
circleMatrix = generateMinecraftCircle(10,resolution);
[r,c] = find(circleMatrix);
scatter(c/resolution,r/resolution)
xlim([0 20])
ylim([0 20])
function circleMatrix = generateMinecraftCircle(radius,resolution)
radius = resolution*radius;
circleMatrix = zeros(2*radius+1, 2*radius+1);
for x = -radius:radius
circleMatrix(x+radius+1,:) = abs(x^2 + (-radius:radius).^2-radius^2)==min(abs(x^2 + (-radius:radius).^2-radius^2));
end
end
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!