I'm using the following formula to calculate the new vector positions for each point selected, I loop through each point selected and get the $(X\_i,Y\_i,Z\_i)$ values, I also get the center values of the selection ($X,Y,Z$) , call them $(X\_c,Y\_c,Z\_c)$ The distance of each point from the center is $d\_i=\sqrt{(X\_i-X\_c)^2+(Y\_i-Y\_c)^2+(Z\_i-Z\_c)^2}$.

The coordinates for the new vector position is:

$g\_i=\left(\frac b{d\_i}(X\_i-X\_c)+X\_c,\frac b{d\_i}(Y\_i-Y\_c)+Y\_c,\frac b{d\_i}(Z\_i-Z\_c)+Z\_c\right)$

My problem is I don't think it's averaging properly, it should be a smooth path or an average path the whole way from every axis.

Here's a screen shot before I run the script:
![enter image description here](https://i.stack.imgur.com/XK6N5.jpg)

And here is what happens after:
![enter image description here](https://i.stack.imgur.com/82MAP.jpg)

It's perfect on the front axis, but as you can see from the top and the side it's not so smooth.

I'm using Python in MAYA to calculate this, here's the code I'm using:

```
import maya.cmds as cmds
import math
sel = cmds.ls(sl=1, fl=1)
averageDistance = 0
cmds.setToolTo('Move')
oldDistanceArray = []
cs = cmds.manipMoveContext("Move", q=1, p=1)
for i in range(0, len(sel), 1):
    vts = cmds.xform(sel[i],q=1,ws=1,t=1)
    x = cs[0] - vts[0]
    y = cs[1] - vts[1]
    z = cs[2] - vts[2]
    distanceFromCenter = math.sqrt(pow(x,2) + pow(y,2) + pow(z,2))
    oldDistanceArray += [(distanceFromCenter)]
    averageDistance += distanceFromCenter    
    if (i == len(sel) -1):
        averageDistance /= len(sel)
        for j in range(0, len(sel), 1):
            vts = cmds.xform(sel[j],q=1,ws=1,t=1)            
            gx = (((averageDistance / oldDistanceArray[j]) * (vts[0] -  cs[0])) + cs[0])
            gy = (((averageDistance / oldDistanceArray[j]) * (vts[1] -  cs[1])) + cs[1])
            gz = (((averageDistance / oldDistanceArray[j]) * (vts[2] -  cs[2])) + cs[2])
            cmds.move(gx,gy,gz,sel[j])
            cmds.refresh()

```

Aditionally, I have found another 'error' here: (before)

![enter image description here](https://i.stack.imgur.com/s5SLJ.jpg)

After: ![enter image description here](https://i.stack.imgur.com/wkMid.jpg)

It should draw a perfect circle, but it seems my algorithm is wrong