← All bug reports

FS#2496Draw > Ellipse > Inscribed may return rotated or wrong result

Type
Bug
Status
Closed
Resolution
Won't fix
Category
QCAD (main)
Severity
Low
Priority
Low
Reported version
3.28.2
Operating system
All
Reported
2023-10-21 by CVH
Closed
2023-12-05 by andrew
Votes
1

Andrew,

In some cases Draw > Ellipse > Inscribed in Quadrilateral (EQ) may return a perfectly healthy result but rotated for 90 degrees.
- Size doesn't matter.
- Quadrant doesn't matter.
- Geometrical open or closed base shape doesn't matter.
- A mirrored base shape usually preforms well.

See attachment with examples.
The incorrect results (red) are rotated 90 degrees around the ellipse center (dotted)
Green is a correct result from a mirrored base shape.

Regards,
CVH

Comments (5)

andrew 2023-12-04

The result can also be completely wrong or slightly off from the desired maximum area solution. This needs a different algorithm.

CVH 2023-12-05

As far I can tell both ellipses in the unit test dxf result in a horizontal major axis.
I don't think that such is a proper unit test.
Expecting an irregular quadrilateral too.

I read in REllipse.cpp:

// offset to 0,0 to reduce magnitudes:

What is good practice but we can't gain in floating point accuracy.

Further I read:

// numbers in this algorithm can get extremely large, so we scale down here
// a bit if appropriate:

Seen the limited accuracy of large numbers, yes agreed.
When a bbox side exceeds 100 the factor is based on 100/maxSize

Question: Is it more stable when only dividers based on 2^n are used?
In a custom tool ConicSection5pts I discovered that down scaling has an adverse effect on results and then more on angles. Binary based divisions only alter the binary exponent.

Line 131-136 calculate the coefficients of the implicit conic equation.
Coefficients a-g can all be divide by the smallest nonzero a-g.
Nonzero with RMath.fuzzyCompare(CoX, 0.0, 1e-7) works well.
One can not expect better accuracies here.

Comparing the discriminant to be less than 1e-50 looks strange to me.
When the discriminant is (almost) zero it is a Parabola.
When less than zero it is a Circle or an Ellipse. (The value must be negative)
When A is (almost) C and B is (almost) zero it is a Circle otherwise it is an Ellipse.
When the discriminant is larger than zero it is a Hyperbola.
What would mean that this verification test is incomplete.

Later comparing b to match zero within 1e-9 is possible too strick.

Regards,
CVH

andrew 2023-12-05

It's an extremely complex mathematical problem and there might simply not be an algorithm that covers all cases.

I will likely leave the tool in there as a "best effort" type tool as it is useful for some use cases.

CVH 2023-12-11

The positions of the tangent points is straight forward with protective geometry.
The center of the ellipse can be found in the same way.
The quad can then be rotated 180 degree around the center.
Resulting it at least 5 distinct tangent points.
ConicSection5pts returns always a perfect result.

Removed from Draw ellipse Open Source.
https://github.com/qcad/qcad/commit/40378726204fb1cacc0d8f07ee887c1bd203abe4

Updated to ellipse proxy
https://github.com/qcad/qcad/commit/5ec2dd79e40291ac2a515e078ff2ff9c71984e85

Can't be of any further assistance, I'll pass, sorry.
CVH

Closure comment

Not fixable within a reasonable time frame.