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
1
Question by Schnodahipfe · Jan 20, 2014 at 12:38 PM · scaletranslatecoordinatesmappingtransformation

Mapping from External to Unity World Coordinates

I get 3D coordinates from an external device. Can someone tell me, how I can construct a matrix or use existing Unity functions (preferably) to map 3D points from the external coordinate system to Unity's 3D world coordinate system?

The device's coordinate system is left handed like Unity's and oriented the same way (i.e. the device's x-axis is parallel to Unity's x-axis and so on), so there would be no rotation necessary. The origins are in different places and the scales of the coordinate systems are different, however.

Does anyone know, how I can construct a mapping if I only have a set of corresponding pairs of points (my guess is I would need three pairs like "point a in the device's coordinate system, corresponds to point a* in Unity's world coordinate system").

Cheers

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Bunny83 · Jan 20, 2014 at 12:56 PM

Just create a Matrix4x4 with your desired values:

     Vector3 position = new Vector3(XX,YY,ZZ);
     Vector3 scale = Vector3.one * scale;
     // or
     //Vector3 scale = new Vector3(scaleX,scaleY,scaleZ);
     
     Matrix4x4 mat = Matrix4x4.TRS(position, Quaternion.identity, scale);

edit
If you don't have any rotation you can also manually scale / transform the points:

 Vector3 Map(Vector3 aPos)
 {
     aPos *= scale;
     aPos += position;
     return aPos;
 }

2. edit

As final alternative you can simply create an empty gameobject, move it where your "new" origin of your external position should be and change the scale ot the object. All childs can be placed at the incoming external coordinates (localPosition) and to read the unity world position just read ".position".

With this approach you get the transformation matrix for free since the Transform component calculates it for you. You can also use TransformPoint and InverseTransformPoint to convert a position from one space to the other.

Comment
Add comment · Show 2 · 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
avatar image Schnodahipfe · Jan 20, 2014 at 01:43 PM 0
Share

Thanks a bunch! How would I get the scale factor and the position/translation vector? Would the following be correct?

  1. Calculate the scale as Vector3.Distance (a*, b*) / Vector3.Distance (a, b) (with a and b being the original points and a* and b* being the corresponding points in the target system).

  2. Scale a with the calculated factor to get a'. Use a* - a' as the position/translation vector.

avatar image Schnodahipfe · Jan 20, 2014 at 04:31 PM 0
Share

Tried it and it worked (with the scale and translation calculated as in the above comment)! Thanks a lot!

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

20 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The translate is located in the wrong position. 0 Answers

Objects that have been scaled have weird X, Y, Z value in the Scene Editor 2 Answers

Extraction of Coordinate and Scaling it down by half. 1 Answer

Texture mapping, "false depth perception" 0 Answers

Center position after scale 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