mathematical functions for scripting in LDCad


RE: mathematical functions for scripting in LDCad
#20
In my code were small errors. I corrected them and put it into a function for those who are interested in rotating parts around an arbitrary center.

If you perform multiple rotations to one part you should not use the orientation of the reference itself as shown in my last reply:
Code:
centerPartRel.transform(ref.getOri())
Therefore I introduces the 'indipendent orientation'.


So, here is the code:
Code:
function rotaround(refPart,centerRot,indOri,angle,rotVec)
    --refPart: refline object/group
    --centerRot: vector to rotation center
    --indOri: indipendent orientation matrix
    --angle: angle of rotation in degrees
    --rotVec: vector to rotate around
    local centerPartRel=refPart:getPos()-centerRot --relative position of part/group center from rotation Center
    local refPartOri=refPart:getOri()
    refPartOri:mulRotateAB(angle,rotVec) --rotates the part/group itself around the x-axis of his center
    centerPartRel:transform(indOri) --makes a coordinate transformation to the relate Position
    refPart:setPos(centerPartRel+centerRot)    --sets the new position as vector-sum of rotation center and transformed relative position vector
    refPart:setOri(refPartOri)
    return refPart:getPosOri()
end
Reply
« Next Oldest | Next Newest »



Messages In This Thread
RE: mathematical functions for scripting in LDCad - by Joscha - 2018-03-29, 19:23

Forum Jump:


Users browsing this thread: 1 Guest(s)