我有一条直线(x1,y1)和(x2,y2).我想看看点(x3,y3)是否位于所述线的"左"或"右".我该怎么办?
可能重复:
如何检测两个线段相交的位置?
有人可以提供算法或C代码来确定两个线段是否相交?
我无法想出一种算法来检测弱的简单多边形(即允许边接触但不能交叉的多边形).目前我只是检查每一方之间的交叉点 - 这是我呼吁所有非相邻方的功能.这样,只允许简单的多边形(根本不接触).多边形是点的向量.
bool linesIntersect(const point &a1, const point &a2, const point &b1, const point &b2) {
// Solve intersection of parametric lines using inverse matrix
// The equation of the parametric lines are line1 = (a2 - a1)*s + a1
// and line2 = (b2 - b1)*t + b1, where a1, a2, etc. are vectors.
// Two equations can be produced from the two components, and these
// this system of two equations can be solved for s and …Run Code Online (Sandbox Code Playgroud)