updateToPolygon This function makes all the necessary calculations and updates all data, not just the polygon according to the polygon that was provided as the parameter
129{
130 QTransform transform;
131
134
135
136
137
138 if (!QTransform::squareToQuad(
polygon, transform)) {
139 return false;
140 }
141
143
144
145
146
147
152
153 QPointF ptR =
originalTransform.map(QPointF(0.5 - 1/(2*sqrt(2)), 0.5 - 1/(2*sqrt(2))));
154
155
156
157
158
159
160 Eigen::MatrixXd
A(5, 5);
161 A << ptR.x() * ptR.y(), ptR.y() * ptR.y(), ptR.x(), ptR.y(), 1.0,
162 pt1.x() * pt1.y(), pt1.y() * pt1.y(), pt1.x(), pt1.y(), 1.0,
163 pt2.x() * pt2.y(), pt2.y() * pt2.y(), pt2.x(), pt2.y(), 1.0,
164 pt3.x() * pt3.y(), pt3.y() * pt3.y(), pt3.x(), pt3.y(), 1.0,
165 pt4.x() * pt4.y(), pt4.y() * pt4.y(), pt4.x(), pt4.y(), 1.0;
166
167 Eigen::VectorXd bVector(5);
168 bVector << - ptR.x() * ptR.x(), - pt1.x() * pt1.x(), - pt2.x() * pt2.x(), - pt3.x() * pt3.x(), - pt4.x() * pt4.x();
169
170 Eigen::VectorXd xSolution =
A.fullPivLu().solve(bVector);
171
172
173
174
175 qreal a = 1;
176 qreal
b = xSolution(0);
177
178 qreal c = xSolution(1);
179 qreal
d = xSolution(2);
180
181 qreal e = xSolution(3);
182 qreal
f = xSolution(4);
183
184
186 return false;
187 }
188
190
191
192
196
197
198
201
202
203 qreal aprim = K*K*a - K*L*
b + L*L*c;
204 qreal bprim = 2*K*L*a + K*K*
b - L*L*
b - 2*K*L*c;
205 qreal cprim = L*L*a + K*L*
b + K*K*c;
206 qreal dprim = K*
d - L*e;
207 qreal eprim = L*
d + K*e;
209
211 return false;
212 }
213
216
218
219
220
221
222
223
225
226 qreal rx = sqrt(qPow(rerotatedCenter.x(), 2) + qPow(rerotatedCenter.y(), 2)*cprim/aprim - fprim/aprim);
227 qreal ry = sqrt(rx*rx*aprim/cprim);
228
231
232#if 0
233
234 qreal cprim_recreated = (rx*rx)/(ry*ry);
235 qreal dprim_recreated = -2*rerotatedCenter.x();
236 qreal eprim_recreated = -2*rerotatedCenter.y()*(rx*rx)/(ry*ry);
237 qreal fprim_recreated = qPow(rerotatedCenter.x(), 2) + qPow(rerotatedCenter.y(), 2)*(rx*rx)/(ry*ry) - (rx*rx);
238
239 if (debug) qCritical() << "recreated equation (with 1): " << 1 << 0 << cprim_recreated << dprim_recreated << eprim_recreated << fprim_recreated;
240 if (debug) qCritical() << "recreated equation: (actual)" << aprim << 0 << aprim*cprim_recreated << aprim*dprim_recreated << aprim*eprim_recreated << aprim*fprim_recreated;
241
243 auto fuzzyCompareWithEps = [
eps] (qreal a, qreal
b) {
return abs(a - b) <
eps; };
244
249
250#endif
251
252 auto convertToPreviousCoordsSystem = [K, L] (QPointF
p) {
return QPointF(K*
p.x() + L*
p.y(), K*
p.y() - L*
p.x()); };
253
254
255
256 QPointF leftVertexRerotated = rerotatedCenter + QPointF(-rx, 0);
257 QPointF rightVertedRerotated = rerotatedCenter + QPointF(rx, 0);
258 QPointF topVertedRerotated = rerotatedCenter + QPointF(0, ry);
259
260 QPointF leftVertexFinal = convertToPreviousCoordsSystem(leftVertexRerotated);
261 QPointF rightVertexFinal = convertToPreviousCoordsSystem(rightVertedRerotated);
262 QPointF topVertexFinal = convertToPreviousCoordsSystem(topVertedRerotated);
263
265 result << leftVertexFinal << rightVertexFinal << topVertexFinal;
266
268
270 return true;
271}
static bool formulaRepresentsAnEllipse(double a, double b, double c)
formulaRepresentsAnEllipse parameters are first three coefficients from a formula: ax^2 + bxy + cy^2 ...
double finalAxisReverseAngleSin
void setFormula(QVector< double > &formula, double a, double b, double c, double d, double e, double f)
double finalAxisReverseAngleCos
QVector< QPointF > polygon
QTransform originalTransform
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Point abs(const Point &pt)