I'm trying to come up with a data structure for a following model: Nodes representing points in space are structured in a tree (general rooted tree with no restrictions). Let's call these nodes "joints". Joints contain information about their position and their axis of rotation: Whole subtrees may rotate around their parent joint's axis by any given angle.
The described tree can be treated as the input. I need to store this data in some data structure, that would provide these two operations as efficient as possible:
rotate(id, angle)
: Rotate a subtree under given joint bywith itsid
subtree by a givenangle
around its parent's axis.get_position(id)
: Retrieve the current position of a joint (including leaves) by itsid
.
(The id
may be the original coordinates, some arbitrary integer stored inside the joint etc.)
There are no strict limits on the time complexities of these operations. But obviously I'm looking for a complexity better than linear (logarithmic would be ideal), as that could be achieved with a straightforward approach. Neither there are any strict limits on space complexity. This structure doesn't have to be dynamic necessarily: I don't need insert
or delete
operations, I only need to store the information about the joints once.
The input tree is not balanced, and there is no way to balance it, as it would loose information about the subtrees' dependencies. So I thought the natural approach would be to construct a different tree structure with some relation other than simply parent node -> subtree
as joint -> joints dependent on its rotation
. But what relation could give me some good results?