mathematical functions for scripting in LDCad

RE: mathematical functions for scripting in LDCad
#19
(2018-03-25, 17:31)Roland Melkert Wrote:
(2018-03-25, 9:12)Joscha Wrote: Roland, I have to come back to your code above. I applied it successfully. Thank you! But I do not understand the getInverted command. How to invert a vector? The command should be only for matrices, shouldn't it?

getInverted only flips the signs of xyz, so e.g. (1,-2,3) returns (-1,2,-3).

I named it inverted as its goal is the same, to "undo" the vectors content (1+ -1 = 0) just as an inverted matrix can be used to get identity back when multiplying with the original.

I have a different approach for the rotation around any center which seems to be much shorter:
Code:
```local angle=23                     --rotation angle local centerPart=ref.getPos()             --center of part/group to be rotated local centerRot=ldc.vector(2,3,4)        --Vector of rotation center local centerPartRel=centerPart-centerRot     --relative position of part/group center from rotation Center                  ref:mulRotateAB(angle,1,0,0)            --rotates the part/group itself around the x-axis of his center centerPartRel.transform(ref.getOri())        --makes a transformation to the relative position with the new orientation ref:setPos(centerPartRel+centerRot)        --sets the new position as vector-sum of rotation center and transformed relative position vector```
« Next Oldest | Next Newest »