Skip Navigation

Are Transform3D's commutative?

As in, for any two Transform3D objects A and B i might encounter does Godot (4.1) always return A * B == B * A as true? Alternatively is it approximately commutative, ie (A * B).is_equal_approx(B * A), in case there are situations where floating point imprecision messes the exact equality up.

4
4 comments
  • Ok so it seems like they don't commute? I asked the question in part because i wanted to do something like:

    const base_transform : Transform3D = 
    
    func get_base_transform(node : Node3D) -> Transform3D:
        return node.transform * base_transform
    
    func set_base_transform(node : Node3D, transform : Transform3D) -> void:
        node.transform = base_transform.affine_inverse() * node.transform
    

    and i wanted to be sure that if i do set_base_transform(some_node, some_transform) i'd be guaranteed to get that get_base_transform(some_node) == some_transform afterwards. But when i tried it the above code did not work out, at least i didnt get the result i expected. But when i flipped it so that set_base_transform did node.transform = node.transform * base_transform.affine_inverse() instead it did work out. Its still not hard proof though, maybe something else was messed up the first time, or it only looks like it works now and i'll discover the transform still isn't what i wanted it to be. Or they do commute but only under some constriction like no scale on any axis or something and i just happened to fulfill it with all the ones i used in my test.

    So it would still be good to know for sure whether/when Transform3D's commute.

    EDIT: I accidentally wrote the first line wrong, it said that they do commute. When actually the experience i had with it working only after both functions did their multiplications in a compatible order should indicate that they don't commute.