Ultimaker / CuraEngine

Powerful, fast and robust engine for converting 3D models into g-code instructions for 3D printers. It is part of the larger open source project Cura.
https://ultimaker.com/en/products/cura-software
GNU Affero General Public License v3.0
1.69k stars 885 forks source link

how to pass model scale and rotate settings to curaEngine? #1141

Closed BrentHuang closed 5 years ago

BrentHuang commented 5 years ago

Application Version

4.3.0

Platform

linux

how to pass model scale and rotate settings to curaEngine? with -s?

Ghostkeeper commented 5 years ago

Exactly! There are a few settings specifically for the command line debug mode to be able to position and rotate your object:

https://github.com/Ultimaker/Cura/blob/648f167911134ce15ac7b9e44619bfa47589817f/resources/definitions/fdmprinter.def.json#L7592-L7640

While the last setting is called "rotation matrix", it can also be used for scaling. You can apply any linear transformation with that matrix.

BrentHuang commented 5 years ago

Thank you, can you give me some configuration examples, such as scaling 1.5 times, then rotating the model, then panning the model?

Ghostkeeper commented 5 years ago

Sure. Here is a scaling matrix:

[[1.5, 0, 0], [0, 1.5, 0], [0, 0, 1.5]]

See also documentation here.

Here is a rotation matrix of 30 degrees around the Z axis (you'd have to calculate the cosines and sines before putting this in a setting):

[[1, 0, 0], [0, cos(30), -sin(30)], [0, sin(30), cos(30)]]

There is a comprehensive formula for it here on Wikipedia but a more intuitive explanation would be on Wolfram.

Panning (moving) the model is not a linear transformation so it can't be represented by the rotation matrix. Use the settings mesh_position_x, mesh_position_y, and mesh_position_z for that.

BrentHuang commented 5 years ago

There is only one matrix here. What should I do if I want to scale and rotate together?

Ghostkeeper commented 5 years ago

You multiply the two matrices with matrix multiplication. The order in which the matrix multiplication happens matters though (whether you rotate first and then scale or scale first and then rotate).

BrentHuang commented 5 years ago

Sure. Here is a scaling matrix:

[[1.5, 0, 0], [0, 1.5, 0], [0, 0, 1.5]]

See also documentation here.

Here is a rotation matrix of 30 degrees around the Z axis (you'd have to calculate the cosines and sines before putting this in a setting):

[[1, 0, 0], [0, cos(30), -sin(30)], [0, sin(30), cos(30)]]

There is a comprehensive formula for it here on Wikipedia but a more intuitive explanation would be on Wolfram.

Panning (moving) the model is not a linear transformation so it can't be represented by the rotation matrix. Use the settings mesh_position_x, mesh_position_y, and mesh_position_z for that.

[[1, 0, 0], [0, cos(30), -sin(30)], [0, sin(30), cos(30)]] => should be rotate by X axis?not Z axis.

Is it clockwise to rotate +10 degrees around the x-axis? How is the direction of rotation determined?

What is the range of rotation angle? 0~360 or -180~180?

ninovanhooff commented 5 years ago

@BrentHuang This issue was closed by @Ghostkeeper. Please direct your question to a maths- or computer graphics related forum.

https://math.stackexchange.com/ https://medium.com/swlh/understanding-3d-matrix-transforms-with-pixijs-c76da3f8bd8

Ghostkeeper commented 5 years ago

Unrelated to maths: putting cos(30) in there like my example won't work. You'll need to calculate the cosine of your angle yourself because CuraEngine will not evaluate it. Whether you do that in degrees, radians, grads, sextants, etc. doesn't matter as long as your calculator does it correctly.