25 const QPointF &posOriginScreen) :
29 m_modelCoords (modelCoords),
30 m_posOriginScreen (posOriginScreen)
38double CentipedeEndpointsPolar::closestAngleToCentralAngle (
double angleCenter,
39 double angleOld)
const
43 double angleNew = angleOld;
44 for (
int delta = -360; delta <= 360; delta += 360) {
45 double angleNext = angleOld + qDegreesToRadians ((
double) delta);
46 if (isFirst || (qAbs (angleNext - angleCenter) < qAbs (angleNew - angleCenter))) {
57 double &angleRotation,
63 QPointF posClickGraph;
66 double rGraph = posClickGraph.y();
69 QPointF posScreenOrigin, posScreen0, posScreen90, posScreen180;
70 transformation.transformRawGraphToScreen (QPointF (tAtOrigin (), rAtOrigin ()),
79 QPointF centerTo90 = posScreen90 - posScreenOrigin;
82 QPointF posScreenTL = posScreen180 + centerTo90;
83 QPointF posScreenTR = posScreen0 + centerTo90;
84 QPointF posScreenBL = posScreen180 - centerTo90;
85 QPointF posScreenBR = posScreen0 - centerTo90;
87 double aAligned = 0, bAligned = 0;
89 posScreenTL.y() - posScreenOrigin.y(),
90 posScreenTR.x() - posScreenOrigin.x(),
91 posScreenTR.y() - posScreenOrigin.y(),
92 posScreenBR.x() - posScreenOrigin.x(),
93 posScreenBR.y() - posScreenOrigin.y(),
98 double angleGraphAxisFromScreenAxis = qAtan2 (posScreen0.y() - posScreenOrigin.y(),
99 posScreen0.x() - posScreenOrigin.x());
105 angleGraphAxisFromScreenAxis,
113 rectBounding = QRectF (-1.0 * aAligned,
118 LOG4CPP_INFO_S ((*
mainCat)) <<
"CentipedeEndpointsPolar::ellipseScreenConstantRForTHighLowAngles angleRotation="
119 << qRadiansToDegrees (angleRotation) <<
" posScreen0=" <<
QPointFToString (posScreen0).toLatin1().data()
122 <<
" b=" << bAligned;
125void CentipedeEndpointsPolar::generatePreviousAndNextPointsConstantR (
double radiusAboutClick,
128 QPointF &posGraphPrevious,
129 QPointF &posGraphNext,
130 QPointF &posScreenPrevious)
const
140 QPointF basisTangential (basisRadial.y(),
141 -1.0 * basisRadial.x());
143 double angleBefore = 2.0 * M_PI * (double) iPrevious / (
double)
NUM_CIRCLE_POINTS;
146 posScreenPrevious =
posClickScreen () + radiusAboutClick * (qCos (angleBefore) * basisRadial + qSin (angleBefore) * basisTangential);
147 QPointF posScreenNext =
posClickScreen () + radiusAboutClick * (qCos (angleAfter) * basisRadial + qSin (angleAfter) * basisTangential);
155QPointF CentipedeEndpointsPolar::posScreenConstantRCommon (
double radius,
158 QPointF posScreenBest;
162 QPointF posClickGraph;
165 double yClick = posClickGraph.y();
170 QPointF posGraphPrevious, posGraphNext, posScreenPrevious;
171 generatePreviousAndNextPointsConstantR (radius,
178 double xGraphPrevious = posGraphPrevious.x();
179 double yGraphPrevious = posGraphPrevious.y();
180 double yGraphNext = posGraphNext.y();
181 double epsilon = qAbs (yGraphPrevious - yGraphNext) / 10.0;
186 bool transitionUp = (yGraphPrevious - epsilon <= yClick) && (yClick < yGraphNext + epsilon);
187 bool transitionDown = (yGraphNext - epsilon <= yClick) && (yClick < yGraphPrevious + epsilon);
189 if (transitionDown || transitionUp) {
204 posScreenBest = posScreenPrevious;
205 xBest = xGraphPrevious;
209 return posScreenBest;
214 return posScreenConstantRCommon (radius,
220 return posScreenConstantRCommon (radius,
226 QPointF &posHigh)
const
229 QPointF posClickGraph;
232 double yClick = posClickGraph.y();
236 bool isFirstLow =
true, isFirstHigh =
true;
237 QPointF posLowGraph, posHighGraph;
239 QPointF posGraphPreviousLow, posGraphNextLow, posScreenPreviousLow;
240 QPointF posGraphPreviousHigh, posGraphNextHigh, posScreenPreviousHigh;
241 generatePreviousAndNextPointsConstantR (radiusAboutClick,
246 posScreenPreviousLow);
247 generatePreviousAndNextPointsConstantR (radiusAboutClick,
250 posGraphPreviousHigh,
252 posScreenPreviousHigh);
254 double epsilon = qAbs (posGraphPreviousLow.y() - posGraphNextLow.y()) / 10.0;
256 bool transitionUpLow = (posGraphPreviousLow.y() - epsilon <= yClick) && (yClick < posGraphNextLow.y() + epsilon);
257 bool transitionDownLow = (posGraphNextLow.y() - epsilon <= yClick) && (yClick < posGraphPreviousLow.y() + epsilon);
258 bool transitionUpHigh = (posGraphPreviousHigh.y() - epsilon <= yClick) && (yClick < posGraphNextHigh.y() + epsilon);
259 bool transitionDownHigh = (posGraphNextHigh.y() - epsilon <= yClick) && (yClick < posGraphPreviousHigh.y() + epsilon);
261 if (isFirstLow && (transitionDownLow || transitionUpLow)) {
264 posLowGraph = (posGraphPreviousLow + posGraphNextLow) / 2.0;
270 if (isFirstHigh && (transitionDownHigh || transitionUpHigh)) {
273 posHighGraph = (posGraphPreviousHigh + posGraphNextHigh) / 2.0;
289 QPointF &posHigh)
const
297 QPointF posOriginScreen;
306 const double DOUBLE_PLUS_EXTRA = 2.1;
307 double maxRadius = DOUBLE_PLUS_EXTRA * (
magnitude (vecCenter) + radius);
308 QPointF posStart = posOriginScreen - 2 * maxRadius *
normalize (vecCenter);
309 QPointF posStop = posOriginScreen + 2 * maxRadius *
normalize (vecCenter);
314 QPointF posPrevious = (1.0 - sPrevious) * posStart + sPrevious * posStop;
315 QPointF posNext = (1.0 - sNext) * posStart + sNext * posStop;
320 if ((distancePrevious < radius && radius <= distanceNext) ||
321 (distancePrevious > radius && radius >= distanceNext)) {
323 if (numberFound == 0) {
324 posLow = (posPrevious + posNext) / 2.0;
325 }
else if (numberFound == 1) {
326 posHigh = (posPrevious + posNext) / 2.0;
335double CentipedeEndpointsPolar::rAtOrigin ()
const
345double CentipedeEndpointsPolar::tAtOrigin ()
const
const int NUM_CIRCLE_POINTS
const int NUM_LINE_POINTS
CentipedeIntersectionType
Intersect with one of the following XT or YT coordinates for constant YR or XT respectively.
@ CENTIPEDE_INTERSECTION_HIGH
Intersection along circle perimeter with lowest value of XT or YR.
@ CENTIPEDE_INTERSECTION_LOW
log4cpp::Category * mainCat
QString QPointFToString(const QPointF &pos)
Class for collecting and then displaying debug information computed during constant R ellipse calcula...
QPointF posClickScreen() const
Center of circle in screen coordinates.
const DocumentModelGuideline & modelGuideline() const
Settings.
const Transformation & transformation() const
Transformation which is static through the entire lifetime of the Centipede class instances.
CentipedeEndpointsAbstract(const DocumentModelGuideline &modelGuideline, const Transformation &transformation, const QPointF &posClickScreen)
Constructor with individual coordinates.
CentipedeEndpointsPolar(const DocumentModelCoords &modelCoords, const DocumentModelGuideline &modelGuideline, const Transformation &transformation, const QPointF &posClickScreen, const QPointF &posOriginScreen)
Constructor with individual coordinates.
QPointF posScreenConstantRForLowT(double radius) const
Screen point for R value of circle/coordinate intersection in the decreasing T direction.
void ellipseScreenConstantRForTHighLowAngles(const Transformation &transformation, const QPointF &posClickScreen, double &angleRotation, QRectF &rectBounding, CentipedeDebugPolar &DebugPolar)
Ellipse for R value of circle/coordinate intersection. Start/span angles are calculated separately.
virtual ~CentipedeEndpointsPolar()
void posScreenConstantRHighLow(double radiusAboutClick, QPointF &posLow, QPointF &posHigh) const
Return two points (posLow and posHigh) where circle around posClickScreen intersects constant-radiusA...
void posScreenConstantTForRHighLow(double radius, QPointF &posLow, QPointF &posHigh) const
Endpoints for radial line segmentin polar coordinates.
QPointF posScreenConstantRForHighT(double radius) const
Screen point for R value of circle/coordinate intersection in the increasing T direction.
Model for DlgSettingsCoords and CmdSettingsCoords.
CoordScale coordScaleYRadius() const
Get method for linear/log scale on y/radius.
double originRadius() const
Get method for origin radius in polar mode.
Model for managing the coordinate values corresponding Guidelines.
#define LOG4CPP_INFO_S(logger)
double magnitude(const QPointF &vec)
Norm of vector.
void ellipseFromParallelogram(double xTL, double yTL, double xTR, double yTR, double xBR, double yBR, double &angleRadians, double &aAligned, double &bAligned)
Calculate ellipse parameters that is incribed in a parallelogram centered at the origin,...
QPointF normalize(const QPointF &vec)
Return normalized vector.