Scaling the matrix - 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: Scaling the matrix ( /thread-23734.html) |

Scaling the matrix - N. W. Perry - 2019-11-04
On to the next of the topics I’m uncovering as I delve further into the world of LDraw! I was building a Technic model and discovered that one of my beams didn’t quite fit onto the pins it’s supposed to—it needed to be “stretched” just a bit (as is common with Technic models with odd angles and connections). I compared my model to another user’s, and I noticed that in his, the beam fit correctly even though all the geometry was the same in both models. I discovered that he had scaled some of the values in the matrix; I copied those values to my beam, and it worked! So the question simply is, when this situation arises, how do I determine which values to scale in the matrix? Typically I’ll just need to make a part longer or shorter or taller by a small fraction. Can I do this interactively in LDCad, or do I just calculate scale factors based on the distance I need (and how do I know which boxes are the correct ones to change)? RE: Scaling the matrix - Johann Eisner - 2019-11-04
(2019-11-04, 17:30)N. W. Perry Wrote: On to the next of the topics I’m uncovering as I delve further into the world of LDraw! Hi [color=unset]Yes that's the problem with the real world and the digital world. There are no kine tolerances in our digital world. I would keep my fingers off scaling a bar. Since scaling affects the same part over and over again, unless you add the scaled bar as a custom part. Personally, I move the bars a little bit, so it looks like it fits exactly. Regards Johann[/color] RE: Scaling the matrix - Travis Cobbs - 2019-11-04
(2019-11-04, 20:32)Johann Eisner Wrote: Hi I'm of two minds about whether or not this a good idea, but N. W. Perry isn't proposing to do either of the things you say. The proposal is to modify the matrix used in the type 1 line that specifies the bar to make it so the bar is slightly longer (or shorter) than reality. That doesn't affect any other instances of the same part, nor does it introduce a scaled custom part. LDView will actually produce a warning (Part transformed non-uniformly) if the scaling is more than a very small amount. But this might actually be a good solution to the problem of digital LEGO models not having the play that real life models have. RE: Scaling the matrix - Johann Eisner - 2019-11-04
(2019-11-04, 22:05)Travis Cobbs Wrote: I'm of two minds about whether or not this a good idea, but N. W. Perry isn't proposing to do either of the things you say. The proposal is to modify the matrix used in the type 1 line that specifies the bar to make it so the bar is slightly longer (or shorter) than reality. That doesn't affect any other instances of the same part, nor does it introduce a scaled custom part. LDView will actually produce a warning (Part transformed non-uniformly) if the scaling is more than a very small amount. But this might actually be a good solution to the problem of digital LEGO models not having the play that real life models have. Sorry, I [color=unset]misinterpreted N. W. [/color]I thought he would change the .dat file. RE: Scaling the matrix - N. W. Perry - 2019-11-05
(2019-11-04, 22:19)Johann Eisner Wrote: Sorry, I [color=unset]misinterpreted N. W. Oh, no, I wasn't proposing to change the part itself, just the one instance of it within the model. I've already tested it and it doesn't affect any other instance of the part. If I were to change the part itself, I certainly would save it as a separate custom part. I've actually done this in the past: for example, in the 950 Fork Lift, there is a stack of seven 2x2 bricks that comes up 4 LDU proud of the connection it's supposed to make with some vertical beams. I created a custom part of a 2x2 brick that is 1 LDU too short, and mixed four of those with three normal ones to make the connection. (This was easier than distributing the 4 LDU error evenly across seven bricks, and is visually imperceptible unless you really know what to look for.) I tend to agree with Travis that scaling a part, whether ad hoc or as a custom part, tends to feel somewhat "illegal", but then again it's true that real-world parts do have not only some physical tolerance between them, but also a certain amount of flexibility that has to be accounted for if you want to accurately represent them in a model—particularly if you want to do photo-realistic rendering. Applying the matrix on a case-by-case basis, as long as we're talking about small fractions of adjustment (and we are, since the real-world tolerances only go so far), does seem to me the most elegant solution. I certainly would rather stretch a single part by a tiny amount then try to bend all the surrounding bricks to make it fit! So can I infer from that "illegality" that there aren't any tools or editors for figuring out the matrix adjustment within LDraw proper? For example, in Studio/Part Designer, which operates a little outside of the basic LDraw standard, I can free scale a part by dragging some handles, or by typing in precise dimensions, but I'd have to know what dimensions to enter. I could calculate those by using LDCad's distance measurement, I suppose, but I'm also morbidly curious about which boxes of the matrix actually control scaling along which axes of the part. (Most online articles about rotation matrices are either highly technical, or along the lines of "this topic is extremely mysterious; we can't really explain it so you'll just have to figure it out by trial-and-error.") RE: Scaling the matrix - Philippe Hurbain - 2019-11-05
This is actually very easy with LDCad (each time I try something new with it, I'm amazed by its flexibility!). Lets start with this example: two pins placed 7 studs apart in two directions almost fit a diagonal beam 11 since 7²+7² ~ 10². (Just tested, it works well IRL!) Distance of holes in the beam is exactly 200 ldu, while distance between pins (as measure by LDCad) is only 197.99 ldu. So we need to scale beam by 197.99/200 = 0.98995 (here it could also be calculated as 2x7²/10² !) Select the beam and press "o" to use relative grid. The great thing is that in this mode, the part that was used as reference has a very simple "identity" matrix, all 0 except on the main diagonal where values are 1. These "1" are actually the scaling of the part in relative x/y/z directions. Since the length of the beam is oriented along blue Z axis, we'll need to change that third "1" on matrix diagonal. Right click again on the beam, choose properties, change Z scaling. scale3.JPG (Size: 42.59 KB / Downloads: 142) ...and now the fit looks perfect! (after re-snapping the part properly) BIG WARNING: When you insert a new part in LDCad, it inherits the orientation of last previously selected part... but also its scaling! This can be very misleading (I was caught by this one while preparing this tutorial!) RE: Scaling the matrix - Roland Melkert - 2019-11-05
(2019-11-05, 17:35)Philippe Hurbain Wrote: BIG WARNING: When you insert a new part in LDCad, it inherits the orientation of last previously selected part... but also its scaling! This can be very misleading (I was caught by this one while preparing this tutorial!)I never intended it to work with scaling, so basically all editing code assumes it's non scaled. That said, as scaling is just an 'rotation extension' it should work in most places RE: Scaling the matrix - Philippe Hurbain - 2019-11-05
(2019-11-05, 19:41)Roland Melkert Wrote: I never intended it to work with scaling, so basically all editing code assumes it's non scaled.I didn't meant this as a criticism, I consider this behaviour as logical. But one must pay attention... Anyway, a small rotation could give the same kind of unwanted issues... RE: Scaling the matrix - N. W. Perry - 2019-11-06
(2019-11-05, 17:35)Philippe Hurbain Wrote: The great thing is that in this mode, the part that was used as reference has a very simple "identity" matrix, all 0 except on the main diagonal where values are 1. These "1" are actually the scaling of the part in relative x/y/z directions. […] Since the length of the beam is oriented along blue Z axis, we'll need to change that third "1" on matrix diagonal. Aha—so the important thing to know is that all scaling operations happen in the boxes along that diagonal. X-scaling in the top left box, Y-scaling in the center, and Z-scaling in the bottom right. The other boxes get used for rotations (and other functions like shear which we wouldn't be using), so as long as I'm using the part's local orientation (or the part isn't rotated), I'll only ever need to change one box for scaling along a single axis. And am I accurately summing up what a matrix is to say that its 3 columns represent the x, y and z coordinates of each point being transformed, while its 3 rows represent movements of those coordinates along the x, y and z axes? And that's why, when we scale along the z axis, we're just taking each z coordinate (third column) and moving it a relative amount along the z axis (third row)? Or something like that… RE: Scaling the matrix - Owen Dive - 2019-11-06
(2019-11-06, 6:00)N. W. Perry Wrote: Aha—so the important thing to know is that all scaling operations happen in the boxes along that diagonal. X-scaling in the top left box, Y-scaling in the center, and Z-scaling in the bottom right. The other boxes get used for rotations (and other functions like shear which we wouldn't be using), so as long as I'm using the part's local orientation (or the part isn't rotated), I'll only ever need to change one box for scaling along a single axis.No - at least, not necessarily. Rotate a part about some arbitrary axis and you'll see all 9 numbers in the matrix change. I don't remember what the mathematical terminology is (and I may even get some of this completely wrong!) but it goes something like this: Imagine you have a part and you want to describe its position and orientation relative to some coordinate system. Position is easy, you say "the centre of the part is at so many units along the x axis, so many along the y axis, and so many along the z axis". But orientation is not so clear. You have to say something like "If I start at the centre of the part, and go forward one unit relative to the part, I'll end up at position x1, y1, z1, and if I go left one unit relative to the part, I end up at position x2, y2, z2, and if I go up one unit, I end up at x3, y3, z3". The 9 numbers in the matrix are the coordinates of these three points. Now suppose I want to scale in the (say) front/back axis, by a factor of 2. I can start at the centre of the part and move _2_ units forward. I'll end up at position 2*x1, 2*y1, 2*z1. If I put those numbers in my matrix, the rendering engine will assume that those coordinates were generated at 1 unit distance, and draw all the pixels two times further forward than before. Does that make it any clearer? Or have I just made it more confusing? Edit: Actually, on re-reading this thread, I suspect that you probably understand all that. If I could delete my post, I would. |