#How do I fill spheres?

1 messages · Page 1 of 1 (latest)

tiny heart
#

How do I spawn spheres of any radius

marsh sequoia
#

Look online and find a sphere calculating formula. I can explain the math but basically you just use some basic trig to generate a number of points that fall into a sphere with an input radius.

Then that will return a pile of location vectors which you can set to your desired block type with an offset.

tiny heart
#

How do I generate that list of blocks?

native patio
#

Use this ig

function sphere(center, radius, hollow = false) {
    const points = [];
    const rSq = radius * radius;
    const innerSq = (radius - 1) * (radius - 1);

    for (let x = Math.floor(center.x - radius); x <= Math.ceil(center.x + radius); x++) {
        for (let y = Math.floor(center.y - radius); y <= Math.ceil(center.y + radius); y++) {
            for (let z = Math.floor(center.z - radius); z <= Math.ceil(center.z + radius); z++) {
                const dx = x - center.x;
                const dy = y - center.y;
                const dz = z - center.z;
                const distSq = dx * dx + dy * dy + dz * dz;

                if (distSq <= rSq && (!hollow || distSq >= innerSq)) {
                    points.push({ x, y, z });
                }
            }
        }
    }

    return points;
}
native patio
#

wdym, its mine lol.

tiny heart
#

Thanks

native patio
#

np

proud crest