Implicit representation of a sphere and cube on a regular grid

mayo 4, 2010


void MakeSphere(Grid &grid, Double h, const Vector &pos, Double radius)
{
FOR_ALL
grid[INDEX(i,j,k)] =((pos-Vector(i,j,k)).Length()-radius) *h;
END_THREE
}


void MakeCube(Grid &init, Double h, const Vector &pos1, const Vector &pos2)
{
FOR_ALL_LS
//Find Nearest Point
Vector Nearest;
Nearest[0] = Clamp((Float)i,pos1[0],pos2[0]);
Nearest[1] = Clamp((Float)j,pos1[1],pos2[1]);
Nearest[2] = Clamp((Float)k,pos1[2],pos2[2]);
if(Nearest[0]==i&&Nearest[1]==j&&Nearest[2]==k){ //inside
Double d1 = min(abs(i-pos1[0]),abs(i-pos2[0]));
Double d2 = min(abs(j-pos1[1]),abs(j-pos2[1]));
Double d3 = min(abs(k-pos1[2]),abs(k-pos2[2]));
init(i,j,k) = -min(d1,min(d2,d3))* h;
}else{ //outside
init(i,j,k) = (Nearest-Vector(i,j,k)).Length()* h;
}
END_FOR_THREE
}

Advertisement

Deja un comentario

Fill in your details below or click an icon to log in:

Logo de WordPress.com

You are commenting using your WordPress.com account. Log Out / Cambiar )

Twitter picture

You are commenting using your Twitter account. Log Out / Cambiar )

Facebook photo

You are commenting using your Facebook account. Log Out / Cambiar )

Connecting to %s

Seguir

Get every new post delivered to your Inbox.