Commit d61b7b13 authored by Valentin Platzgummer's avatar Valentin Platzgummer

planicalc and polycalc edited

parent 68512dd5
......@@ -127,13 +127,13 @@ QPolygonF Circle::approximateSektor(double angleDiscretisation, double alpha1, d
double currentAngle = alpha1;
// rotate the vertex numberOfCorners-1 times add the origin and append to the polygon.
while(currentAngle < alpha2) {
PlanimetryCalculus::rotatePoint(vertex, currentAngle);
PlanimetryCalculus::rotate(vertex, currentAngle);
polygon.append(vertex + _circleOrigin);
currentAngle = PlanimetryCalculus::truncateAngle(currentAngle + angleDiscretisation);
}
// append last point if necessarry
PlanimetryCalculus::rotatePoint(vertex, alpha2);
PlanimetryCalculus::rotate(vertex, alpha2);
vertex = vertex + _circleOrigin;
if ( !qFuzzyIsNull(PlanimetryCalculus::distance(polygon.first(), vertex))
&& !qFuzzyIsNull(PlanimetryCalculus::distance(polygon.last(), vertex )) ){
......
......@@ -19,7 +19,7 @@ namespace PlanimetryCalculus {
double angleWLDegree = line.angle(); // angle between wold and line coordinate system
QPointF originCircleL = circle.origin() - translationVector;
rotatePoint(originCircleL, -angleWLDegree); // circle origin in line corrdinate system
rotate(originCircleL, -angleWLDegree); // circle origin in line corrdinate system
double y = originCircleL.y();
double r = circle.radius();
......@@ -31,7 +31,7 @@ namespace PlanimetryCalculus {
if (x_ori >= 0 && x_ori <= line.length()) {
if (calcInstersect) {
QPointF intersectionPt = QPointF(x_ori, 0);
rotatePoint(intersectionPt, angleWLDegree);
rotate(intersectionPt, angleWLDegree);
intersectionPoints.append(intersectionPt + translationVector);
}
......@@ -50,7 +50,7 @@ namespace PlanimetryCalculus {
if (x1 >= 0 && x1 <= line.length()) { // check if intersection point is on the line
if (calcInstersect) {
QPointF intersectionPt = QPointF(x1, 0); // first intersection point (line system)
rotatePoint(intersectionPt, angleWLDegree);
rotate(intersectionPt, angleWLDegree);
intersectionPoints.append(intersectionPt + translationVector); // transform (to world system) and append first intersection point
}
doesIntersect = true;
......@@ -58,7 +58,7 @@ namespace PlanimetryCalculus {
if (x2 >= 0 && x2 <= line.length()) { // check if intersection point is on the line
if (calcInstersect) {
QPointF intersectionPt = QPointF(x2, 0); // second intersection point (line system)
rotatePoint(intersectionPt, angleWLDegree);
rotate(intersectionPt, angleWLDegree);
intersectionPoints.append(intersectionPt + translationVector); // transform (to world system) and append second intersection point
}
doesIntersect = true;
......@@ -76,7 +76,7 @@ namespace PlanimetryCalculus {
\fn void rotatePoint(QPointF &point, double alpha)
Rotates the \a point counter clockwisely by the angle \a alpha (in radiants).
*/
void rotatePoint(QPointF &point, double alpha)
void rotate(QPointF &point, double alpha)
{
if (!point.isNull()) {
double x = point.x();
......@@ -87,10 +87,10 @@ namespace PlanimetryCalculus {
}
}
void rotatePoint(QList<QPointF> &points, double alpha)
void rotate(QList<QPointF> &points, double alpha)
{
for (int i = 0; i < points.size(); i++) {
rotatePoint(points[i], alpha);
rotate(points[i], alpha);
}
}
......@@ -98,15 +98,15 @@ namespace PlanimetryCalculus {
\fn void rotatePointDegree(QPointF &point, double alpha)
Rotates the \a point counter clockwisely by the angle \a alpha (in degrees).
*/
void rotatePointDegree(QPointF &point, double alpha)
void rotateDegree(QPointF &point, double alpha)
{
rotatePoint(point, alpha/180*M_PI);
rotate(point, alpha/180*M_PI);
}
void rotatePointDegree(QList<QPointF> &points, double alpha)
void rotateDegree(QList<QPointF> &points, double alpha)
{
for (int i = 0; i < points.size(); i++) {
rotatePointDegree(points[i], alpha);
rotateDegree(points[i], alpha);
}
}
......@@ -211,7 +211,7 @@ namespace PlanimetryCalculus {
intersectionPoints.append(QPointF(x, -y));
}
// Transform the coordinate to the world coordinate system. Alpha is the angle between world and circle1 coordinate system.
rotatePoint(intersectionPoints, alpha);
rotate(intersectionPoints, alpha);
return returnValue;
}
......@@ -292,6 +292,97 @@ namespace PlanimetryCalculus {
}
/*!
* \fn IntersectType intersects(const QLineF &line1, const QLineF &line2, QPointF &intersectionPt);
* Determines wheter \a line1 and \a line2 intersect and of which type the intersection is.
* Stores the intersection point in \a intersectionPt
* Returns \c NoIntersection if no intersection occured, \c EdgeIntersection if a interisSelfIntersectingsection occured near a endpoint of a line (within epsilonMeter), or \c InteriorIntersection else.
*
* \sa QGeoCoordinate
*/
IntersectType intersects(const QLineF &line1, const QLineF &line2, QPointF &intersectionPt)
{
QPointF pt11(0, 0);
QPointF intersectionPoint;
// continue here
}
/*!
* \overload QList<IntersectionType> intersects(const QList<QGeoCoordinate> &polygon, const QList<QGeoCoordinate> &line, QList<QGeoCoordinate> &intersectionList, QList<QPair<int, int> > &neighbourList)
* Checks if \a polygon intersect with \a line.
* Stores the intersection points in \a intersectionList.
*
* Stores the indices of the closest two \a area vetices for each of coorespoinding intersection points in \a neighbourList. *
* For example if an intersection point is found between the first and the second vertex of the \a area the intersection point will
* be stored in \a intersectionList and the indices 1 and 2 will be stored in \a neighbourList.
* \a neighbourList has entries of type \c {QPair<int, int>}, where \c{pair.first} would contain 1 and \c{pair.second} would contain 2, when
* relating to the above example.
*
* Returns the \c IntersectionType of each intersection point within a QList.
*
* \sa QPair, QList
*/
QList<IntersectionType> intersects(const QList<QGeoCoordinate> &polygon, const Line &line, QList<QGeoCoordinate> &intersectionList, QList<QPair<int, int> > &neighbourList)
{
if (polygon.size() >= 3) { // are line a proper line and poly a proper poly?other,
intersectionList.clear();
neighbourList.clear();
QList<IntersectionType> intersectionTypeList;
// Assemble a line form each tow consecutive polygon vertices and check whether it intersects with line
for (int i = 0; i < polygon.size(); i++) {
Line interatorLine;
QGeoCoordinate currentVertex = polygon[i];
QGeoCoordinate nextVertex = polygon[nextPolygonIndex(polygon.size(), i)];
interatorLine.first = currentVertex;
interatorLine.second = nextVertex;
QGeoCoordinate intersectionPoint;
IntersectionType returnValue = intersects(line, interatorLine, intersectionPoint);
if ( returnValue == IntersectionType::EdgeIntersection
|| returnValue == IntersectionType::InteriorIntersection) {
intersectionList.append(intersectionPoint);
QPair<int, int> neighbours;
neighbours.first = i;
neighbours.second = nextPolygonIndex(polygon.size(), i);
neighbourList.append(neighbours);
intersectionTypeList.append(returnValue);
}
}
if (intersectionList.count() > 0) {
return intersectionTypeList;
} else {
return QList<IntersectionType>();
}
} else {
qWarning("WimaArea::intersects(line, poly): line->count() != 2 || poly->count() < 3");
return QList<IntersectionType>();
}
}
/*!
* \overload bool intersects(const QList<QGeoCoordinate> &polygon, const QList<QGeoCoordinate> &line)
* Returns \c true if any intersection between \a polygon and \a line exists, \c false else.
*
* \sa QPair, QList
*/
bool intersects(const QList<QGeoCoordinate> &polygon, const Line &line)
{
QList<QGeoCoordinate> dummyGeo;
QList<QPair<int, int>> dummyNeighbour;
intersects(polygon, line, dummyGeo, dummyNeighbour);
if (dummyGeo.size() > 0)
return true;
return false;
}
} // end namespace PlanimetryCalculus
......
......@@ -2,6 +2,7 @@
#include <QLineF>
#include <QPointF>
#include <QPolygonF>
#include <QtMath>
#include <QLineF>
......@@ -15,17 +16,30 @@ namespace PlanimetryCalculus {
NoIntersection, Tangent, Secant, // Circle Line Intersetion
EdgeCornerIntersection, EdgeEdgeIntersection, CornerCornerIntersection,
LinesParallel, LinesEqual, // Line Line intersection
Error // general
};
void rotatePoint(QPointF &point, double alpha);
void rotatePoint(QList<QPointF> &point, double alpha);
void rotatePointDegree(QPointF &point, double alpha);
void rotatePointDegree(QList<QPointF> &points, double alpha);
void rotate(QPointF &point, double alpha);
void rotate(QList<QPointF> &point, double alpha);
void rotate(QLineF &point, double alpha);
void rotate(QPolygonF &point, double alpha);
void rotateDegree(QPointF &point, double alpha);
void rotateDegree(QList<QPointF> &points, double alpha);
void rotateDegree(QLineF &point, double alpha);
void rotateDegree(QPolygonF &point, double alpha);
IntersectType intersects(const Circle &circle1, const Circle &circle2);
IntersectType intersects(const Circle &circle1, const Circle &circle2, QList<QPointF> &intersectionPoints);
IntersectType intersects(const Circle &circle, const QLineF &line);
IntersectType intersects(const Circle &circle, const QLineF &line, QList<QPointF> &intersectionPoints);
IntersectType intersects(const QLineF &line1, const QLineF &line2, QPointF &intersectionPt);
QList<IntersectType> intersects(const QPolygonF &polygon, const QLineF &line, QList<QPointF> &intersectionList, QList<QPair<int, int>> &neighbourList);
IntersectType intersects(const QPolygonF &polygon, const QLineF &line);
double distance(const QPointF &p1, const QPointF p2);
double angle(const QPointF &p1, const QPointF p2);
double angleDegree(const QPointF &p1, const QPointF p2);
......
This diff is collapsed.
......@@ -2,8 +2,25 @@
#define POLYGONCALCULUS_H
#include <QPointF>
#include <QPolygonF>
#include "PlanimetryCalculus.h"
namespace PolygonCalculus {
enum JoinPolygonError { NotSimplePolygon, PolygonJoined, Disjoint, PathSizeLow};
int closestVertexIndex (const QPolygonF &polygon, const QPointF &coordinate);
QPointF closestVertex (const QPolygonF &polygon, const QPointF &coordinate);
int nextPolygonIndex (int pathsize, int index);
int previousPolygonIndex(int pathsize, int index);
JoinPolygonError joinPolygon (QPolygonF polygon1, QPolygonF polygon2, QPolygonF &joinedPolygon);
bool isSimplePolygon (const QPolygonF &polygon);
bool hasClockwiseWinding (const QPolygonF &path);
void reversePath (QPolygonF &path);
bool offsetPolygon (QPolygonF &polygon, double offset);
double distanceInsidePolygon (const QPointF &c1, const QPointF &c2, QPolygonF polygon);
}
#endif // POLYGONCALCULUS_H
This diff is collapsed.
......@@ -31,23 +31,11 @@ public:
double epsilonMeter() const;
// Member Methodes
int closestVertexIndex (const QList<QGeoCoordinate> &path, const QGeoCoordinate &coordinate);
QGeoCoordinate closestVertex (const QList<QGeoCoordinate> &path, const QGeoCoordinate &coordinate);
int nextPolygonIndex (int pathsize, int index);
int previousPolygonIndex(int pathsize, int index);
JoinPolygonError joinPolygon (QList<QGeoCoordinate> polygon1, QList<QGeoCoordinate> polygon2,
QList<QGeoCoordinate> &joinedPolygon);
IntersectionType intersects (const Line &line1, const Line &line2,
QGeoCoordinate &intersectionPt);
QList<IntersectionType> intersects (const QList<QGeoCoordinate> &polygon, const Line &line,
QList<QGeoCoordinate> &intersectionList, QList<QPair<int, int>> &neighbourList);
bool intersects (const QList<QGeoCoordinate> &polygon, const Line &line);
DijkstraError dijkstraPath (const QList<QGeoCoordinate> &polygon, const QGeoCoordinate& start,
const QGeoCoordinate& end, QList<QGeoCoordinate>& dijkstraPath);
bool isSimplePolygon (const QList<QGeoCoordinate> &polygon);
bool hasClockwiseWinding (const QList<QGeoCoordinate> &path);
void reversePath (QList<QGeoCoordinate> &path);
bool offsetPolygon (QList<QGeoCoordinate> &polygon, double offset);
......@@ -56,7 +44,7 @@ signals:
public slots:
private:
double distanceInsidePolygon (const QGeoCoordinate& c1, const QGeoCoordinate& c2, QList<QGeoCoordinate> polygon);
double _epsilonMeter; // The accuracy used for distance calculations (unit: m).
......
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