RE: mathematical functions for scripting in LDCad
2018-03-29, 19:23 (This post was last modified: 2018-03-29, 19:24 by Joscha.)
2018-03-29, 19:23 (This post was last modified: 2018-03-29, 19:24 by Joscha.)
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:
Therefore I introduces the 'indipendent orientation'.
So, here is the code:
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())
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