Answers for "Confining Marching Cubes to the Radius of a Sphere"
http://answers.unity.com/questions/1466942/confining-marching-cubes-to-the-radius-of-a-sphere.html
The latest answers for the question "Confining Marching Cubes to the Radius of a Sphere"Answer by Bunny83
http://answers.unity.com/answers/1467164/view.html
Your xOrigin, yOrigin and zOrigin should not have any influence on the radius distance since it's a local coordinate vector. Your `Vector3(x,y,z)` is always a vector from the "world origin" up to (size,size,size).
<br>
What you actually want is a local space vector that doesn't go from (0,0,0) up to (size,size,size) but a vector that should have the range (-size/2f, -size/2f, -size/2f) up to (size/2f, size/2f, size/2f). So you just subtract half the size of each component. The resulting vector will be a relative vector from the center of your cube volume. The length of this vector should be compared against your desired radius. Since we just want to compare length we can use the squared length since it's easier to calculate:
float radius = size * 0.5f;
float sqrRadius = radius * radius;
for (int x = 0; x < size; x++) {
for (int y = 0; y < size; y++) {
for (int z = 0; z < size; z++) {
var v = new Vector3(x-radius, y-radius, z-radius);
if (v.sqrMagnitude > sqrRadius)
{
data[x, y, z] = -1;
continue;
}
// [ .. ]Sun, 11 Feb 2018 12:12:40 GMTBunny83