Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 solutionlab · Jan 14, 2020 at 01:33 PM · parentchildcoordinate-system

Coordinates relative to parent (root)

Hey guys, I need the coordinates from child "TCP" relative to its parent "Kuka_iiwa" (root). At the Moment I am creating an object and taking the coordinates from TCP (Tool Center Point):

                Trajektory.Add(new Trajektory(TCP.position.x, TCP.position.y, TCP.position.z, TCP.rotation.x, TCP.rotation.y, TCP.rotation.z,));


Afterwards I create an .txt-File with all coordinates:

 public void CreateTextFile3()
     {
         
         string path = Application.dataPath + "/VRTeachIn_04.txt";
         if (File.Exists(path))
         {
             File.Delete(path);
         }
         
         for (int i = 0; i < Trajektory.Count; i++)
         {
 
            
             if (Trajektory[i].Index == 0 && i == 0)
             {
                 content = "setPositionXYZABC_" + (TransformList[i].localPosition.y * 1000) + "_" + (TransformList[i].localPosition.x * (-1000)) + "_" + (TransformList[i].localPosition.z * (-1000)) + "_lin \n";
             }
             //Text in das File einfügen
             File.AppendAllText(path, content);
         }
 
     }

It should looks like this:alt text alt text

Problem is that I don´t have the right values... I think that´s because of child and parent connection. For a better understanding there are two pictures.

Does anybody has an idea how I get the right values?

Kind regards, Stefan

picture-model.png (127.6 kB)
koordinatensysteme-iiwa.png (111.3 kB)
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
0

Answer by Bunny83 · Jan 14, 2020 at 02:25 PM

I think you have multiple issues here. First of all you just grab the world space position and rotation of the TCP object. So it's relative to the world origin and the world space orientation. If you want to get its position in the local space of the "basis frame" you have to use the transform component of that basis object and use its InverseTransformPoint method to convert from world to local space.


The next issue is that Unity is using a left handed coordinate system. The arrows you've drawn in your first image represent a right handed system. So you need to decide how you want / need to convert between the two coordinate systems if you need it in a right handed system.


Finally I you most likely did not realise that "TCP.rotation" does not represent euler angles. It's the rotation of the object as quaternion. You just grab the x,y and z component of the quaternion which doesn't make much sense since a quaternion is a 4 dimensional complex number so you're missing the "w" component. It's not clear what you need this data for. However if you wanted to store euler angles you have to use TCP.eulerAngles instead. Note that the eulerAngles are calculated from the quaternion representation and any sort of interpolation might not give you the desired results since eulerangles do not have a unique representation for the same orientation.


Finally keep in mind that Unity's horizontal plane is the X-Z plane and Y is pointing up. From the camera's perspective X goes right, Y goes up and Z goes into the scene.

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 Bunny83 · Jan 14, 2020 at 02:28 PM 0
Share

I just noticed you used "localPosition" in your later code. $$anonymous$$eep in $$anonymous$$d that localPosition is the position relative to the direct parent object. So it's the position within the coordinate system of the direct parent.

avatar image solutionlab · Jan 15, 2020 at 05:37 AM 0
Share

Hello @Bunny83 ,

Thank´s for your answer! Regarding the coordinate system problem: as you can see I change the direction of z and also have a different order when write it to .txt-File. But Thanks for the hint.


Regarding "TCP.rotation": after I read your answer for the first time I changed it and also added the calculation for changing the coordinate system:

 double X = System.$$anonymous$$ath.Round(TCP.position.x * (-1000), 2);
 double Y = System.$$anonymous$$ath.Round(TCP.position.y * 1000, 2);
 double Z = System.$$anonymous$$ath.Round(TCP.position.z * (-1000), 2);
  double A = newObject.transform.eulerAngles.x;
               A = System.$$anonymous$$ath.Round(A, 2);
 double B = newObject.transform.eulerAngles.y;
              B = System.$$anonymous$$ath.Round(B, 2);
 double C = newObject.transform.eulerAngles.z;
              C = System.$$anonymous$$ath.Round(C, 2);




Finally your first/last point: "you have to use the transform component of that basis object and use its InverseTransformPoint method to convert from world to local space" Could you please make an example of that?


I am very thankful for your help, Thanks!

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

119 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 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 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 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 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 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

Make a simple tree 1 Answer

[C#] How do I instantiate multiple objects at the same time? 1 Answer

Check if there is a child of object, and if so, get tag? 2 Answers

How to make a child transform not move relative to parent? 1 Answer

Detach child and add force 0 Answers


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