Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by RSG · May 25, 2013 at 02:40 AM · matrixmatrix4x4transformsinverse

How to get the inverse of a transformation matrix that has a scale of zero?

Hello every one, I’m working on a project where I use a transformation matrix (translation, rotation and scale) to edit the vertices of a mesh. I also group vertices into parent child relationships. There are times where I need to go from a local space to a parent space so I usually use the inverse of my matrix to do that. This works most of the time except when I set the scale to 0 for x, y, or z then the inverse is always a zero matrix. Here is what I mean:

 parentScale = Vector3.one;
 
 // Create a transformation matrix for parent
 Matrix4x4 M = Matrix4x4.TRS(parentTranslation, parentRotation, parentScale);
 
 // Convert local point to parent point
 Vector3 parentPoint = M.MultiplyPoint3x4(localPoint);
 
 // Convert parent point back to local point
 Vector3 originalPoint = M.inverse.MultiplyPoint3x4(parentPoint);




Does not work:

 parentScale = new Vector3(1,1,0);
 
 // Create a transformation matrix for parent
 Matrix4x4 M = Matrix4x4.TRS(parentTranslation, parentRotation, parentScale);
 
 // Convert local point to parent point
 Vector3 parentPoint = M.MultiplyPoint3x4(localPoint);
 
 // Convert parent point back to local point
 Vector3 originalPoint = M.inverse.MultiplyPoint3x4(parentPoint);
 
 // originalPoint is always Vector3.Zero



I notice that in unity the Transform.worldToLocalMatrix and Transform.localToWorldMatrix don’t have that issue. If you have a gameobjet on the scene, that is not a child of another object, then Transform.worldToLocalMatrix is the inverse of Transform.localToWorldMatrix when you have a non-zero scale. If you set the scale of your game object to zero then Transform.worldToLocalMatrix is not the inverse of Transform.localToWorldMatrix but is not a zero matrix either.

Does anyone know how unity generates Transform.worldToLocalMatrix or Transform.localToWorldMatrix or how to generate an inverse matrix that has zero scale? Thanks in advance.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image smnerat · May 25, 2013 at 03:28 AM 0
Share

How do get a 4 X 4 matrix in unity?

avatar image RSG · May 25, 2013 at 04:22 AM 0
Share

You can create a transform matrix by using the $$anonymous$$atrix4x4.TRS function.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by smnerat · May 25, 2013 at 03:59 PM

Hmm, I was just wondering what the fourth entry is, time? Either way I can only answer part of the question.

A matrix is invertible if the determinant is non zero. Which is usually not the case. But to get a zero scale you would have to multiply a [4 X 4] matrix by a [1 X 4] matrix filled with zero, which will give you a matrix with a scale of zero. I don't think this is the problem.

I think the problem occurs when you try and invert a matrix with a zero scale because you probably end up with a scaled [4 X 4] matrix with a determinant that is equal to zero. So when computing the inverse of the matrix you end up trying to divide by zero. Which is why you don't get an inverted matrix or a zero matrix.

I can't help when it comes to figuring out how Unity calculates matrices.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

14 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Calculation behind camera.ScreenToWorldPoint 0 Answers

InverseTransformPoint via Matrices? 2 Answers

Matrix rotation of a Vector3 around three planes of rotation 1 Answer

Why Matrix4x4.MultiplyPoint does row-major access while Matrix4x4 is column-major? 1 Answer

Creating a Matrix4x4 from an Object's Transform 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges