# Calculate vector position

I'm trying to calculate & move vertices to their average "radius" and form a circle from these new positions.

Example: I have 8 vertices selected, I have a little script in Maya that will iterate through each point, find the distance from the center of the selection to the current point in the loop. It saves these values and creates an "average distance from the center" value. • Black = Each vertex position (X,Y,Z)
• Red = Distance between center and vertex
• Blue = Average of ALL verts from the Centerpoint (X,Y,Z) & Vertex (X,Y,Z) = integerXYZ (blue is the same distance)
• Green is the position I'm trying to find in (XYZ)

I can't figure out how to calculate the (X,Y,Z) coordinates of the green dot!

I have calculated this information with: (up to the position of the green points):

import maya.cmds as cmds
import math
sel = cmds.ls(sl=1, fl=1)
averageDistance = 0
cmds.setToolTo('Move')
oldCoordArray = []
oldDistanceArray = []
newXPos = 0
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)
print vts
x = round(float(cs),2) - round(float(vts),2)
y = round(float(cs),2) - round(float(vts),2)
z = round(float(cs),2) - round(float(vts),2)
distanceFromCenter = math.sqrt((x * x) + (y * y) + (z * z))
oldCoordArray += [(round(float(vts),2),round(float(vts),2),round(float(vts),2))]
oldDistanceArray += [(distanceFromCenter)]
averageDistance += distanceFromCenter
if (i == len(sel) -1):
averageDistance /= len(sel)
print 'average Distance: %s' %averageDistance
for i in range(0, len(sel), 1):
#Calculate percentage difference between distances
t = oldDistanceArray[i] * 100 / averageDistance
percDiff = (t / 100) * oldCoordArray[i]
newXPos -= (oldCoordArray[i] / percDiff) * 100


(original image here)

• And what is your question? – copper.hat Mar 5 '13 at 3:22
• I can't calculate the X,Y,Z coordinates of the green dot basically! – Shannon Hochkins Mar 5 '13 at 3:23
• Oh crap. This is 3D, and I did 2D in an earlier answer I'll remove right after this comment. For 3D, you should consider using polar coordinates. If 2D is of any help, let me know, and I'll undelete my 2D answer that is fully written. – gnometorule Mar 5 '13 at 4:16

## 1 Answer

If I understand, you have looped through the eight points $(X_i,Y_i,Z_i)$and averaged the $X,Y,Z$ coordinates to find the red coordinates, 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}$. If you just average all the $d_i$ the blue segments will extend past the nearer points. It is not clear to me how you choose the blue length $b$. But however you do it, the coordinates of the green points $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)$

• How would this return 3 coordinates? (X,Y,Z) I'm not quite following sorry – Shannon Hochkins Mar 5 '13 at 4:36
• If it helps, I have updated my question with my current python code. – Shannon Hochkins Mar 5 '13 at 4:39
• @ShannonHochkins: there are three coordinates shown. The $X$ one is $\frac b{d_i}(X_i-X_c)+X_c$ – Ross Millikan Mar 5 '13 at 4:39
• Oh i didn't even notice the "," You're not able to take a quick look at my python code and explain how I might implement it would you? – Shannon Hochkins Mar 5 '13 at 4:40
• is the 'b' the "blue" distance?? – Shannon Hochkins Mar 5 '13 at 4:41