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)