Commit 257fcdbc authored by Valentin Platzgummer's avatar Valentin Platzgummer

planicalc edited

parent d61b7b13
...@@ -127,13 +127,13 @@ QPolygonF Circle::approximateSektor(double angleDiscretisation, double alpha1, d ...@@ -127,13 +127,13 @@ QPolygonF Circle::approximateSektor(double angleDiscretisation, double alpha1, d
double currentAngle = alpha1; double currentAngle = alpha1;
// rotate the vertex numberOfCorners-1 times add the origin and append to the polygon. // rotate the vertex numberOfCorners-1 times add the origin and append to the polygon.
while(currentAngle < alpha2) { while(currentAngle < alpha2) {
PlanimetryCalculus::rotate(vertex, currentAngle); PlanimetryCalculus::rotateReference(vertex, currentAngle);
polygon.append(vertex + _circleOrigin); polygon.append(vertex + _circleOrigin);
currentAngle = PlanimetryCalculus::truncateAngle(currentAngle + angleDiscretisation); currentAngle = PlanimetryCalculus::truncateAngle(currentAngle + angleDiscretisation);
} }
// append last point if necessarry // append last point if necessarry
PlanimetryCalculus::rotate(vertex, alpha2); PlanimetryCalculus::rotateReference(vertex, alpha2);
vertex = vertex + _circleOrigin; vertex = vertex + _circleOrigin;
if ( !qFuzzyIsNull(PlanimetryCalculus::distance(polygon.first(), vertex)) if ( !qFuzzyIsNull(PlanimetryCalculus::distance(polygon.first(), vertex))
&& !qFuzzyIsNull(PlanimetryCalculus::distance(polygon.last(), vertex )) ){ && !qFuzzyIsNull(PlanimetryCalculus::distance(polygon.last(), vertex )) ){
......
...@@ -19,7 +19,7 @@ namespace PlanimetryCalculus { ...@@ -19,7 +19,7 @@ namespace PlanimetryCalculus {
double angleWLDegree = line.angle(); // angle between wold and line coordinate system double angleWLDegree = line.angle(); // angle between wold and line coordinate system
QPointF originCircleL = circle.origin() - translationVector; QPointF originCircleL = circle.origin() - translationVector;
rotate(originCircleL, -angleWLDegree); // circle origin in line corrdinate system rotateReference(originCircleL, -angleWLDegree); // circle origin in line corrdinate system
double y = originCircleL.y(); double y = originCircleL.y();
double r = circle.radius(); double r = circle.radius();
...@@ -31,7 +31,7 @@ namespace PlanimetryCalculus { ...@@ -31,7 +31,7 @@ namespace PlanimetryCalculus {
if (x_ori >= 0 && x_ori <= line.length()) { if (x_ori >= 0 && x_ori <= line.length()) {
if (calcInstersect) { if (calcInstersect) {
QPointF intersectionPt = QPointF(x_ori, 0); QPointF intersectionPt = QPointF(x_ori, 0);
rotate(intersectionPt, angleWLDegree); rotateReference(intersectionPt, angleWLDegree);
intersectionPoints.append(intersectionPt + translationVector); intersectionPoints.append(intersectionPt + translationVector);
} }
...@@ -50,7 +50,7 @@ namespace PlanimetryCalculus { ...@@ -50,7 +50,7 @@ namespace PlanimetryCalculus {
if (x1 >= 0 && x1 <= line.length()) { // check if intersection point is on the line if (x1 >= 0 && x1 <= line.length()) { // check if intersection point is on the line
if (calcInstersect) { if (calcInstersect) {
QPointF intersectionPt = QPointF(x1, 0); // first intersection point (line system) QPointF intersectionPt = QPointF(x1, 0); // first intersection point (line system)
rotate(intersectionPt, angleWLDegree); rotateReference(intersectionPt, angleWLDegree);
intersectionPoints.append(intersectionPt + translationVector); // transform (to world system) and append first intersection point intersectionPoints.append(intersectionPt + translationVector); // transform (to world system) and append first intersection point
} }
doesIntersect = true; doesIntersect = true;
...@@ -58,7 +58,7 @@ namespace PlanimetryCalculus { ...@@ -58,7 +58,7 @@ namespace PlanimetryCalculus {
if (x2 >= 0 && x2 <= line.length()) { // check if intersection point is on the line if (x2 >= 0 && x2 <= line.length()) { // check if intersection point is on the line
if (calcInstersect) { if (calcInstersect) {
QPointF intersectionPt = QPointF(x2, 0); // second intersection point (line system) QPointF intersectionPt = QPointF(x2, 0); // second intersection point (line system)
rotate(intersectionPt, angleWLDegree); rotateReference(intersectionPt, angleWLDegree);
intersectionPoints.append(intersectionPt + translationVector); // transform (to world system) and append second intersection point intersectionPoints.append(intersectionPt + translationVector); // transform (to world system) and append second intersection point
} }
doesIntersect = true; doesIntersect = true;
...@@ -76,7 +76,7 @@ namespace PlanimetryCalculus { ...@@ -76,7 +76,7 @@ namespace PlanimetryCalculus {
\fn void rotatePoint(QPointF &point, double alpha) \fn void rotatePoint(QPointF &point, double alpha)
Rotates the \a point counter clockwisely by the angle \a alpha (in radiants). Rotates the \a point counter clockwisely by the angle \a alpha (in radiants).
*/ */
void rotate(QPointF &point, double alpha) void rotateReference(QPointF &point, double alpha)
{ {
if (!point.isNull()) { if (!point.isNull()) {
double x = point.x(); double x = point.x();
...@@ -87,10 +87,10 @@ namespace PlanimetryCalculus { ...@@ -87,10 +87,10 @@ namespace PlanimetryCalculus {
} }
} }
void rotate(QList<QPointF> &points, double alpha) void rotateReference(QList<QPointF> &points, double alpha)
{ {
for (int i = 0; i < points.size(); i++) { for (int i = 0; i < points.size(); i++) {
rotate(points[i], alpha); rotateReference(points[i], alpha);
} }
} }
...@@ -98,15 +98,15 @@ namespace PlanimetryCalculus { ...@@ -98,15 +98,15 @@ namespace PlanimetryCalculus {
\fn void rotatePointDegree(QPointF &point, double alpha) \fn void rotatePointDegree(QPointF &point, double alpha)
Rotates the \a point counter clockwisely by the angle \a alpha (in degrees). Rotates the \a point counter clockwisely by the angle \a alpha (in degrees).
*/ */
void rotateDegree(QPointF &point, double alpha) void rotateReferenceDegree(QPointF &point, double alpha)
{ {
rotate(point, alpha/180*M_PI); rotateReference(point, alpha/180*M_PI);
} }
void rotateDegree(QList<QPointF> &points, double alpha) void rotateReferenceDegree(QList<QPointF> &points, double alpha)
{ {
for (int i = 0; i < points.size(); i++) { for (int i = 0; i < points.size(); i++) {
rotateDegree(points[i], alpha); rotateReferenceDegree(points[i], alpha);
} }
} }
...@@ -211,7 +211,7 @@ namespace PlanimetryCalculus { ...@@ -211,7 +211,7 @@ namespace PlanimetryCalculus {
intersectionPoints.append(QPointF(x, -y)); intersectionPoints.append(QPointF(x, -y));
} }
// Transform the coordinate to the world coordinate system. Alpha is the angle between world and circle1 coordinate system. // Transform the coordinate to the world coordinate system. Alpha is the angle between world and circle1 coordinate system.
rotate(intersectionPoints, alpha); rotateReference(intersectionPoints, alpha);
return returnValue; return returnValue;
} }
...@@ -293,20 +293,92 @@ namespace PlanimetryCalculus { ...@@ -293,20 +293,92 @@ namespace PlanimetryCalculus {
/*! /*!
* \fn IntersectType intersects(const QLineF &line1, const QLineF &line2, QPointF &intersectionPt); * \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. * Determines wheter \a line1 and \a line2 intersect and of which type the intersection is.
* Stores the intersection point in \a intersectionPt * 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. * Returns the intersection type (\c IntersectType).
*
* Intersection Types:
* \c NoIntersection
* \c CornerCornerIntersection; A intersection is present such that two of the lines cornes touch.
* \c EdgeCornerIntersection; A intersection is present such that a corner and a edge touch.
* \c EdgeEdgeIntersection; A intersection is present such two edges intersect.
* \c LinesParallel
* \c LinesEqual
* \c Error; Returned if at least on line delivers isNULL() == true.
*
* *
* \sa QGeoCoordinate * \sa QGeoCoordinate
*/ */
IntersectType intersects(const QLineF &line1, const QLineF &line2, QPointF &intersectionPt) IntersectType intersects(const QLineF &line1, const QLineF &line2, QPointF &intersectionPt)
{ {
QPointF pt11(0, 0); if (line1.isNull() || line2.isNull())
return Error;
// line 1 coordinate system: origin line1.p1(), x-axis towards line1.p2()
QPointF translationVector = line1.p1(); // translation vector between world and line1 system
double alpha = line1.angle();
double l1 = line1.length();
QLineF line2L1 = line1;
line2L1.translate(-translationVector);
rotateReference(line2L1, -alpha);
double x1 = line2L1.x1();
double x2 = line2L1.x2();
double y1 = line2L1.y1();
double y2 = line2L1.y2();
double dx = (x2-x1);
double dy = (y2-y1);
double xNull = 0; // (xNull, 0) intersection point in line1 system
if (!qFuzzyIsNull(dx)) {
double k = dy/dx;
if (qFuzzyIsNull(k)) {
if (qFuzzyIsNull(x1) && qFuzzyIsNull(y1) && qFuzzyCompare(x2, l1))
return LinesEqual;
else
return LinesParallel;
}
double d = (y1*x2-y2*x1)/dx;
xNull = -d/k;
} else {
// lines orthogonal
if (signum(y1) != signum(y2)){
xNull = x1;
}
else
return NoIntersection;
}
IntersectType returnValue;
QPointF intersectionPoint; if (xNull >= x1 && xNull <= x2){
// determine intersection type
// continue here if(qFuzzyIsNull(xNull) || qFuzzyCompare(xNull, l1)) {
if(qFuzzyIsNull(y1) || qFuzzyIsNull(y2))
returnValue = CornerCornerIntersection;
else
returnValue = EdgeCornerIntersection;
} else if (xNull > 0 && xNull < l1) {
if(qFuzzyIsNull(y1) || qFuzzyIsNull(y2))
returnValue = EdgeCornerIntersection;
else
returnValue = EdgeEdgeIntersection;
} else
return NoIntersection;
} else
return NoIntersection;
intersectionPt = QPointF(xNull, 0); // intersection point in line1 system
rotateReference(intersectionPt, alpha);
intersectionPt += translationVector;
return returnValue;
} }
/*! /*!
...@@ -383,6 +455,41 @@ namespace PlanimetryCalculus { ...@@ -383,6 +455,41 @@ namespace PlanimetryCalculus {
return false; return false;
} }
void rotateReference(QLineF &line, double alpha)
{
line.setP1(rotateReturn(line.p1(), alpha));
line.setP2(rotateReturn(line.p2(), alpha));
}
QPointF rotateReturn(QPointF point, double alpha)
{
rotateReference(point, alpha);
return point;
}
QList<QPointF> rotateReturn(QList<QPointF> points, double alpha)
{
rotateReference(points, alpha);
return points;
}
QLineF rotateReturn(QLineF line, double alpha)
{
rotateReference(line, alpha);
return line;
}
/*!
* \fntemplate <typename T> int signum(T val)
* Returns the signum of a value \a val.
*
* \sa QPair, QList
*/
template <typename T> int signum(T val)
{
return (T(0) < val) - (val < T(0));
}
} // end namespace PlanimetryCalculus } // end namespace PlanimetryCalculus
......
...@@ -22,14 +22,16 @@ namespace PlanimetryCalculus { ...@@ -22,14 +22,16 @@ namespace PlanimetryCalculus {
Error // general Error // general
}; };
void rotate(QPointF &point, double alpha); void rotateReference(QPointF &point, double alpha);
void rotate(QList<QPointF> &point, double alpha); void rotateReference(QList<QPointF> &points, double alpha);
void rotate(QLineF &point, double alpha); void rotateReference(QLineF &line, double alpha);
void rotate(QPolygonF &point, double alpha); //void rotateReference(QPolygonF &polygon, double alpha);
void rotateDegree(QPointF &point, double alpha);
void rotateDegree(QList<QPointF> &points, double alpha); QPointF rotateReturn(QPointF point, double alpha);
void rotateDegree(QLineF &point, double alpha); QList<QPointF> rotateReturn(QList<QPointF> points, double alpha);
void rotateDegree(QPolygonF &point, double alpha); QLineF rotateReturn(QLineF line, double alpha);
//QPolygonF rotateReturn(QPolygonF &polygon, double alpha);
IntersectType intersects(const Circle &circle1, const Circle &circle2); IntersectType intersects(const Circle &circle1, const Circle &circle2);
IntersectType intersects(const Circle &circle1, const Circle &circle2, QList<QPointF> &intersectionPoints); 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);
...@@ -45,6 +47,8 @@ namespace PlanimetryCalculus { ...@@ -45,6 +47,8 @@ namespace PlanimetryCalculus {
double angleDegree(const QPointF &p1, const QPointF p2); double angleDegree(const QPointF &p1, const QPointF p2);
double truncateAngle(double angle); double truncateAngle(double angle);
double truncateAngleDegree(double angle); double truncateAngleDegree(double angle);
template <typename T> int signum(T val);
} }
......
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