- Home /
Question by
grahnzz · Dec 13, 2013 at 11:06 PM ·
spheregenerationvoxelvoxelsmarching cubes
Generating scalar field for a sphere
The method I'm using now creates binary point values i.e. they are either empty or filled. I need a method for a smooth sphere.
public Vector3 center;
public float radius = 10.0f;
public float GetValue(float x,float y,float z)
{
float distance = Vector3.Distance(new Vector3(x,y,z),center);
if(distance < radius)
return -1.0f;
return 1.0f;
}
The value needs to be in the range of 1.0 to -1.0, 1.0 being full and -1.0 being empty.
Comment
Best Answer
Answer by robertbu · Dec 13, 2013 at 11:08 PM
I think this is what you are asking for:
if (distance >= radius) {
return 1.0f;
}
else {
return (distance / radius) * 2.0f - 1.0f;
}
Your answer
Follow this Question
Related Questions
Rounding edges of cubes (Voxels and Marching Cubes) 1 Answer
Voxel-Grid rounded Marching Cube values for a sphere 1 Answer
Cube made out of many voxels 0 Answers
How to remove small & thin triangles from a marching cubes voxel engine? 2 Answers
How can I smoothen my cubic mesh using marching cubes? 0 Answers