<p>The core calculation seems to be </p>

<pre><code>  sub_v3_v3v3(vec, td-&gt;iloc, tc-&gt;center_local);

  radius = normalize_v3(vec);

  tratio = ratio * td-&gt;factor;

  mul_v3_fl(vec, radius * (1.0f - tratio) + t-&gt;val * tratio);

  add_v3_v3v3(td-&gt;loc, tc-&gt;center_local, vec);
</code></pre>

<p>Which in C-ish psuedo code looks like</p>

<pre><code>vec = pos - center; //find vector from center to point
radius = length(vec); // get the length of the vector
vec = vec / radius;  //normalize the vector

tratio = ratio * individual_sensitivity; // adjust sensitivity per vertex 

vec = lerp(vec * radius, vec * t-&gt;val, tratio); //linearly interpolate between the original and where the point would be on the sphere

pos = center + vec; // store result
</code></pre>

<p>So the code projects the point to the sphere and linearly interpolates the point between the original location and the sphere location. </p>

CC BY-SA 4.0
2019-06-19T09:38:10.500Z
Ok, I will try this asap and mark as answer if it works; thanks a lot for the help in deciphering the code!
Jonathan H
CC BY-SA 4.0
2019-06-19T10:45:54.770Z
This only seems to work if the original surface is convex; if it is not, this creates "folds" in the resulting sphere, which effectively corrupts the neighbourhood information from the original mesh.
Jonathan H
CC BY-SA 4.0
2019-06-19T08:58:49.617Z
2019-06-19T08:58:49.617Z
ratchet freak
<p>I am after a simple (not necessarily efficient) algorithm to "continuously" transform a closed surface mesh into a sphere. </p>

<p>It seems that Blender is able to do this quite well: <a href="https://docs.blender.org/manual/en/latest/modeling/meshes/editing/transform/to_sphere.html" rel="nofollow noreferrer">https://docs.blender.org/manual/en/latest/modeling/meshes/editing/transform/to_sphere.html</a> </p>

<p>However I cannot find a reference, or technical description of the algorithm they use. I tried looking at <a href="https://github.com/sobotka/blender/blob/5767dcbe60c07cd9ef113e2f54eaad6981a47bce/source/blender/editors/transform/transform.c#L4168" rel="nofollow noreferrer">the code</a> but did not managed to figure out what it does unfortunately.</p>

<transformations><mesh>
Inflate 3D mesh into sphere
Jonathan H
# Inflate 3D mesh into sphere

(Asked by: username_0 on 2019-06-19)

I am after a simple (not necessarily efficient) algorithm to "continuously" transform a closed surface mesh into a sphere.

It seems that Blender is able to do this quite well: <https://docs.blender.org/manual/en/latest/modeling/meshes/editing/transform/to_sphere.html>

However I cannot find a reference, or technical description of the algorithm they use. I tried looking at [the code](https://github.com/sobotka/blender/blob/5767dcbe60c07cd9ef113e2f54eaad6981a47bce/source/blender/editors/transform/transform.c#L4168) but did not managed to figure out what it does unfortunately.

**Tags:** transformations, mesh


---

## 1 answers

### Answer by username_1 on 2019-06-19. Score: 2

The core calculation seems to be

```
  sub_v3_v3v3(vec, td->iloc, tc->center_local);

  radius = normalize_v3(vec);

  tratio = ratio * td->factor;

  mul_v3_fl(vec, radius * (1.0f - tratio) + t->val * tratio);

  add_v3_v3v3(td->loc, tc->center_local, vec);

```

Which in C-ish psuedo code looks like

```
vec = pos - center; //find vector from center to point
radius = length(vec); // get the length of the vector
vec = vec / radius;  //normalize the vector

tratio = ratio * individual_sensitivity; // adjust sensitivity per vertex 

vec = lerp(vec * radius, vec * t->val, tratio); //linearly interpolate between the original and where the point would be on the sphere

pos = center + vec; // store result

```

So the code projects the point to the sphere and linearly interpolates the point between the original location and the sphere location.

> **Comments:**
> **username_0**: Ok, I will try this asap and mark as answer if it works; thanks a lot for the help in deciphering the code!  
> **username_0**: This only seems to work if the original surface is convex; if it is not, this creates "folds" in the resulting sphere, which effectively corrupts the neighbourhood information from the original mesh.  

---

