py3dframe.Frame.from_dict#

classmethod Frame.from_dict(data)[source]#

Load the Frame object from a dictionary.

The dictionary has the following structure:

{
    "package": "py3dframe",
    "class": "Frame",
    "version": __version__,
    "translation": [float, float, float],
    "quaternion": [float, float, float, float],
    "rotation_vector": [float, float, float],
    "rotation_matrix": [[float, float, float], [float, float, float], [float, float, float]],
    "euler_angles": [float, float, float],
    "convention": int
}
  • The quaternion is given in WXYZ format (scalar first).

  • The rotation vector is given in radians.

  • The Euler angles are given in radians and the axes are “xyz”.

  • The rotation is given in the convention of the frame.

  • The translation vector is given in the convention of the frame.

See also

Note

Only one of the rotation keys is needed to reconstruct the frame. The reader chooses the key to use in the following order of preference if several are given:

  • quaternion

  • rotation_vector

  • rotation_matrix

  • euler_angles

Warning

euler_angles can raise a this warning :

  • UserWarning: Gimbal lock detected. Setting third angle to zero since it is not possible to uniquely determine all angles.

I recommand to not use it.

Warning

  • parent frame is not loaded (only local frame is saved), so the loaded frame must be reattached to the parent frame if needed. (See also FrameTree to save/load a system of frames).

Parameters:

data (Dict[str, Any]) – The dictionary containing the Frame object.

Returns:

The Frame object.

Return type:

Frame

Examples

Create a Frame object and save it to a dictionary using the default method (quaternion, rotation_vector, rotation_matrix):

from py3dframe import Frame
frame = Frame.from_axes(origin=[1, 2, 3], x_axis=[1, 0, 0], y_axis=[0, 1, 0], z_axis=[0, 0, 1], convention=0)
frame_dict = frame.to_dict()

# Reload the Frame object from the dictionary:

loaded_frame = Frame.from_dict(frame_dict)

Warning, the method no longer saves the parent frame. To save/load a system of frames, consider using the FrameTree class.

from py3dframe import Frame

parent = Frame.from_axes(origin=[0, 0, 0], x_axis=[1, 0, 0], y_axis=[0, 1, 0], z_axis=[0, 0, 1], convention=0)
child = Frame.from_axes(origin=[1, 0, 0], x_axis=[1, 0, 0], y_axis=[0, 1, 0], z_axis=[0, 0, 1], convention=0, parent=parent)

child_dict = child.to_dict(method=["quaternion", "rotation_vector"])
parent_dict = parent.to_dict(method=["quaternion", "rotation_vector"])

# Reload the frames from the dictionaries

loaded_parent = Frame.from_dict(parent_dict)
loaded_child = Frame.from_dict(child_dict)
loaded_child.parent = loaded_parent # IMPORTANT