How to Generate Perfect Circles for Minecraft Builds in MATLAB

34 views (last 30 days)
Gloria on 15 Jan 2024
Edited: Florian Bidaud on 15 Jan 2024
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:
if round(sqrt(x^2 + y^2)) == radius
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:
1. 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.
2. 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.

Florian Bidaud on 15 Jan 2024
Edited: Florian Bidaud on 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])
end
end