cross clear for size_t lines size -1 x1 lines y1 lines x2 lines y2 lin

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
cross.clear();
for (size_t i=0;i<lines.size()-1;++i) {
x1 = lines[i].x; y1 = lines[i].y;
x2 = lines[i+1].x; y2 = lines[i+1].y;
x3 = x1Pos; y3 = y1Pos;
x4 = x2Pos; y4 = y2Pos;
yp = ((x3*y4 - x4*y3)*(y2 - y1) - (x1*y2 - x2*y1)*(y4 - y3)) / ((x2 - x1)*(y4-y3) - (x4 - x3)*(y2 - y1)) ;
xp = ((y3*x4 - y4*x3)*(x2 - x1) - (y1*x2 - y2*x1)*(x4 - x3)) / ((y2 - y1)*(x4-x3) - (y4 - y3)*(x2 - x1)) ;
double A, B, C, d;
A = y4 - y3;
B = x3 - x4;
C = y3*x4 - x3*y4;
d = abs(A*xp + B*yp + C)/sqrt(A*A + B*B);
if (d==0) cross.push_back(wxPoint((int)xp,(int)yp));
}