0

I'm working on a PyMEL script that allows the user to duplicate a selected object multiple times, using a CV curve and its points coordinates to transform & rotate each copy to a certain point in space. In order to achieve this, Im using the adjacent 2 points of each CV (control vertex) to determine the rotation for the object.

I have managed to retrieve the coordinates of the curve's CVs

#Add all points of the curve to the cvDict dictionary
int=0
cvDict={}
while int<selSize:
    pointName='point%s' % int
    coords= pointPosition ('%s.cv[%s]' % (obj,int), w=1)

    #Setup the key for the current point
    cvDict[pointName]={}

    #add coords to x,y,z subkeys to dict
    cvDict[pointName]['x']= coords[0]
    cvDict[pointName]['y']= coords[1]
    cvDict[pointName]['z']= coords[2]

    int += 1

Now the problem I'm having is figuring out how to get the angle for each CV. I stumbled upon the angleBetween() function:

http://download.autodesk.com/us/maya/2010help/CommandsPython/angleBetween.html

In theory, this should be my solution, since I could find the "middle vector" (not sure if that's the mathematical term) of each of the curve's CVs (using the adjacent CVs' coordinates to find a fourth point) and use the above mentioned function to determine how much I'd have to rotate the object using a reference vector, for example on the z axis.

At least theoretically - the issue is that the function only takes 1 set of coords for each vector and I have absolutely no Idea how to convert my point coords to that format (since I always have at least 2 sets of coordinates, one for each point).

Thanks.

gh057
  • 3
  • 5
  • This seems to be a mathematical question, but it is highly unclear to anyone who doesn't know PyMEL. What is a CV? You seem to use "CV" and "point" synonymously-- are they the same? What does this have to do with duplication of something? Are you trying to determine how to rotate something as it moves along a curve? – Beta Aug 11 '13 at 12:38
  • Ah, sorry. It's more of a Maya question, really. CV refers to the control vertices of the curve that's being queried (which is, essentially, a point in space). Im using the coords of each cv to transform a duplicated object to that cv - however I also want to rotate it so that it faces the proper direction. However, this is non-animated - the object would be duplicated once per cv, and moved and rotated to fit that cv. No animation happening, nor intended. I'll edit the post accordingly though, to make it clearer. – gh057 Aug 11 '13 at 13:34
  • All right, now how do you want to represent the rotation? I mean, do you want an angle and an axis, or a set of (explicitly defined) Euler angles, or what? – Beta Aug 11 '13 at 13:38
  • Also, essentially what I need to know is in the header - I have 2 points with coordinates, but I need to convert this into one set of corrdinates of a vector in Maya. That's basically what I need to know. – gh057 Aug 11 '13 at 13:40
  • Basically, I just need the rotation in worldspace, that I need to apply to the object, so that it faces the same direction as the vector I constructed. Im assuming angle & axis would be sufficient :S – gh057 Aug 11 '13 at 13:41
  • Yes, those are sufficient, but for arguments (i.e. input) you'll need more than the two adjacent points. Suppose I'm in Rome, facing North, standing on a magic carpet. The carpet carries me to Paris. Now which way am I facing? If it flew North over Venice and Innsbruck, gradually turning West, then I would arrive facing West. If it flew West over the Mediterranean and Corsica, gradually turning North, I would arrive facing East. Two points are insufficient; what you need is the **tangent to the curve**. – Beta Aug 11 '13 at 13:54
  • Hm. I think we're not on the same page or im not understanding what you mean. for each CV, Im using three points (the actual CV and the next and previous CV's coords). From the latter, I can construct a segment and find its midpoint. That midpoint can then be used to construct a third vector (which I would like the object to be rotated to). If I use a reference vector (i.e. any Axis), shouldnt I be able to properly rotate the object? I'll look into the tangents eitherway, maybe that makes it easier. – gh057 Aug 11 '13 at 15:56
  • Are you trying to simply duplicate a NURBS curve and mirror it? – Argiri Kotsaris Aug 11 '13 at 16:01
  • Not duplicating the curve but a seperate object :) I use the curve's CVs to transform and rotate the object, at least that's the plan. I should also point out that the curve is linear. – gh057 Aug 11 '13 at 16:14
  • @gh057 Let's take this to a [chat](http://chat.stackoverflow.com/rooms/35226/pymel). – Argiri Kotsaris Aug 11 '13 at 16:18
  • missing the rep for that :/ – gh057 Aug 11 '13 at 16:39
  • As far as this goes, you're just trying to grab a random object and and set the orientation to match the curve you have, why not just grab the world rotations of the curve and apply it to the object? – Argiri Kotsaris Aug 11 '13 at 16:43

2 Answers2

0

If you wanna go the long way and not grab the world transforms of the curve, definitely make use of pymel's datatypes module. It has everything that python's native math module does and a few others that are Maya specific. Also the math you would require to do this based on CVs can be found here.

Hope that puts you in the right direction.

Argiri Kotsaris
  • 492
  • 3
  • 7
  • Guys, I just realized I could as well use the midpoint of the 2 points adjacent to the CV im looking to rotate the object to to create a locator at that position, and aim constrain that object to the locator. ..which does exactly what I want. Thanks for the provided links tho, they were useful in their own way :) Thank you all for your patience! issue resolved! :D – gh057 Aug 11 '13 at 18:07
0

If you're going to skip the math, maybe you should just create a locator, path-animate it along the curve, and then sample the result. That would allow you to get completely continuous orientations along the curve. The midpoint-constraint method you've outlined above is limited to 1 valid sample per curve segment -- if you wanted 1/4 of the way or 3/4 of the way between two cv's your orientation would be off. Plus you don't have to reinvent all of the manu different options for deciding on the secondary axis of rotation, reading curves with funky parameterization, and so forth.

theodox
  • 12,028
  • 3
  • 23
  • 36