Hinge matching algorithm