A robust mathematical model for knot tying simulation and knot identification