rendered paste bodytemplate <class T>struct vector3{ T x, y, z; vector3(): x(), y(), z() {} vector3(T _x, T _y, T _z): x(_x), y(_y), z(_z) {} vector3<T> operator+(vector3<T> rhs) { return vector3<T>(x + rhs.x, y + rhs.y, z + rhs.z); } vector3<T> operator-(vector3<T> rhs) { return vector3<T>(x - rhs.x, y - rhs.y, z - rhs.z); }};template <class T>bool intersect(vector3<T> pa1, vector3<T> pa2, vector3<T> pb1, vector3<T> pb2){ vector3<T> va = pa2 - pa1, vb = pb2 - pb1, vc = pb1 - pa1; T _aybx = va.y * vb.x, _aycx = va.y * vc.x, _bycx = vb.y * vc.x, _axcy = va.x * vc.y, _bxcy = vb.x * vc.y; T det = va.z * (_bycx - _bxcy - vb.y * vb.y) + vb.z * (_axcy - _aycx) + vc.z * _aybx; if (det > T(1e-8) || det < T(-1e-8)) throw std::domain_error("pa1-pa2 and pb1-pb2 is not in same plane"); T _denom = T(1) / (_aybx - _axby); T ta = (_bxcy - _bycx) * _denom, tb = (_aycx - _axcy) * _denom; return (T(0) <= ta && ta <= T(1) && T(0) <= tb && tb = T(1));}