bugfix: straight lines in pie and chord were not drawn as curve in DrawMode=DrawAsMathematicalCurve

This commit is contained in:
jkriege2 2020-09-03 23:27:08 +02:00
parent e97c0a13fe
commit 33a9cb5b2d
6 changed files with 22 additions and 10 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 68 KiB

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 68 KiB

After

Width:  |  Height:  |  Size: 70 KiB

View File

@ -31,7 +31,7 @@ All test-projects are Qt-projects that use qmake to build. You can load them int
|:-------------:| ------------- | ------------- |
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/geometric_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/geometric) | [Plotting Geometric Objects](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/geometric) | |
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/geo_arrows_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/geo_arrows) | [Plotting Arrows](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/geo_arrows) | |
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/geo_simple_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/geo_simple) | [Plotting Arrows](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/geo_simple) | |
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/geo_simple_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/geo_simple) | [Demo-Plots of Geometric Objects for Documentation](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/geo_simple) | |
## Styling the Plot, Keys, Axes, ...

View File

@ -62,15 +62,18 @@ QVector<QPointF> JKQTPSplitEllipseIntoPoints(double x, double y, double a, doubl
return result;
}
QVector<QPointF> JKQTPSplitEllipseIntoPoints(std::function<QPointF (QPointF)> fTransform, double x, double y, double a, double b, double angle_start, double angle_end, double alpha, QPointF *x_start, QPointF *x_end)
QVector<QPointF> JKQTPSplitEllipseIntoPoints(std::function<QPointF (QPointF)> fTransform, double x, double y, double a, double b, double angle_start, double angle_end, double alpha, QPointF *x_start, QPointF *x_end, QPointF *x_start_notrafo, QPointF *x_end_notrafo)
{
const double sina=sin(1.0*alpha/180.0*JKQTPSTATISTICS_PI);
const double cosa=cos(1.0*alpha/180.0*JKQTPSTATISTICS_PI);
std::function<QPointF(double)> fell=[&](double t)->QPointF {
return QPointF(x+a*cos(t)*cosa-b*sin(t)*sina, y+a*cos(t)*sina+b*sin(t)*cosa);
};
std::function<double(double)> fx = [&](double t) ->double {
return fTransform(QPointF(x+a*cos(t)*cosa-b*sin(t)*sina, y+a*cos(t)*sina+b*sin(t)*cosa)).x();
return fTransform(fell(t)).x();
};
std::function<double(double)> fy = [&](double t) ->double {
return fTransform(QPointF(x+a*cos(t)*cosa-b*sin(t)*sina, y+a*cos(t)*sina+b*sin(t)*cosa)).y();
return fTransform(fell(t)).y();
};
JKQTPAdaptiveFunctionGraphEvaluator eval(fx, fy);
@ -78,6 +81,8 @@ QVector<QPointF> JKQTPSplitEllipseIntoPoints(std::function<QPointF (QPointF)> fT
if (points.size()>0) {
if (x_start) *x_start=points.first();
if (x_end) *x_end=points.last();
if (x_start_notrafo) *x_start_notrafo=fell(angle_start*JKQTPSTATISTICS_PI/180.0);
if (x_end_notrafo) *x_end_notrafo=fell(angle_end*JKQTPSTATISTICS_PI/180.0);
}
return points;
}

View File

@ -125,12 +125,14 @@ JKQTCOMMON_LIB_EXPORT QVector<QPointF> JKQTPSplitEllipseIntoPoints(double x, dou
\param angle_start starting angle of ellipse section
\param angle_end ending angle of ellipse section
\param alpha rotation angle of ellipse
\param[out] x_start first point of ellipse
\param[out] x_end last point of ellipse
\param[out] x_start first point of ellipse, with fTransform applied
\param[out] x_end last point of ellipse, with fTransform applied
\param[out] x_start_notrafo first point of ellipse, without fTransform applied
\param[out] x_end_notrafo last point of ellipse, without fTransform applied
\note all angles are given in degrees [0..360]
*/
JKQTCOMMON_LIB_EXPORT QVector<QPointF> JKQTPSplitEllipseIntoPoints(std::function<QPointF(QPointF)> fTransform, double x, double y, double a, double b, double angle_start=0, double angle_end=360, double alpha=0, QPointF* x_start=nullptr, QPointF* x_end=nullptr);
JKQTCOMMON_LIB_EXPORT QVector<QPointF> JKQTPSplitEllipseIntoPoints(std::function<QPointF(QPointF)> fTransform, double x, double y, double a, double b, double angle_start=0, double angle_end=360, double alpha=0, QPointF* x_start=nullptr, QPointF* x_end=nullptr, QPointF* x_start_notrafo=nullptr, QPointF* x_end_notrafo=nullptr);

View File

@ -467,10 +467,15 @@ void JKQTPGeoEllipse::drawInternal(JKQTPEnhancedPainter& painter, double angleSt
if(mode==InternalDrawMode::Ellipse) {
rect=JKQTPSplitEllipseIntoPoints(fTransform, x,y,width/2.0, height/2.0,0,360, angle);
} else if (mode==InternalDrawMode::Pie) {
rect=JKQTPSplitEllipseIntoPoints(fTransform, x,y,width/2.0, height/2.0,angleStart,angleStop, angle);
rect.append(transform(x,y));
QPointF first, last;
rect=JKQTPSplitEllipseIntoPoints(fTransform, x,y,width/2.0, height/2.0,angleStart,angleStop, angle, nullptr, nullptr, &first, &last);
QVector<QPointF> pie;
pie<<last<<QPointF(x,y)<<first;
rect.append(JKQTPSimplyfyLineSegemnts(JKQTPSplitPolylineIntoPoints(pie, fTransform)));
} else if (mode==InternalDrawMode::Chord) {
rect=JKQTPSplitEllipseIntoPoints(fTransform, x,y,width/2.0, height/2.0,angleStart,angleStop, angle);
QPointF first, last;
rect=JKQTPSplitEllipseIntoPoints(fTransform, x,y,width/2.0, height/2.0,angleStart,angleStop, angle, nullptr, nullptr, &first, &last);
rect.append(JKQTPSimplyfyLineSegemnts(JKQTPSplitLineIntoPoints(QLineF(last, first), fTransform)));
}
painter.drawPolygon(rect);