Rigging

Rigging101 » Rigging128

Querry a joint's rotation (10 posts)

About This Topic

Tags

No tags yet.

  1. Mark Neil

    offline
    Member
    Posted 6 years ago
    #

    I'm trying to Query a joint's Y rotation relative to world space for a script I'm writing, but I can't seem to figure out the proper method (I thought it was xform, but that's not working right...)

    To get an idea of what I mean, see the attached image compared to my expected results. In it, there are two joints/bones that I seek to get data on (for this example). the results I would expect to get from my query would be

    For the left/Upper joint, I would expect 45, 0, 0

    For the right/lower joint, I'd expect 45, 30ish, 0

    http://markneil.ca/ShareFiles/Jointorient.JPG

    Is there any way to query and get the results I'm looking for?

    xform -q -ws -ro has been giving me odd results that aren't usable (even on new joints that should have 0 Y and Z world rotations).

    (as to my reasons, I am trying to create a script that will produce the no flip knee from "The Art of Rigging", and I need a way to determine the starting Y rotation (relative to worldspace) in order to subtract from 90 in order to get the starting IK Twist/offSet value. Any help would be appreciated.)

    Thank you in advance.

  2. PixL

    offline
    Member
    Posted 6 years ago
    #

    Do you want to query the joint orientation (rather than rotation)?:
    # Get Joint Orientation
    sel = cmds.ls (sl=1)
    jo = cmds.getAttr (sel[0]+'.jointOrient') # Will get all 3 values
    print jo
    joX = cmds.getAttr (sel[0]+'.jointOrientX')
    print joX

  3. Mark Neil

    offline
    Member
    Posted 6 years ago
    #

    Thanks PixL. Unfortunately, that isn't working (doesn't return the values I'm looking for. Plus having a parent joint that has rotations alters the values, even is the joint itself hasn't moved.).

    I'm not even sure if what I'm after is even possible. I'm after the angle the joint is offset relative to the worlds Z axis (or x Axis, ether works for me) when viewed top down, regardless of the joints other transformations and any parent's transformations. As marked by the red lines/angle/compass in the bellow image.

    http://markneil.ca/ShareFiles/Angle.JPG

    As I said, not even sure if it's possible (there may be a reason the book doesn't provide a script for it after all), but it would be helpful.

  4. mzahmbie

    offline
    Member
    Posted 6 years ago
    #

    Hey Mark, do you need to query that angle just once so you know the initial value or does the script need to keep a watch at that angle as it changes?

    I'm not sure there's a quick query command to find that angle, but if you just need to query it once you can do some quick vector math to find it. You'd essentially make a ground plane projection of the joint chain (take 2 locators, and snap them on the x and z translation axis so that when viewed from the top the 2 locators sit perfectly in line with the joints, except on the ground plane.). So for the example of the Angle.JPG picture you'd then find the angle of (0,0,1) which is a vector pointing along the Z axis like the vertical line, and then find the vector between the 2 locators for the diagonal and get the angle between them for your world offset angle.

    I'm not sure how clear I made that, but I'm happy to explain in more detail if that sounds like it would solve the issue for you.

  5. Mark Neil

    offline
    Member
    Posted 6 years ago
    #

    I just need it once (per leg) in order to set a starting point (Art of rigging no flip knee adjusts the 3 pole vectors of the leg IK. The adjustments rotate the leg and I need this angle to correct that rotation, and reposition the leg back to it's starting point, by setting the twist).

    I do understand what you're suggesting. I was considering that method as well, but I'm not sure on the math to find that angle. I'd appreciate any help.

  6. mzahmbie

    offline
    Member
    Posted 6 years ago
    #

    That makes things a good amount easier So here goes.

    locatorA will be the point at the base of the joint chain, locatorB the point at the tip of the joint chain. I'll go off the grid and axis in your picture, so locatorA is at (1,0,0) and locatorB is at (4,0,5).

    VectorAB, meaning the vector starting at locatorA and going to locatorB is locatorB-locatorA.
    VectorAB = (4,0,5) - (1,0,0) = (3,0,5)

    The zero vector, which would be the vertical line in the image is (0,0,x) x being any number, we normalize it later so it doesn't matter, but to keep the example simple we'll go with how long it's drawn in the picture.
    ZeroVector = (0,0,4)

    The angle between 2 vectors is defined as 'angle = acos(vector1 dot vector2)' I don't have a good symbol for the dot but it'll do to stand for dot product. And with both vectors normalized. So first we need to normalize the vectors, which gives us a vector going in the same direction, but with a length of 1 unit. We're doing this because the acos needs a number between 0 and 1.

    A normalized vector is just a vector divided by it's length. length being sqrt( x*x + y*y + z*z )

    VectorAB_normalized = VectorAB / sqrt( 3*3 + 0*0 + 5*5 ) = VectorAB / sqrt( 34 ) = VectorAB / 5.8309518948453 = ( 0.514, 0, 0.857 )

    ZeroVector_normalized = ( 0, 0, 1 )

    a dot product is ( v1x*v2x + v1y*v2y + v1z*v2z ) v1 being a vector, and v2 being another vector.

    VectorAB_normalized dot ZeroVector_normalized = ( 0.514*0 + 0*0 + .857*1 ) = 0.857

    And we finaly come to acos( 0.857 ) = 31.0186 which is pretty close to your estimate of 30ish

    And there we have it. Plug in your own numbers for any joint chain and you've got the angle you're looking for. I hope this helps!

  7. Javier "Goosh" Solsona (admin)

    offline
    Key Master
    Posted 6 years ago
    #

    aahhh... math

  8. Javier "Goosh" Solsona (admin)

    offline
    Key Master
    Posted 6 years ago
    #

    Oh.. btw.. if the joints don't change length, you could use trigonometry too

  9. mzahmbie

    offline
    Member
    Posted 6 years ago
    #

    Ahhh yeah, trig would probably make that problem a good bit simpler. You can find the length of all 3 sides of a triangle made up of your 2 lines(3 points), and you could even use the measure dist tool to give you the lengths to avoid the vector math to find it.

    Me and trig have never gotten along though, it makes me default off to vectors instead

  10. Mark Neil

    offline
    Member
    Posted 6 years ago
    #

    Thanks a lot guys. I'll try to incorporate this asap (Just started a new job, so may take me a few days. I might be back, but don't think so, this looks helpful.)

Reply

You must log in to post.

Rigging101 » Rigging128
1,099 posts in 307 topics over 110 months by 188 of 8,226 members. Latest: fashionpvp, d2q4p5z2j, gasheldonl