tan1_2p: improved geometrical algorithm