mathematical functions for scripting in LDCad  Printable Version + LDraw.org Discussion Forums (https://forums.ldraw.org) + Forum: LDraw Programs (https://forums.ldraw.org/forum7.html) + Forum: LDraw Editors and Viewers (https://forums.ldraw.org/forum11.html) + Thread: mathematical functions for scripting in LDCad (/thread22756.html) Pages:
1
2

RE: mathematical functions for scripting in LDCad  Joscha  20180316 (20180316, 9:08)Jarema Wrote: As with another pool of questions. Because I have never been strong... in mathematics. I ask how to determine the angle of inclination of a given part with respect to a given axis ? Do you mean the angle between the orientation of a part/group and any vector? Isn't it 'getAngle'? RE: mathematical functions for scripting in LDCad  Jarema  20180316 How calculate the angle of Technic Axle 6 relative to the Y axis. See attached file. RE: mathematical functions for scripting in LDCad  Roland Melkert  20180316 (20180316, 17:15)Jarema Wrote: How calculate the angle of Technic Axle 6 relative to the Y axis. See attached file. Axles point into their local X direction, so... Take a vector of 1 0 0 Transform it by the axles rotation ( :getRef, :getOri) Take a vector of abs Y (0 1 0) Get the angle between the two by absYVector:getAngle(absAxleXVector) Hope this get you on the right path. ps: I'm assuming you need this for scripting, during editing you better off using the selection information feature. RE: mathematical functions for scripting in LDCad  Joscha  20180317 (20180316, 9:08)Jarema Wrote: As with another pool of questions. Because I have never been strong... in mathematics. I ask how to determine the angle of inclination of a given part with respect to a given axis ? Hi Jarema From the mathematical point of view the angle between two vectors is determined by angle=acos( vecA*vecB / abs(vecA) / abs(vecB) ) Sorry, I wanted to post a formula, but for some reason I couldn't post the image. RE: mathematical functions for scripting in LDCad  Jarema  20180317 I discovered Today, that genTools.lua in default\modules have triangleAngle and trianglePlacementAngles. I hope that this module will be regularly enriched with new, standalone functions RE: mathematical functions for scripting in LDCad  Roland Melkert  20180317 (20180317, 17:31)Jarema Wrote: I discovered Today, that genTools.lua in default\modules have triangleAngle and trianglePlacementAngles. I hope that this module will be regularly enriched with new, standalone functions I added those because I needed them in multiple example animations trianglePlacementAngles basiclly does what the option in the selection information menu does. RE: mathematical functions for scripting in LDCad  Joscha  20180325 (20180314, 23:55)Roland Melkert Wrote: To rotate around another center you do indeed need to apply a translate, like so: RE: mathematical functions for scripting in LDCad  Roland Melkert  20180325 (20180325, 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. RE: mathematical functions for scripting in LDCad  Joscha  20180326 (20180325, 17:31)Roland Melkert Wrote:(20180325, 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? I have a different approach for the rotation around any center which seems to be much shorter: Code: local angle=23 rotation angle RE: mathematical functions for scripting in LDCad  Joscha  20180329 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()) So, here is the code: Code: function rotaround(refPart,centerRot,indOri,angle,rotVec) 