Commit 5f6b6df7 authored by Valentin Platzgummer's avatar Valentin Platzgummer

befor changeing circular survey

parent 6ac2e382
...@@ -115,36 +115,71 @@ QList<QPointF> Circle::approximateSektor(int numberOfCorners, double alpha1, dou ...@@ -115,36 +115,71 @@ QList<QPointF> Circle::approximateSektor(int numberOfCorners, double alpha1, dou
QList<QPointF> Circle::approximateSektor(double angleDiscretisation, double alpha1, double alpha2) const QList<QPointF> Circle::approximateSektor(double angleDiscretisation, double alpha1, double alpha2) const
{ {
using namespace PlanimetryCalculus; using namespace PlanimetryCalculus;
// truncate alpha1 to [0, 2*pi], fmod() does not work in this case // check if input is valid
if ( qFuzzyCompare(alpha1, alpha2) )
return QList<QPointF>();
alpha1 = truncateAngle(alpha1); alpha1 = truncateAngle(alpha1);
alpha2 = truncateAngle(alpha2); alpha2 = truncateAngle(alpha2);
double deltaAlpha = truncateAngle(alpha2 - alpha1); double deltaAlpha = fabs(alpha1 - alpha2);
angleDiscretisation = truncateAngle(angleDiscretisation)*signum(angleDiscretisation); if (signum(angleDiscretisation*(alpha1 - alpha2)) == 1) {
deltaAlpha = 2*M_PI - deltaAlpha;
}
if (fabs(angleDiscretisation) > deltaAlpha || qFuzzyIsNull(angleDiscretisation)) // check if input is valid
if ( fabs(angleDiscretisation) > fabs(deltaAlpha)
|| qFuzzyIsNull(angleDiscretisation))
return QList<QPointF>(); return QList<QPointF>();
QList<QPointF> sector; QList<QPointF> sector;
QPointF vertex0(_circleRadius,0); // initial vertex
double currentAngle = alpha1; double currentAngle = alpha1;
// rotate the vertex numberOfCorners-1 times add the origin and append to the polygon. // how many nodes?
int j = floor(fabs(deltaAlpha/angleDiscretisation));
// rotate the vertex j+1 times add the origin and append to the sector.
do { do {
QPointF currentVertex = rotateReturn(vertex0, currentAngle); sector.append(toCoordinate(currentAngle));
sector.append(currentVertex + _circleOrigin); currentAngle = truncateAngle(currentAngle + angleDiscretisation);
currentAngle = PlanimetryCalculus::truncateAngle(currentAngle + angleDiscretisation); }while(j--);
}while(currentAngle < alpha2);
// append last point if necessarry // append last point if necessarry
QPointF currentVertex = rotateReturn(vertex0, alpha2) + _circleOrigin; QPointF vertex = toCoordinate(alpha2);
if ( !qFuzzyIsNull(PlanimetryCalculus::distance(sector.first(), currentVertex)) if ( !qFuzzyIsNull(PlanimetryCalculus::distance(sector.first(), vertex))
&& !qFuzzyIsNull(PlanimetryCalculus::distance(sector.last(), currentVertex )) ){ && !qFuzzyIsNull(PlanimetryCalculus::distance(sector.last(), vertex )) ){
sector.append(currentVertex); sector.append(vertex);
} }
return sector; return sector;
} }
/*!
* \fn void Circle::toCoordinate(QPointF &coordinate, double alpha) const
* Calculates the coordinates of a point on the circle with angle \a alpha.
* Stores the result in \a coordiante.
*
* \sa QPointF
*/
void Circle::toCoordinate(QPointF &coordinate, double alpha) const
{
using namespace PlanimetryCalculus;
coordinate = QPointF(_circleRadius,0);
rotateReference(coordinate, alpha);
coordinate += _circleOrigin;
}
/*!
* \overload QPointF Circle::toCoordinate(double alpha) const
* Returns the coordinates of a point on the circle with angle \a alpha.
*
* \sa QPointF
*/
QPointF Circle::toCoordinate(double alpha) const
{
QPointF coordinate;
toCoordinate(coordinate, alpha);
return coordinate;
}
bool Circle::isNull() const bool Circle::isNull() const
{ {
return _circleRadius <= 0 ? true : false; return _circleRadius <= 0 ? true : false;
......
...@@ -31,6 +31,8 @@ public: ...@@ -31,6 +31,8 @@ public:
QList<QPointF> approximate (double angleDiscretisation) const; QList<QPointF> approximate (double angleDiscretisation) const;
QList<QPointF> approximateSektor(int numberOfCorners, double alpha1, double alpha2) const; QList<QPointF> approximateSektor(int numberOfCorners, double alpha1, double alpha2) const;
QList<QPointF> approximateSektor(double angleDiscretisation, double alpha1, double alpha2) const; QList<QPointF> approximateSektor(double angleDiscretisation, double alpha1, double alpha2) const;
void toCoordinate (QPointF &toCoordinate, double alpha) const;
QPointF toCoordinate (double alpha) const;
bool isNull() const; bool isNull() const;
signals: signals:
......
...@@ -102,9 +102,9 @@ void CircularSurveyComplexItem::_rebuildTransectsPhase1() ...@@ -102,9 +102,9 @@ void CircularSurveyComplexItem::_rebuildTransectsPhase1()
} }
} }
qWarning("r_min, r_max:"); // qWarning("r_min, r_max:");
qWarning() << r_min; // qWarning() << r_min;
qWarning() << r_max; // qWarning() << r_max;
QList<QPolygonF> convexPolygons; QList<QPolygonF> convexPolygons;
decomposeToConvex(surveyPolygon, convexPolygons); decomposeToConvex(surveyPolygon, convexPolygons);
...@@ -116,44 +116,58 @@ void CircularSurveyComplexItem::_rebuildTransectsPhase1() ...@@ -116,44 +116,58 @@ void CircularSurveyComplexItem::_rebuildTransectsPhase1()
QList<QList<QPointF>> currPolyPath; QList<QList<QPointF>> currPolyPath;
bool currentPolyPathUpdated = false; bool currentPolyPathUpdated = false;
int direction = 1;
while (r < r_max) { while (r < r_max) {
Circle circle(r, origin); Circle circle(r, origin);
QList<QPointFList> intersectPoints; QList<QPointFList> intersectPoints;
QList<IntersectType> typeList; QList<IntersectType> typeList;
if (intersects(circle, polygon, intersectPoints, typeList)) { QList<QPair<int, int>> neighbourList;
if (intersects(circle, polygon, intersectPoints, neighbourList, typeList)) {
if (intersectPoints.size() >= 1) { if (intersectPoints.size() >= 1) {
// continue here
QPointF p1 = intersectPoints.first()[0]; for (int i = 0; i < intersectPoints.size(); i++) {
QPointF p2 = intersectPoints.first()[1]; QList<QPointF> intersects = intersectPoints[i];
double beta1 = angle(p1);
double beta2 = angle(p2); QPointF p1 = polygon[neighbourList[i].first];
double alpha1 = fmin(beta1, beta2); QPointF p2 = polygon[neighbourList[i].second];
double alpha2 = fmax(beta1, beta2); QLineF intersetLine(p1, p2);
double lineAngle = truncateAngle(angle(intersetLine));
QList<QPointF> sector = circle.approximateSektor(direction*dalpha, alpha1, alpha2);
QList<QPointF> sectorPath; double alpha1 = 0;
for ( const QPointF &p : sector) { bool skip = true;
if (polygon.containsPoint(p, Qt::FillRule::OddEvenFill)) QPointF vertex;
sectorPath.append(p); for (QPointF ipt : intersects) {
double circleTangentAngle = truncateAngle(angle(ipt)+M_PI_2);
if (lineAngle > circleTangentAngle && lineAngle < circleTangentAngle + M_PI) {
alpha1 = truncateAngle(circleTangentAngle-M_PI_2);
vertex = ipt;
skip = false;
}
} }
if (sectorPath.size() > 0 ) {
if (direction == -1){ QList<QPointF> sectorPath;
direction = 1; // walk clockwisely along the circle, and break when leaving the polygon
} else if (!skip) {
direction = -1; double alpha = alpha1;
do {
sectorPath.append(vertex);
alpha += dalpha;
circle.toCoordinate(vertex, alpha);
} while (polygon.containsPoint(vertex, Qt::FillRule::OddEvenFill));
}
// use shortestPath() here if necessary, could be a problem if dr >> // use shortestPath() here if necessary, could be a problem if dr >>
currPolyPath.append(sectorPath); currPolyPath.append(sectorPath);
currentPolyPathUpdated = true; currentPolyPathUpdated = true;
} }
} }
} }
r += dr; r += dr;
} }
if (currentPolyPathUpdated) { if (currentPolyPathUpdated) {
if (fullPath.size() > 1) { if (fullPath.size() > 1) {
QPointF start = fullPath.last().last(); QPointF start = fullPath.last().last();
......
...@@ -532,13 +532,23 @@ bool WimaPlaner::recalcJoinedArea(QString &errorString) ...@@ -532,13 +532,23 @@ bool WimaPlaner::recalcJoinedArea(QString &errorString)
// join service area, op area and corridor // join service area, op area and corridor
// remove if debugging finished // // remove if debugging finished
WimaServiceArea *test = new WimaServiceArea(this); // WimaServiceArea *test = new WimaServiceArea(this);
Circle circle(25, this);
using namespace GeoUtilities; // WimaServiceArea *test1 = new WimaServiceArea(this);
// WimaServiceArea *test2 = new WimaServiceArea(this);
test->setPath(toGeo(circle.approximateSektor(10, -1, 1), _joinedArea.center())); // WimaServiceArea *test3 = new WimaServiceArea(this);
_visualItems.append(test); // Circle circle(25, this);
// using namespace GeoUtilities;
// test->setPath(toGeo(circle.approximateSektor(0.5, 1, 3), _joinedArea.center()));
// _visualItems.append(test);
// test1->setPath(toGeo(circle.approximateSektor(0.5, 1, -1), _joinedArea.center()));
// _visualItems.append(test1);
// test2->setPath(toGeo(circle.approximateSektor(0.5,-1, 3), _joinedArea.center()));
// _visualItems.append(test2);
// test3->setPath(toGeo(circle.approximateSektor(0.5, -1, -3), _joinedArea.center()));
// _visualItems.append(test3);
return true; return true;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment