# Finding Radius or Scale from Mesh Vertices Data

I am having trouble visualizing how the vertices relate to quantitative aspects of the geometry of the sphere or object it defines (such as radius, localscale, world coordinates, etc) @ http://unity3d.com/support/documentation/ScriptReference/Mesh.html.

Here is the snippet from the manual:

function Update () {
var mesh : Mesh = GetComponent(MeshFilter).mesh;
var vertices : Vector3[] = mesh.vertices;
var normals : Vector3[] = mesh.normals;

for (var i = 0; i < vertices.Length; i++)
vertices += normals _* Mathf.Sin(Time.time);_
_*mesh.vertices = vertices;*_
_*}*_
_*
*_

I understand that this is applying a sinusoidal transformation on the sphere (or other object that itâ€™s in). Basically, the object would start at whatever its preset scale is, and then get bigger, and back to the same size again, etc. It would be nice if Unity Inspector could track the instantaneous radius of this procedural manipuulation, but it seems to only track the actual localScale of the sphere, rather than the new scale created by vertices.

How do you track the radius or world coordinate dimensions of a shape given only vertices, like in the example above?

From geometry, I have an idea of how to do this, but it is very expensive in terms of computation - basically collide a plane with the sphere (crossing origin), and the intersection will be the instantaneous circle and fetch the radius from circumference c = 2 \pi r - is there a more direct way to get these quantities from vertices?

It would be nice if Unity Inspector could track the instantaneous radius of this procedural manipuulation, but it seems to only track the actual localScale of the sphere, rather than the new scale created by vertices.

You're confusing scale with mesh geometry. The local scale of a game object is completely separate from any geometry associated with it or with the bounds of that geometry, so there's no reason that the former should reflect the latter.

What it sounds like you're looking for is the bounds of the mesh geometry itself. If you need that information, the Mesh class has a function (IIRC) that will recompute the bounds given the current state of the geometry. If you call this function after changing the vertex positions, the bounds should then reflect the updated positions. (There may be some expense involved in recomputing the bounds frequently, but you'll probably just have to factor that in.)

Unity represents the bounds using a box, I think. You can derive a bounding sphere from this box, but if you need a more optimal bounding sphere, you may have to compute it yourself. Computing an approximate bounding sphere is pretty straightforward; computing an optimal or near-optimal bounding sphere isn't necessarily as straightforward. In either case though, it shouldn't require an intersection test (like you described in your post).