[LDCad] Advanced rotation techniques - Printable Version +- LDraw.org Discussion Forums (https://forums.ldraw.org) +-- Forum: LDraw Programs (https://forums.ldraw.org/forum-7.html) +--- Forum: LDraw Editors and Viewers (https://forums.ldraw.org/forum-11.html) +--- Thread: [LDCad] Advanced rotation techniques (/thread-26579.html) |
Advanced rotation techniques - N. W. Perry - 2022-07-22 I feel like I'm under-using LDCad's advanced rotation capabilities. But instead of a question, I think it's easier to just give an example—and sort of a challenge. In the attached test file I have an oddly-shaped piece that I want to rest on the ground, here represented by a nice big tile. This part has four lower extremities, all with different y-values, and to be realistic it would need to rest against the lowest three of them. What's the best way to do this using LDCad? test.ldr (Size: 173 bytes / Downloads: 2) Here's how I would approach it:
Is there a better way? How would you approach this problem? (Can't attach the .lua file for the angle script, but here it is Code: function onRun() RE: Advanced rotation techniques - Roland Melkert - 2022-07-22 (2022-07-22, 13:40)N. W. Perry Wrote: Is there a better way? How would you approach this problem?With alpha 2 of 1.7 you could use script to find the 'bottom' coordinates. Then use those to make a plane, which then can be used to construct an orientation matrix. The only real problem is finding those resting points inside the mesh's unique points list. RE: Advanced rotation techniques - N. W. Perry - 2022-07-23 (2022-07-22, 22:04)Roland Melkert Wrote: With alpha 2 of 1.7 you could use script to find the 'bottom' coordinates. Indeed, it would be really slick if we could directly access the mesh points! But assuming I know a couple of the points, is there a way to find the vector between them through the GUI? I guess via selection info (taking angle values from each of the orthogonal views)? RE: Advanced rotation techniques - Roland Melkert - 2022-07-23 (2022-07-23, 1:25)N. W. Perry Wrote: Indeed, it would be really slick if we could directly access the mesh points! The attached script levels (3 items of) the selection. core of the script: Code: for i=1,3 do The script takes 3 items from the selection and use them to get a plane normal. Then it uses one of the 2 triangle vectors as the x-axis to build an orientation matrix. You'll have to rotate it around Y afterwards to get it on its final place. The really cool thing would be to analyze the mesh (possible in 1.7 Alpha 2a) to get those 3 points automatically. RE: Advanced rotation techniques - Owen Dive - 2022-07-24 I think there are fundamental geometric problems with the "select all three points at once then rotate" approach. This is because you can't specify "the three lowest points" without also specifying an absolute rotation. If you select your three lowest points and then _change_ the orientation of the part, there's no guarantee that the new "three lowest points" are the same three points. Owen. RE: Advanced rotation techniques - N. W. Perry - 2022-07-24 (2022-07-24, 1:34)Owen Dive Wrote: I think there are fundamental geometric problems with the "select all three points at once then rotate" approach. This is because you can't specify "the three lowest points" without also specifying an absolute rotation. If you select your three lowest points and then _change_ the orientation of the part, there's no guarantee that the new "three lowest points" are the same three points. Indeed, and another thing is that you won't always have a nice level plane. What if, instead, you need the part to rest against the inside of a box with studs on the bottom? So I think of a step-by-step approach:
Still, I think there are certain cases where your eyes will tell you that a plane on one part can be rotated to match a plane on another, and if that's the case it's nice to have a one-step process. RE: Advanced rotation techniques - N. W. Perry - 2022-07-25 (2022-07-23, 19:20)Roland Melkert Wrote: The attached script levels (3 items of) the selection. Nifty! So that makes the process:
RE: Advanced rotation techniques - Roland Melkert - 2022-07-25 (2022-07-25, 2:50)N. W. Perry Wrote: Select the 3 helper parts and apply the script.You can also extend the script to apply the rotation to the whole selection instead of just the first 3 items. (2022-07-25, 2:50)N. W. Perry Wrote: So the only question now is, what happens if the ground isn't nice and smooth?There's always room for improvement RE: Advanced rotation techniques - N. W. Perry - 2022-07-25 (2022-07-25, 20:54)Roland Melkert Wrote: You can also extend the script to apply the rotation to the whole selection instead of just the first 3 items. That's what I was thinking, any items beyond three would be rotated also—and it would take the first part in the selection as the rotation center, like usual? Quote:There's always room for improvement Indeed. Maybe by selecting another three points, you could establish them as the "target" plane. Although, you probably wouldn't know those three points until you've worked out the rotation, so a stepwise approach is probably necessary for cases like those. Only thing I'm still not sure of is, how can I find the XYZ values for this dialog: Like if I want to select two helper parts, then rotate the main part around the vector connecting them? RE: Advanced rotation techniques - Roland Melkert - 2022-07-26 (2022-07-25, 21:32)N. W. Perry Wrote: Only thing I'm still not sure of is, how can I find the XYZ values for this dialog: If you want to rotate around the x-as you would use vector 1,0,0 (or -1,0,0) just like scripts do. The dialog was intended for using information from third parties whom often use these rotation vectors instead of an orientation matrices. RE: Advanced rotation techniques - N. W. Perry - 2022-07-26 (2022-07-26, 19:16)Roland Melkert Wrote: If you want to rotate around the x-as you would use vector 1,0,0 (or -1,0,0) just like scripts do. Oh, I see, so that's a matrix row, not angles. Maybe that tool doesn't work the way I thought! RE: Advanced rotation techniques - Travis Cobbs - 2022-07-26 (2022-07-26, 21:25)N. W. Perry Wrote: Oh, I see, so that's a matrix row, not angles. Maybe that tool doesn't work the way I thought! The X, Y, and Z values in the dialog are not a matrix row. They are the coordinates of one endpoint of line segment representing a vector. (The other endpoint is implicitly 0,0,0.) The direction the vector points defines the axis of rotation, and the rotation angle defines the magnitude of the rotation. Note that the only thing that matters for this vector is the direction it points, not its own magnitude. So, 1,0,0 and 2,0,0 would produce the same results for a given angle, since both are aligned with the X axis. RE: Advanced rotation techniques - N. W. Perry - 2022-07-27 (2022-07-26, 23:03)Travis Cobbs Wrote: The X, Y, and Z values in the dialog are not a matrix row. They are the coordinates of one endpoint of line segment representing a vector. (The other endpoint is implicitly 0,0,0.) The direction the vector points defines the axis of rotation, and the rotation angle defines the magnitude of the rotation. Note that the only thing that matters for this vector is the direction it points, not its own magnitude. So, 1,0,0 and 2,0,0 would produce the same results for a given angle, since both are aligned with the X axis. Well shoot, I always though matrix rows were vectors. But I'd never really thought in terms of coordinates before. (This is always my problem with this stuff: I learn specific concepts for specific tasks, but I'm always missing the important bits in the middle.) So this means, to find the values for this dialog, I could simply select the first helper part and set the grid relative to it. Then, the coordinates of the second helper part would give me the XYZ values I need to rotate around a vector connecting them. I think. |