Author Topic: How to create a proper solid sphere? [Solved]  (Read 1284 times)

How would I create a sphere in 4x4 cubes (using 2 positions) properly? Could I get an example of two functions which one is using x y and z and the other one using sine, cosine and two other ones in a loop?
« Last Edit: February 17, 2017, 07:16:08 PM by Kyuande »

do you want to create it client or server side? (building with bricks + super shift or just place with console)
and which part of the brick must be inside the sphere to be placed, any part, the center, or fully enclosed?

edit:
this is what I used to use to build the top half of spheres
Code: [Select]
function sphere(%diameter)
{
%a = 0;
if(!(%diameter % 2))
%a += 0.5;
for(%z = 0; %z < %diameter / 2; %z++)
{
for(%y = %diameter / -2; %y < %diameter / 2; %y++)
{
for(%x = %diameter / -2; %x < %diameter / 2; %x++)
{
if(mSqrt(mPow(%x + %a, 2) + mPow(%y + %a, 2) + mPow(%z + %a, 2)) <= %diameter / 2)
commandtoserver('plantbrick');
commandtoserver('supershiftbrick', 0, -1, 0);
}
commandtoserver('supershiftbrick', -1, %diameter, 0);
}
commandtoserver('supershiftbrick', %diameter, 0, 1);
}
commandtoserver('supershiftbrick', 0, 0, %diameter / 2);
}

Oh yeah, I wanted to do this server side with creating bricks. I have a function to easily create the brick just want to know how to create a sphere with them. I would like to have it fully enclosed

do you just want the edges or to be completely filled?

Completely filled. I am trying to do this for a mining server but unfortunately it lags pretty bad the larger the area is. I'm currently using search containers but that lags after hitting over 100k bricks.

in that case you may want to delay the placements of the bricks
Code: [Select]
function sphere(%diameter)
{
%delay = 0;
%a = 0;
if(!(%diameter % 2))
%a += 0.5;
%radius = %diameter / 2;
for(%z = %radius * -1; %z < %radius; %z++)
for(%y = %radius * -1; %y < %radius; %y++)
for(%x = %radius * -1; %x < %radius; %x++)
if(mSqrt(mPow(%x + %a, 2) + mPow(%y + %a, 2) + mPow(%z + %a, 2)) <= %radius)
schedule((%delay++) * 33, 0, placeBrick, %x, %y, %z); //forgot how to pass args in schedule, have fun with that
}

function placeBrick(%x, %y, %z)
{
//you get to do this part
}

something along those lines should work
it does loop in empty areas needlessly, but that shouldn't lag the server, placing bricks will slow things down a ton

This is waay better than the 2 methods I have been trying.

Yeah I put some checks to see if it already tried that position. Thank you so much.