How to rotate joints/limbs like a real human would


My task is to transfer human motion to a model in threejs. I have a series of recorded positions of joints from a human motion. I’ve converted positions to rotations for respective joints/limbs, and applied to the 3d objects in the model.

As you can see in the .gif, the positions don’t contain the exact rotation of human body. There are constraints, such as the knees can not face backward, elbows can not face forward, etc. My questions is, how to express these constraints in geometry, and adjust the rotations calculated from positions, therefore make the model move like a real human would.

Suggestions are welcome