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*.Index == 0 && i == 0)*

{
content = “setPositionXYZABC_” + (TransformList.localPosition.y * 1000) + “" + (TransformList.localPosition.x * (-1000)) + "” + (TransformList.localPosition.z * (-1000)) + "lin
";

}
//Text in das File einfügen
File.AppendAllText(path, content);
}_

}
It should looks like this:[151252-koordinatensysteme-iiwa.png|151252]
[151251-picture-model.png*|151251]*
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
*
*

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.

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.Math.Round(TCP.position.x * (-1000), 2);
double Y = System.Math.Round(TCP.position.y * 1000, 2);
double Z = System.Math.Round(TCP.position.z * (-1000), 2);
 double A = newObject.transform.eulerAngles.x;
              A = System.Math.Round(A, 2);
double B = newObject.transform.eulerAngles.y;
             B = System.Math.Round(B, 2);
double C = newObject.transform.eulerAngles.z;
             C = System.Math.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!