Skip to content

Instantly share code, notes, and snippets.

@aaronfranke
Last active February 21, 2023 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronfranke/754f55c3d181e18154c9dccf801f9050 to your computer and use it in GitHub Desktop.
Save aaronfranke/754f55c3d181e18154c9dccf801f9050 to your computer and use it in GitHub Desktop.
Inertia Tensor ChatGPT

Aaron Franke

I am working on a standard for specifying parameters for rigid body physics. This standard needs to support multiple physics engines. I already have parameters for the body's mass, linear velocity, and angular velocity. I need to add a new parameter for the inertia tensor, which describes the body's resistance to be rotated in different directions. The problem is that some physics engines implement the inertia tensor as a 3x3 matrix, and some physics engines implement inertia as a Vector3. I am thinking that I should specify the parameter as a 3x3 matrix, and include algorithms to convert to and from Vector3 inertia to support those physics engines that use Vector3 inertia. What is the formula to do this? Also, can you evaluate if my approach is portable?

ChatGPT

Your approach of specifying the inertia tensor as a 3x3 matrix and including algorithms to convert to and from Vector3 inertia is a good way to handle the variability in how different physics engines implement inertia. To convert between a 3x3 matrix and a Vector3, you can use the following formulas:

Converting from a 3x3 matrix to a Vector3:

Vector3 = (Ixx, Iyy, Izz)

where Ixx, Iyy, and Izz are the diagonal elements of the 3x3 matrix representing the inertia tensor.

Converting from a Vector3 to a 3x3 matrix:

| Ixx  0   0  |
|  0  Iyy  0  |
|  0   0  Izz |

where Ixx, Iyy, and Izz are the components of the Vector3 representing the inertia tensor.

This approach should be portable across different physics engines, as long as you include the conversion algorithms for both directions in your standard. By doing so, you enable all physics engines to implement your standard in their own way, and to convert the inertia tensor to their preferred format. However, you may want to consider providing additional guidance on how to choose the values of the inertia tensor to ensure consistency across different physics engines.

Aaron Franke

Can you link me some resources which I can use to confirm that the algorithms you suggest are correct? They seem good, but I need to be sure.

ChatGPT

Certainly! Here are some resources that can help you confirm the correctness of the algorithms I provided for converting between a 3x3 matrix and a Vector3 representing the inertia tensor:

  • For the conversion from a 3x3 matrix to a Vector3, you can refer to the Wikipedia page on "Inertia tensor". Specifically, the "Properties" section mentions that the diagonal elements of the 3x3 matrix representing the inertia tensor are equal to the moments of inertia around the principal axes, which is exactly what the algorithm I provided uses.

  • For the conversion from a Vector3 to a 3x3 matrix, you can refer to the book "Physics for Game Developers" by David M. Bourg and Bryan Bywalec. In chapter 8, section 8.3.2, the authors discuss the conversion between a Vector3 and a diagonal matrix representing the inertia tensor, which is equivalent to the 3x3 matrix with the off-diagonal elements set to zero that I provided.

I hope this helps! Let me know if you have any further questions.

Aaron Franke

This is great! Can you help me build my understanding some more? What do the non-diagonal elements of the matrix physically represent? Is it fine that when converting to a Vector3 we only use the values on the diagonal that represent the principle axes, and not use the non-diagonal elements? Is it valid to have an inertia tensor where the diagonal is zero and the non-diagonal elements are non-zero, if so what does that physically represent, if not why?

ChatGPT

Sure, I'd be happy to help!

The non-diagonal elements of the inertia tensor matrix represent the product of inertia, which is a measure of how different pairs of axes are coupled with each other. The product of inertia represents the amount of coupling between the angular motions around two different axes. For example, if the body is a long thin rod, the product of inertia for the x-axis and y-axis would be non-zero, because rotating the rod around one axis will cause some rotation around the other axis as well.

When converting from a 3x3 matrix representing the inertia tensor to a Vector3, it is common practice to use only the diagonal elements of the matrix, which represent the moments of inertia around the principal axes. This is because moments of inertia around the principal axes are the most meaningful values, and they allow us to determine how easily the body can rotate around each of its three principal axes. However, keep in mind that the off-diagonal elements of the matrix may still affect the behavior of the rigid body in certain situations, such as when it experiences a torque or is subject to collisions with other objects.

It is not valid to have an inertia tensor where the diagonal is zero and the non-diagonal elements are non-zero, because this would imply that the body has no resistance to rotation around any of its principal axes. In reality, all rigid bodies have some resistance to being rotated around their principal axes. Additionally, the off-diagonal elements of the matrix should always be symmetric, meaning that the (i,j)-th element should be equal to the (j,i)-th element. If the off-diagonal elements are not symmetric, this would indicate that the body has different resistance to rotation depending on the direction of rotation, which is physically impossible.

Aaron Franke

Since the matrix is symmetric, and the non-diagonal elements represent how the axes are coupled with each other, if I am understanding correctly the matrix really encodes these 6 numbers: Principle X, Y, Z, and couplings between XY, YZ, and XZ. Is my understanding correct?

ChatGPT

Yes, that's correct! The inertia tensor matrix is a symmetric 3x3 matrix that encodes the moments of inertia around the three principal axes, as well as the coupling between the three axes. Specifically, the diagonal elements of the matrix represent the moments of inertia around the principal axes, and the off-diagonal elements represent the coupling between the angular motion around each pair of axes.

So the inertia tensor matrix encodes a total of 6 unique values: the three moments of inertia around the principal axes (Ixx, Iyy, and Izz) and the three products of inertia (Ixy, Ixz, and Iyz). Note that because the matrix is symmetric, the products of inertia satisfy the symmetry condition Ixy = Iyx, Ixz = Izx, and Iyz = Izy.

I hope that helps clarify things! Let me know if you have any more questions.

Aaron Franke

With this information, I am wondering if instead of a 3x3 matrix (represented as a 9 number array), I should have the physics standard use a 6-number array. Then physics engines with Vector3 inertia can only use the values for the principle axes, and physics engines that use a 3x3 matrix can populate it with the principle axes and two copies of each non-diagonal coupling value. Is this a good approach since it reduces redundancy, or would it be better to use a 3x3 matrix since it's a format that is directly used in some places?

ChatGPT

Using a 6-number array instead of a 3x3 matrix is a valid approach that could potentially reduce redundancy in your physics standard. By storing only the moments of inertia around the principal axes and the products of inertia, you are essentially encoding the same information as the 3x3 matrix, but in a more compact form. This can be useful for physics engines that use a Vector3 representation for inertia.

However, keep in mind that using a 3x3 matrix has some advantages as well. For one, it is a more common format that is directly used in some physics engines, so it may be easier to integrate with those engines if you use a matrix. Additionally, using a matrix provides a more complete and explicit representation of the inertia tensor, including all of the moments of inertia and products of inertia. This could be important for certain types of simulations or analyses that require a detailed understanding of the inertia tensor.

Ultimately, the choice between a 6-number array and a 3x3 matrix will depend on your specific needs and the needs of the physics engines that will be using your standard. If you anticipate that many engines will benefit from a more compact representation of the inertia tensor, then a 6-number array could be a good choice. On the other hand, if compatibility with existing physics engines is a higher priority, then a 3x3 matrix might be a better choice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment