py3dframe.Frame.get_global_frame#
- Frame.get_global_frame()[source]#
Get the global frame of the frame. The representation of the frame with respect to the global canonical frame.
If the frame has no parent, the global frame is the frame itself.
Otherwise, the global frame is computed by composing the transformation between the global frame and the parent frame with the transformation between the parent frame and this frame.
Note
The parent attribute of the global frame is None.
Warning
The Frame object is a new object. Any change in the returned object will not affect the original object. Furthermore, any change in the original object will not affect the returned object. It describes the frame at the state of the call.
- Returns:
The global frame of the frame.
- Return type:
Examples
Lets consider a train and a person standing into the train.
First we can define the train frame relative to the global frame (the canonical frame) and then we can define the person frame relative to the train frame.
from py3dframe import Frame train = Frame.from_axes(origin=[0, 0, 0], x_axis=[1, 0, 0], y_axis=[0, 1, 0], z_axis=[0, 0, 1], parent=None) person = Frame.from_axes(origin=[0, 1, 0], x_axis=[1, 0, 0], y_axis=[0, 1, 0], z_axis=[0, 0, 1], parent=train)
Lets assume the train moves and the person moves inside the train.
train.set_translation([10, 0, 0], convention=0) # The train moves of 10 units along the x axis of the global frame. person.set_translation([0, 2, 0], convention=0) # The person moves by 1 unit along the y axis of the train frame. person.set_euler_angles([0, 0, 45], convention=0, degrees=True) # The person rotates of 45 degrees around the z axis of the train frame.
We can determine the orientation and position of the person relative to the global frame at any time using the
get_global_frame()method:global_person = person.get_global_frame() # Get the global frame of the person. print("Person origin in the global frame:", global_person.origin) print("Person x axis in the global frame:", global_person.x_axis) print("Person y axis in the global frame:", global_person.y_axis) print("Person z axis in the global frame:", global_person.z_axis) # Output: # Person origin in the global frame: [[10] [2] [0]] # Person x axis in the global frame: [[ 0.70710678] [ 0.70710678] [ 0. ]] # Person y axis in the global frame: [[-0.70710678] [ 0.70710678] [0. ]] # Person z axis in the global frame: [[0.] [0.] [1.]]