/ * A basic concept base point: is the coordinate point where the selected picture is in. Straight line: It is the X-direction and Y to the axis of the base point, but there is a length range, in fact, a line segment, the middle is the assumption. Path: Composed of some connected lines, not more than three straight lines. II Specific Thoughts 1, first obtain the base points P1, P2 in two selected pictures. 2, establish a straight line of P1 and P2, with up to four. 3. Judgment the relationship between the base points P1 and P2. 4. If two base points are on the same straight line, they can be directly connected to a path to generate a path. 5, not on the same line. At this point, it is also necessary to determine whether the straight line of P1 and P2 intersects. If there is intersect, it can also directly form a pathway. If you do not intersect, you need another straight line to form a path and can only add a straight line. Look for two straight lines in parallel, start every point of the vertical line from one end of a straight line, see if it is intersecting another line, if you intersect, you get a new path. If there is no intersection, it means that the two base points cannot be connected. In this way, the other two lines can also be searched over again to know if the two base points can be connected. * /// Lianlian connection path detection algorithm
// # include
INT Main () {// Map Set Short Mapx = 6, MAPY = 5; // (To Improve) Horizontal Variation Short Map [5] [6] = {0, 0, 0, 0, 0, 0, 0, 1, 3, 2, 3, 0, 0, 2, 2, 1, 2, 0, 0, 1, 3, 1, 3, 0, 0, 0, 0, 0, 0, 0) ;
/ / Set the selected coordinate // (To improve) To detect whether the position is the same, the value is the same Short set1x = 4, set1y = 1, set2x = 2, set2y = 3;
// Process // Longitudinal Processing // Cache Initial // (To Improve) Cache Length Short Set1Bufy [6] [2] = {0, 0, 0, 0, 0, 0, 0, 0, 0 , 0, 0, 0}; Short set2bufy [6] [2] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
// Based on the cache set1bufy [0] [0] = set1x; set1bufy [0] [1] = set1Y; set2bufy [0] [0] = set2x; set2bufy [0] [1] = set2y; // longitudinal detection : Basic point 1 SHORT NBUFY = 1; for (short tmpy = set1y - 1; tmpy> = 0; --TMPY) {if (MAP [TMPY] [set1x] == 0) {set1bufy [nbufy] [0] = Set1x; set1bufy [nbufy] [1] = tmpy; nbufy;} else {breaf;}}}
// Longitudinal detection: base point 1 below for (short tmpy = set1y 1; tmpy
// Longitudinal detection: base point 2 below for (short tmpy = set2y 1; tmpy // Longitudinal detection: Transverse path detection // communication flag BOOL BCHKOK = FALSE; for (Short nchklink1 = 0 ;! (set1bufy [nchklink1] [0] == 0 && set1bufy [nchklink1] [1] == 0); nchklink1) {// Set the coaxial contrast acceleration check mark BOOL bshortpass = false; // debug // cout << "Enter x for 1" << ENDL; For (Short nchklink2 = 0;! (set2bufy [nchklink2] [0] == 0 && set2bufy [nchklink2] [1] == 0); nchklink2) {// debug // cout << "Enter x for 2 << endl; // Detection whether it is in the same horizontal axis IF (set1bufy [nchklink1] [1] == set2bufy [nchklink2] [1]) {// Since the coaxial point has been checked, the coaxial contrast acceleration check mark is true bshortpass = True; // debug // cout << "Enter x for 2-if" << Endl; // Calculate the interpolation distance short nstep = set1bufy [nchklink1] [0] - set2bufy [nchklink2] [0]; // Offset Short OPNUM; IF (NSTEP> 0) {OPNUM = -1; --NSTEP; } Else {opnum = 1; nstep;} bchkok = true; short tmpvy = set1bufy [nchklink1] [1]; for (short mstep = nstep; mstep! = 0; mstep = opnum) {// debug // COUT << "Enter x for 3" << Endl; IF (MAP [Tmpvy] [set1bufy [nchklink1] [0] - mstep] == 0) {// Continue detection Next:} else {// pathway has an obstacle to connect BCHKOK = FALSE; BREAK;}} // If the passage is connected, the communication information IF (bchkok == true) {// cout << "Linked." << Endl; Printf ("% s", "limited / n"); RETURN 0;}}}}}}}}}}}}}}}}}}}}} The coaxial contrast acceleration check mark to implement inspection acceleration IF (bshortpass == true) {// debug // cout << "Enter short shortpass << ENDL; Break;}}}}} / / Longitudinal processing // Transverse processing // Cache initial // (To improve) The cache length should be able to set Short set1bufx [7] [2] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 , 0}; Short set2bufx [7] [2] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; // Based on the cache set1bufx [0] [0] = set1x; set1bufx [0] [1] = set1y; set2bufx [0] [0] = set2x; set2bufx [0] [1] = set2y; // lateral detection : Basic point 1 with left Short Nbufx = 1; for (short tmpx = set1x - 1; tmpx> = 0; --TMPX) {if (Map [set1y] [tmpx] == 0) {set1bufx [nbufx] [0] = TMPX; set1bufx [nbufx] [1] = set1y; nbufx;} else {breaf;}}} // Transverse detection: base point 1 with right for (short tmpx = set1x 1; tmpx // Transverse detection: Base point 2 with right for (short tmpx = set2x 1; tmpx // Transverse detection: longitudinal passage detection // communication flag BCHKOK = FALSE; for (Short nchklink1 = 0 ;! (set1bufx [nchklink1] [0] == 0 && set1bufx [nchklink1] [1] == 0); Nchklink1) {// Set the coaxial contrast acceleration check mark BOOL bshortpass = false; // debug // cout << "Enter x for 1" << ENDL; For (Short nchklink2 = 0;! (set2bufx [nchklink2] [0] == 0 && set2bufx [nchklink2] [1] == 0); nchklink2) {// debug // cout << "Enter x for 2 << endl; / / Detection whether it is in the same vertical axis IF (set1bufx [nchklink1] [0] == set2bufx [nchklink2] [0]) {// Since the coaxial point has been checked, the coaxial contrast acceleration check mark is true bshortpass = True; // debug // cout << "Enter x for 2-if" << Endl; // Calculate the interpolation distance short nstep = set1bufx [nchklink1] [1] - set2bufx [nchklink2] [1]; // Offset Short OPNUM; IF (NSTEP> 0) {OPNUM = -1; --NSTEP; } Else {opnum = 1; nStep;} bchkok = true; short tmpvx = set1bufx [nchklink1] [0]; for (short mstep = nstep; mstep! = 0; mstep = opnum) {// debug // COUT << "Enter x for 3" << Endl; IF (MAP [set1bufx [nchklink1] [1] - mstep] [TMPVX] == 0) {// Continue detection Next Continue;} else {// pathway has obstacles unable to connect BCHKOK = FALSE; BREAK;}} // If the path is connected, the communication information IF (bchkok == true) {// cout << "Linked." << endl; printf ("linked / n"); RETURN 0;}}}}}}}}}}}}}}}}}}}}} The coaxial contrast acceleration check mark to implement inspection acceleration IF (bshortpass == true) {// debug // cout << "Enter short shortpass << ENDL; Break;}}}}} // lateral processing // Processing process / / If the path cannot be connected, it is displayed that the information IF (bchkok == false) {// cout << "unlinked." << Endl; Printf ("% s", "unlinked / n");} Return 0;}