Answers.Body: <p>There's a fairly in-depth discussion on the Eurobricks Digital Designer Forum in the post <a href="http://www.eurobricks.com/forum/index.php?showtopic=92863" rel="nofollow noreferrer">Understanding LDDs LFXML Schema</a>, where the <code>transformation</code> element <a href="http://www.eurobricks.com/forum/index.php?showtopic=92863&amp;#entry1876550" rel="nofollow noreferrer">is defined as</a>:</p>
  
  <blockquote>
    <p>Transformation contains 12 comma separated double precision floating point values that represent the first three columns of a 3d transformation matrix and are thus able to handle any linear transformation. It's something that you'll need to learn for yourself but the first 9 entries handle rotation, the last 3 are translation. It's worth noting that the origin of most bricks is at the bottom with the y-axis heading up through the center of a stud, this makes rotations around the axis of the stud slightly easier. Brick width is 0.8, brick height is 0.96 and plate height 0.32. This probably ties in with real world dimensions in some form, but I don't have the details to hand. The double precision floating point format can't necessary cope with precise decimal values as we might expect to see them, therefore you'll see slight deviations from the values given above, eg. -0.79999935626983643 instead of -0.8. Those 0.707 values are 45 degree rotations, they correspond to the sin or cosine of 45 degrees (or PI/4 in radians) and are part of the transformation. Transformations are in world coordinates.</p>
  </blockquote>
  
  <p>As Philo points out <a href="https://bricks.stackexchange.com/questions/3201/can-anyone-explain-the-transformation-information-within-a-lego-digital-designer/3204?noredirect=1#comment3859_3204">in the comments</a>, the values that The_Cook queries as "probably ties in with real world dimensions" are indeed the sizes of bricks in centimetres, which means you should be able to transform between systems nicely.</p>
  
  <p>In response to your final goal (building a plugin for 3ds Max) what you're really going to need is a complete set of high-quality meshes - the LDD format works with part models rather than vertices/faces/edges/etc. that 3ds uses. Therefore what you'll probably want to take a look at is a tool to convert from LDD to something like LDraw (you could just use the "Export" function in the LDD file menu), and then use the LDraw model library as your basis for importing into 3ds, or use the features in LDView to export to .3ds (the older, text based file type 3d Studio used before it became "Max").</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-02T11:30:42.973Z
Answers.Text: "Brick width is 0.8, brick height is 0.96 and plate height 0.32.": These are dimensions of bricks in centimeters...
Answers.UserDisplayName: Philo
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-02T11:47:26.050Z
Answers.Text: Good catch, indeed we've covered those nicely on [What are the dimensions of a LEGO brick](http://bricks.stackexchange.com/q/288/56), but it's nice to see that internally LDD is using real world units as well - makes converting easier ;)
Answers.UserDisplayName: Zhaph - Ben Duguid
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-02T12:57:50.757Z
Answers.Text: Thanks for the info and link, just what I was after =) I've been building a max part library for a while by doing exactly that - importing parts in .3ds and completely rebuilding them for best use in max... hopefully have something fun for others to play with one of these days
Answers.UserDisplayName: Phil
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-02T11:17:22.220Z
Answers.LastActivityDate: 2014-06-02T12:15:11.843Z
Answers.LastEditDate: 2017-04-13T12:47:56.213Z
Answers.UserDisplayName: Zhaph - Ben Duguid
Answers.Body: <p>The 3 last values in the transformation attribute are the position of the brick in 3D space XYZ. Simple.</p>
  
  <p>The interesting part is the first 9 values in the transformation attribute</p>
  
  <pre><code>&lt;Rigid refID="0" transformation="0,0,1,0,0.99999910593032837,0,-0.99999988079071045,0,0,-0.39999967813491821,0.40000063180923462,1.2000013589859009" boneRefs="0"/&gt;
  </code></pre>
  
  <p>They are read as a 3x3 rotation matrix (in-depth explanation: <a href="https://en.wikipedia.org/wiki/Rotation_matrix" rel="nofollow noreferrer">Wikipedia Rotation Matrix</a>)</p>
  
  <pre><code>[a1 a2 a3]       [ 0  0  1]
  [a3 a4 a5]  ==&gt;  [ 0  1  0]
  [a6 a7 a8]       [-1  0  0]
  </code></pre>
  
  <p>In this case, this is a single rotation around the Y axis, as the axes directions are:</p>
  
  <p><a href="https://i.sstatic.net/YWcqO.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/YWcqO.png" alt="enter image description here"></a></p>
  
  <p>So if you describe the rotation of the brick as <a href="https://howthingsfly.si.edu/flight-dynamics/roll-pitch-and-yaw" rel="nofollow noreferrer">yaw, pitch, roll</a> you can say that this matrix describes a 90 degrees yaw clockwise. A 90 degrees yaw counter clockwise is considered a turn of -90 degrees. (clockwise and counter clockwise are probably not the right terms to use here. I am using to make the description easier to understand)</p>
  
  <p>as long as the brick does a single 90 degrees yaw, pitch or roll, it is simple to detect the rotation axis, because there is a single row in the matrix that remains the same, see section <a href="https://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations" rel="nofollow noreferrer">Basic Rotations</a>. In the case of rotating around Y axis, the middle row <code>[0, 1, 0]</code> doesn't change.</p>
  
  <p>Rotating around X axis, keeps the 1st row unchanged <code>[1, 0, 0]</code></p>
  
  <p>Rotating around Z axis, keeps the 3rd row unchanged <code>[0, 0, 1]</code></p>
  
  <p>So, rotating 90 degrees around the Y axis is (2nd row is 0, 1, 0 as described above)</p>
  
  <pre><code>[Cos90   0   Sin90]
  [0       1   0    ]
  [-Sin90  0   Cos90]
  </code></pre>
  
  <p>If the transformation is a combination of rotating around 2 or 3 axes, the matrix is not trivial to read and is a matrix multiplication of 2 or 3 of the above matrices with the respective degree of rotation around each axis.</p>
  
  <p>Turning the brick to 90, 180, 270 degrees in each direction, results in values of 0, 1 or -1 for each cell in the matrix. These are the results for the Sin and Cos functions for 0, 90, 180, 270 degrees.</p>
  
  <p>last point to consider:</p>
  
  <p>If you get values that are not 0, 1, -1 there are two options:</p>
  
  <ol>
  <li>LDD has a slight miscalculation (This is not a confirmed fact, only my opinion). You can see in the attribute at the top of the post that one of the values is 0.99999... which is basically 1, so it's a 90 degrees turn.</li>
  <li>You turned a LEGO object in an angle which is not a multiplication of 90 (e.g. hat on top of a head turned 30 degrees clockwise)</li>
  </ol>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-26T16:41:10.453Z
Answers.LastActivityDate: 2018-09-27T07:08:30.293Z
Answers.LastEditDate: 2018-09-27T07:08:30.293Z
Answers.UserDisplayName: RaamEE
Body: <p>I've been taking a look at the structure of the LDD files recently to see if it's feasible to create a plugin for 3D studio max that allows you to directly open LXF files for higher quality rendering... </p>
  
  <p>It seems possible, but to get some preliminary tests happening I just need to understand exactly how the transformation string works:</p>
  
  <p>transformation="0,0,1,0,1,0,-1,0,0,0.40000009536743164,0,-0.40000009536743164"</p>
  
  <p>It seems pretty obvious from playing around that the last 3 relate to the position of the piece, and the first 9 somehow relate it's rotation (and perhaps 1 or 2 other things I'm not aware of yet). If anyone knows I'd love a detailed explanation as it would save me a LOT of messing around =)</p>
  
  <p>Also are there any good resources of info on lxf files? I have only come across fairly basic stuff so far, would love to find a good resource... </p>
  
Tags: <ldd>
Title: Can anyone explain the transformation information within a Lego Digital Designer LXF file?
UserDisplayName: Phil
ThreadText: # Can anyone explain the transformation information within a Lego Digital Designer LXF file?
  
  (Asked by: username_0 on 2014-06-02)
  
  I've been taking a look at the structure of the LDD files recently to see if it's feasible to create a plugin for 3D studio max that allows you to directly open LXF files for higher quality rendering...
  
  It seems possible, but to get some preliminary tests happening I just need to understand exactly how the transformation string works:
  
  transformation="0,0,1,0,1,0,-1,0,0,0.40000009536743164,0,-0.40000009536743164"
  
  It seems pretty obvious from playing around that the last 3 relate to the position of the piece, and the first 9 somehow relate it's rotation (and perhaps 1 or 2 other things I'm not aware of yet). If anyone knows I'd love a detailed explanation as it would save me a LOT of messing around =)
  
  Also are there any good resources of info on lxf files? I have only come across fairly basic stuff so far, would love to find a good resource...
  
  **Tags:** ldd
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2014-06-02. Score: 4 | Accepted answer
  
  There's a fairly in-depth discussion on the Eurobricks Digital Designer Forum in the post [Understanding LDDs LFXML Schema](http://www.eurobricks.com/forum/index.php?showtopic=92863), where the `transformation` element [is defined as](http://www.eurobricks.com/forum/index.php?showtopic=92863&#entry1876550):
  
  > Transformation contains 12 comma separated double precision floating point values that represent the first three columns of a 3d transformation matrix and are thus able to handle any linear transformation. It's something that you'll need to learn for yourself but the first 9 entries handle rotation, the last 3 are translation. It's worth noting that the origin of most bricks is at the bottom with the y-axis heading up through the center of a stud, this makes rotations around the axis of the stud slightly easier. Brick width is 0.8, brick height is 0.96 and plate height 0.32. This probably ties in with real world dimensions in some form, but I don't have the details to hand. The double precision floating point format can't necessary cope with precise decimal values as we might expect to see them, therefore you'll see slight deviations from the values given above, eg. -0.79999935626983643 instead of -0.8. Those 0.707 values are 45 degree rotations, they correspond to the sin or cosine of 45 degrees (or PI/4 in radians) and are part of the transformation. Transformations are in world coordinates.
  
  As username_2 points out [in the comments](https://bricks.stackexchange.com/questions/3201/can-anyone-explain-the-transformation-information-within-a-lego-digital-designer/3204?noredirect=1#comment3859_3204), the values that The\_Cook queries as "probably ties in with real world dimensions" are indeed the sizes of bricks in centimetres, which means you should be able to transform between systems nicely.
  
  In response to your final goal (building a plugin for 3ds Max) what you're really going to need is a complete set of high-quality meshes - the LDD format works with part models rather than vertices/faces/edges/etc. that 3ds uses. Therefore what you'll probably want to take a look at is a tool to convert from LDD to something like LDraw (you could just use the "Export" function in the LDD file menu), and then use the LDraw model library as your basis for importing into 3ds, or use the features in LDView to export to .3ds (the older, text based file type 3d Studio used before it became "Max").
  
  > **Comments:**
  > **username_2**: "Brick width is 0.8, brick height is 0.96 and plate height 0.32.": These are dimensions of bricks in centimeters...  
  > **username_1**: Good catch, indeed we've covered those nicely on [What are the dimensions of a LEGO brick](http://bricks.stackexchange.com/q/288/56), but it's nice to see that internally LDD is using real world units as well - makes converting easier ;)  
  > **username_0**: Thanks for the info and link, just what I was after =) I've been building a max part library for a while by doing exactly that - importing parts in .3ds and completely rebuilding them for best use in max... hopefully have something fun for others to play with one of these days  
  
  ---
  
  ### Answer by username_3 on 2018-09-26. Score: 2
  
  The 3 last values in the transformation attribute are the position of the brick in 3D space XYZ. Simple.
  
  The interesting part is the first 9 values in the transformation attribute
  
  ```
  <Rigid refID="0" transformation="0,0,1,0,0.99999910593032837,0,-0.99999988079071045,0,0,-0.39999967813491821,0.40000063180923462,1.2000013589859009" boneRefs="0"/>
  
  ```
  
  They are read as a 3x3 rotation matrix (in-depth explanation: [Wikipedia Rotation Matrix](https://en.wikipedia.org/wiki/Rotation_matrix))
  
  ```
  [a1 a2 a3]       [ 0  0  1]
  [a3 a4 a5]  ==>  [ 0  1  0]
  [a6 a7 a8]       [-1  0  0]
  
  ```
  
  In this case, this is a single rotation around the Y axis, as the axes directions are:
  
  [![enter image description here](https://i.sstatic.net/YWcqO.png)](https://i.sstatic.net/YWcqO.png)
  
  So if you describe the rotation of the brick as [yaw, pitch, roll](https://howthingsfly.si.edu/flight-dynamics/roll-pitch-and-yaw) you can say that this matrix describes a 90 degrees yaw clockwise. A 90 degrees yaw counter clockwise is considered a turn of -90 degrees. (clockwise and counter clockwise are probably not the right terms to use here. I am using to make the description easier to understand)
  
  as long as the brick does a single 90 degrees yaw, pitch or roll, it is simple to detect the rotation axis, because there is a single row in the matrix that remains the same, see section [Basic Rotations](https://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations). In the case of rotating around Y axis, the middle row `[0, 1, 0]` doesn't change.
  
  Rotating around X axis, keeps the 1st row unchanged `[1, 0, 0]`
  
  Rotating around Z axis, keeps the 3rd row unchanged `[0, 0, 1]`
  
  So, rotating 90 degrees around the Y axis is (2nd row is 0, 1, 0 as described above)
  
  ```
  [Cos90   0   Sin90]
  [0       1   0    ]
  [-Sin90  0   Cos90]
  
  ```
  
  If the transformation is a combination of rotating around 2 or 3 axes, the matrix is not trivial to read and is a matrix multiplication of 2 or 3 of the above matrices with the respective degree of rotation around each axis.
  
  Turning the brick to 90, 180, 270 degrees in each direction, results in values of 0, 1 or -1 for each cell in the matrix. These are the results for the Sin and Cos functions for 0, 90, 180, 270 degrees.
  
  last point to consider:
  
  If you get values that are not 0, 1, -1 there are two options:
  
  1. LDD has a slight miscalculation (This is not a confirmed fact, only my opinion). You can see in the attribute at the top of the post that one of the values is 0.99999... which is basically 1, so it's a 90 degrees turn.
  2. You turned a LEGO object in an angle which is not a multiplication of 90 (e.g. hat on top of a head turned 30 degrees clockwise)
  
  
  ---
  
  