Rotation & angle of universal joint?


RE: Rotation & angle of universal joint?
#5
(2019-10-02, 3:36)N. W. Perry Wrote: Since I got such quick and helpful advice on my piston rod question, here is my next challenge: universal joints!

I don't have the time to go in to details at the moment, but you might want to look at my 8860 animation script (included in LDCad's examples).

It does realtime frame depended universal placements.

Code section of interest:

Code:
    --The universal joints are a bit tricky and need some rotation matrix 'magic'.
    -- As there are two of them a function can be used to apply things on both of them.
    -- This uses the source's known local X and Z axis' to construct the link's orientation by using the also known destination Z-axis (axle length direction).
    -- The orientation of the destination can then be constructed based upon the link's orientation.
    -- We don't have to worry about positions in absolute model space as the aniTools joint mechanics will take care of that.
    local function calcUniAxle(fromAxleOri, dstAxleZ, linkPosOri, dstAxlePosOri)

      --link
      local jntX=fromAxleOri:getOriRow(1)
      local jntZ=fromAxleOri:getOriRow(3)
      local jAngle=jntX:getSignedAngle(dstAxleZ, jntZ)

      local ori=ldc.matrix()
      ori:setRotate(jAngle, jntX)
      jntZ:transform(ori)

      local jntY=jntZ:getCross(jntX)
      ori:setOriRows(jntX, jntY, jntZ)
      ori:mulAB(fromAxleOri:getInvertedOri())
      linkPosOri:set(ori)

      --dst
      jAngle=jntY:getSignedAngle(dstAxleZ, jntZ)
      ori:setRotate(jAngle, jntY)
      jntZ:transform(ori)
      jntX=jntY:getCross(jntZ)
      dstAxlePosOri:setIdentity()
      dstAxlePosOri:setOriRows(jntX, jntY, jntZ)
    end

    local z=self.axle1Joint.orgAbsPosOri:getPos()-self.axle3Joint.orgAbsPosOri:getPos()
    calcUniAxle(self.axle3PosOri.value, z, self.axleJnt2PosOri.value, self.axle2PosOri.value)

    z=self.axle1Joint.obj:getOri():getOriRow(3)
    calcUniAxle(self.axle2PosOri.value, z, self.axleJnt1PosOri.value, self.axle1PosOri.value)
Reply
« Next Oldest | Next Newest »



Messages In This Thread
RE: Rotation & angle of universal joint? - by Roland Melkert - 2019-10-02, 18:17

Forum Jump:


Users browsing this thread: 2 Guest(s)