1
$\begingroup$

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.

enter image description here

  • 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[0]),2) - round(float(vts[0]),2)
    y = round(float(cs[1]),2) - round(float(vts[1]),2)
    z = round(float(cs[2]),2) - round(float(vts[2]),2)
    distanceFromCenter = math.sqrt((x * x) + (y * y) + (z * z))
    oldCoordArray += [(round(float(vts[0]),2),round(float(vts[1]),2),round(float(vts[2]),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][0]
            newXPos -= (oldCoordArray[i][0] / percDiff) * 100     

(original image here)

$\endgroup$
  • $\begingroup$ And what is your question? $\endgroup$ – copper.hat Mar 5 '13 at 3:22
  • $\begingroup$ I can't calculate the X,Y,Z coordinates of the green dot basically! $\endgroup$ – Shannon Hochkins Mar 5 '13 at 3:23
  • $\begingroup$ 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. $\endgroup$ – gnometorule Mar 5 '13 at 4:16
1
$\begingroup$

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)$

$\endgroup$
  • $\begingroup$ How would this return 3 coordinates? (X,Y,Z) I'm not quite following sorry $\endgroup$ – Shannon Hochkins Mar 5 '13 at 4:36
  • $\begingroup$ If it helps, I have updated my question with my current python code. $\endgroup$ – Shannon Hochkins Mar 5 '13 at 4:39
  • $\begingroup$ @ShannonHochkins: there are three coordinates shown. The $X$ one is $\frac b{d_i}(X_i-X_c)+X_c$ $\endgroup$ – Ross Millikan Mar 5 '13 at 4:39
  • $\begingroup$ 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? $\endgroup$ – Shannon Hochkins Mar 5 '13 at 4:40
  • $\begingroup$ is the 'b' the "blue" distance?? $\endgroup$ – Shannon Hochkins Mar 5 '13 at 4:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.