1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
| Point* findCloestPoint(QVector<Point>& initialPoints) {
static Point cloestPoints[2]; Point p1 = initialPoints[0]; Point p2 = initialPoints[1]; int index1 = 0; int index2 = 1; double mindis = p1.cal_distence(p2); for (int i = 1; i < initialPoints.size() - 1; i++) { for (int j = i + 1; j < initialPoints.size(); j++) { double tempdis = initialPoints[i].cal_distence(initialPoints[j]); if (mindis > tempdis) { p1 = initialPoints[i]; p2 = initialPoints[j]; index1 = i; index2 = j; mindis = tempdis; } } } cloestPoints[0] = p1; cloestPoints[1] = p2; initialPoints.erase(initialPoints.begin() + index1); initialPoints.erase(initialPoints.begin() + index2 - 1); return cloestPoints; }
void MainInterface::findFirstTIN(Point& p1, Point& p2, QVector<Point>& v) { MyVector mv1, mv2; int index = 0; mv1 = MyVector(p1, v[0]); mv2 = MyVector(p2, v[0]); double cos00 = mv1.cal_number(mv2) / (mv1.length * mv2.length); for (int i = 1; i < v.size(); i++) { mv1 = MyVector(p1, v[i]); mv2 = MyVector(p2, v[i]); double cos0 = mv1.cal_number(mv2) / (mv1.length * mv2.length); if (cos0 < cos00) { cos00 = cos0; index = i; } } Line line1 = Line(p1, p2, v[index], 1); Line line2 = Line(p1, v[index], p2, 1); Line line3 = Line(p2, v[index], p1, 1); m_allline = { line1, line2, line3 }; m_baseline = { line1, line2, line3 }; qDebug() << "三角形总边数为:" << m_allline.size(); }
LineInfo lineUsedCount(Line& line, QVector<Line>& v) { LineInfo lineinfo; for (int i = 0; i < v.size(); i++) { if (line == v[i]) { if (v[i].flag == 2) { lineinfo.count = 2; lineinfo.index = i; return lineinfo; } else { lineinfo.count = 1; lineinfo.index = i; return lineinfo; } } } lineinfo.count = 0; lineinfo.index = -1; return lineinfo; }
void creatTIN(QVector<Line>& va, QVector<Line>& vb, QVector<Point>& vp) { while (vb.size()) { Line baseline = vb[0]; if (lineUsedCount(baseline, va).count == 2) { vb.erase(vb.begin()); continue; } while (true) { std::vector<Point> potentialpt; double re1 = MyVector(baseline.startpt, baseline.endpt).cal_vector(MyVector(baseline.startpt, baseline.sametinpt)); for (int i = 0; i < vp.size(); i++) { double re2 = MyVector(baseline.startpt, baseline.endpt).cal_vector(MyVector(baseline.startpt, vp[i])); if (re1 * re2 < 0) { potentialpt.push_back(vp[i]); } } if (potentialpt.size() == 0) { vb.erase(vb.begin()); break; } MyVector mv1, mv2; int index = 0; mv1 = MyVector(baseline.startpt, potentialpt[0]); mv2 = MyVector(baseline.endpt, potentialpt[0]); double cos00 = mv1.cal_number(mv2) / (mv1.length * mv2.length); for (int i = 1; i < potentialpt.size(); i++) { mv1 = MyVector(baseline.startpt, potentialpt[i]); mv2 = MyVector(baseline.endpt, potentialpt[i]); double cos0 = mv1.cal_number(mv2) / (mv1.length * mv2.length); if (cos0 < cos00) { cos00 = cos0; index = i; } } Line newl1 = Line(baseline.startpt, potentialpt[index], baseline.endpt, 1); Line newl2 = Line(baseline.endpt, potentialpt[index], baseline.startpt, 1); LineInfo info1 = lineUsedCount(newl1, va); if (info1.count == 0) { va.push_back(newl1); vb.push_back(newl1); } else { vb.push_back(newl1); va[info1.index].flag = 2; } LineInfo info2 = lineUsedCount(newl2, va); if (info2.count == 0) { va.push_back(newl2); vb.push_back(newl2); } else { vb.push_back(newl2); va[info2.index].flag = 2; } va[lineUsedCount(baseline, va).index].flag = 2; vb.erase(vb.begin()); break; } } qDebug() << "建网结束!"; }
|