// 判断点pt是否在线段ab上 GEOMAPI bool mgIsBetweenLine2( const Point2d& a, const Point2d& b, const Point2d& pt, const Tol& tol) { if (!mgIsColinear2(a, b, pt, tol)) return false; // If ab not vertical, check betweenness on x; else on y. if (a.x != b.x) { return ((a.x <= pt.x + tol.equalPoint()) && (pt.x <= b.x + tol.equalPoint())) || ((a.x >= pt.x - tol.equalPoint()) && (pt.x >= b.x - tol.equalPoint())); } else { return ((a.y <= pt.y + tol.equalPoint()) && (pt.y <= b.y + tol.equalPoint())) || ((a.y >= pt.y - tol.equalPoint()) && (pt.y >= b.y - tol.equalPoint())); } }
bool mglnrel::isColinear2( const Point2d& a, const Point2d& b, const Point2d& pt, const Tol& tol) { float dist = (b-a).crossProduct(pt-a); return fabsf(dist) < tol.equalPoint(); }
bool mglnrel::isLeftOn2( const Point2d& a, const Point2d& b, const Point2d& pt, const Tol& tol) { float dist = (b-a).distanceToVector(pt-a); return dist > -tol.equalPoint(); }
int main(int argc, char ** argv) { Tol t { argc, argv }; return t.Run(); }
// 判断两个矢量是否平行 bool Vector2d::isParallelTo(const Vector2d& vec, const Tol& tol) const { float cosfz = dotProduct(vec); float sinfz = crossProduct(vec); return (fabsf(sinfz) <= fabsf(cosfz) * tol.equalVector()); }
bool Matrix2d::isEqualTo(const Matrix2d& mat, const Tol& tol) const { return mgHypot(m11 - mat.m11, m12 - mat.m12) <= tol.equalVector() && mgHypot(m21 - mat.m21, m22 - mat.m22) <= tol.equalVector() && mgHypot(dx - mat.dx, dy - mat.dy) <= tol.equalVector(); }
// 判断点pt是否在有向直线a->b的左边 GEOMAPI bool mgIsLeft2( const Point2d& a, const Point2d& b, const Point2d& pt, const Tol& tol) { float dist = (b-a).distanceToVector(pt-a); return dist > tol.equalPoint(); }