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

mathematical functions for scripting in LDCad  Joscha  20180314 Hi Is there any overview on the mathematical functions included in the scripting language of LDCad? Does it include algebraic operations (Matrices)? Is it possible to add such libraries? Regards Joscha RE: mathematical functions for scripting in LDCad  Jarema  20180314 According to Scripting API documentation. LDCad have module match included described here http://luausers.org/wiki/MathLibraryTutorial. RE: mathematical functions for scripting in LDCad  Joscha  20180314 (20180314, 9:07)Jarema Wrote: According to Scripting API documentation. LDCad have module match included described here http://luausers.org/wiki/MathLibraryTutorial. Hi Jarema Thank you for yor quick answer and sorry for being blind. It is quite obvious on the LDCad homepage. It doesn't seem to support algebraic functions. RE: mathematical functions for scripting in LDCad  Roland Melkert  20180314 (20180314, 16:57)Joscha Wrote: It doesn't seem to support algebraic functions. The default lua math library is very limited, but the beauty of a scripting language is you can extend it with the things you need. Ether by using a thirdparty library or by writing one your self. If all you need is matrix and vector math I did add support for that through the ldc module as LDraw is heavily depended on matrix math. But the ldc matrix math is highly targeted on LDraw usage, so if you need more complicated things you might need to use something like: https://github.com/anaef/lualinear But this would require you to compile a .dll (window) or .so (Linux). There might also be a pure lua module for this out there, but I couldn't find it during a quick web search. If you go the compile route be sure to match the main executable 32 or 64 bit wise. And use the lua 5.3 headers. RE: mathematical functions for scripting in LDCad  Joscha  20180314 (20180314, 18:33)Roland Melkert Wrote: If all you need is matrix and vector math I did add support for that through the ldc module as LDraw is heavily depended on matrix math. Hi Roland Yes, all I need is vector and matrix math. My problem is, I would like to rotate a part and I would like to know (or use it in the script) the new position of a specific point of this part. This would usually be a simple coordinate system rotation multiplying a vector with the rotation matrix. The most suitable command seems to be 'transform'. Only somehow it does not behave fully like this. It seems to flip my part by 180°. Furthermore, is there any way to access the location of the parts center? I mean the rotation matrix always rotates a part around its center. If I like to rotate it around another center during a script I would have to rotate and translate it. This seems to be confusing. RE: mathematical functions for scripting in LDCad  Roland Melkert  20180314 (20180314, 22:15)Joscha Wrote: Hi Roland Keep in mind the LDraw coordinate system uses a negative Y while OpenGL does not. I correct for this by using a base model view rotation of 180 degrees. To rotate around another center you do indeed need to apply a translate, like so: Code: local center=ldc.vector(10, 0, 10) some alternative center. I know it's not very efficient but, if it would need to be really fast you wouldn't be using script You could wrap the matrix construction in a function if you worried about readability etc. To find the abs position of point in the part you need to use Code: someVectorWithPositionRelativeToBrickRefIsLinkedTo:transform(refMatrix) RE: mathematical functions for scripting in LDCad  Joscha  20180315 I figured out why I experienced the 180° flip. I just applied the rotation to the wrong orientation matrix. But basically I learned now that everything I need is already packed inside the scripting API. Thank you! Coming back to the matrix type. You describe that it is a 4x4 matrix initialised as identity matrix. But for the location and orientation only 12 elements are used. Do the four remaining elements contain information? RE: mathematical functions for scripting in LDCad  Roland Melkert  20180315 (20180315, 14:05)Joscha Wrote: Coming back to the matrix type. You describe that it is a 4x4 matrix initialised as identity matrix. But for the location and orientation only 12 elements are used. Do the four remaining elements contain information? The 12 elements are what is used in LDraw "type 1" lines. It's a position and 3x3 rotation matrix. Internally this is stored in a 4x4 matrix but one column (or row depending how you look at it) is (or should be) always 0 0 0 1 as it assumes the matrices only contain a rotation and translation. ps: I noticed an error in my code which works only because of a fluke: Code: local matrix=ldc.matrix() Code: local matrix=ldc.matrix() RE: mathematical functions for scripting in LDCad  Jarema  20180316 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 ? RE: mathematical functions for scripting in LDCad  Joscha  20180316 (20180315, 18:13)Roland Melkert Wrote: Indeed, I thought about why using mulAB once with a matrix once with a vector, but I didn't dare to ask I just stumbled over the center:getInverted(). In your manual getInverted is for matrices. What does it do with the vector? 