// t = xT(p2-p1) - p1T(p2-p1) / (p2-p1)T(p2-p1)
// t = (x-p1)T(p2-p1) / |(p2-p1)|^2
final Vector3 p2p1 = p2.sub(p1);
p2p1.z = 0; // we only work in the xy plane
final double t = x.sub(p1).dot(p2p1) / p2p1.squaredNorm();
if (t>= -epsilon && t <= 1+epsilon) {
// closest point on line
Vector3 lp = p1.add(p2.sub(p1).multiply(t));
if ( lp.sub(x).xynorm() < epsilon ) {
intPoint.assign(lp);