此曲线由这些点组成。我想知道红线是否与曲线相交。红线由PointA和PointB组成。我该怎么办?
答案 0 :(得分:0)
struct pos
{
double x ;
double y ;
};
struct line
{
pos st ;
pos end ;
};
int n ;
double Multiply(pos p1, pos p2, pos p0)
{
return ( (p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y) );
}
bool iscross(line L1, line L2)
{
return( (max(L1.st.x, L1.end.x) >= min(L2.st.x, L2.end.x)) &&
(max(L2.st.x, L2.end.x) >= min(L1.st.x, L1.end.x)) &&
(max(L1.st.y, L1.end.y) >= min(L2.st.y, L2.end.y)) &&
(max(L2.st.y, L2.end.y) >= min(L1.st.y, L1.end.y)) &&
(Multiply(L2.st, L1.end, L1.st) * Multiply(L1.end, L2.end, L1.st) >= 0) &&
(Multiply(L1.st, L2.end, L2.st) * Multiply(L2.end, L1.end, L2.st) >= 0)
);
}