FS#2564 - REllipse::getVectorTo(p) returns a vector to a major point when p is on the major axis
Andrew,
If a given point p is on the major axis then REllipse::getVectorTo(p) returns one of the major points. In the code this is handled as a special case when the point is in-line (collinear) with the major axis.
This is only correct for points outside the evolute.
On the major axis is defined by getAngle().
This may fail for a magnitude equal to or less than 1e-6.
A point that close to the center should not have a single solution at zero degrees.
The correct solutions are:
- If p is equal to the center ⇒ Two vectors to the two minor points.
- On the major axis and strictly inside the evolute ⇒ Two mirrored vectors.
- On the major axis and on or outside the evolute ⇒ The nearest major point.
- On the minor axis ⇒ The nearest minor point.
An additional problem is now what to return on a duality with full ellipses.
Or for an ellipse arc where both of two results are valid.
getVectorTo() typically returns but one unique result.
For example:
RCircle::getVectorTo(p) returns an invalid vector when the point is near the center.
Then there are an unlimited number of solutions.
Further discovered that the point related to the returned vector may fail x²/a²+y²/b²=1
Although almost on the ellipse within 2.299e-10 ... f(x,y) may return 9.5310
This example would fail REllipse::contains while the border is considered as inside.
Meanwhile implemented a ‘simple method’ to find the nearest point(s) on an ellipse.
Fast converging in 3 steps, no trigs and very accurate, about 24 lines of code.
f(x,y) returns mostly 1.000 with so far:
- a minimum of 0.9999999999999997
- a maximum of 1.0000000000000007.
In other words, it is only off for the last meaningful decimal digit.
With this all methods that are based on REllipse::getVectorTo(p) can be implemented very reliable with tolerance, border flag, ... and so on.
By default the normal for a point is given with high accuracy and a tangent is that rotated.
...
..
.
Regards,
CVH
Related topic: https://www.qcad.org/rsforum/viewtopic.php?f=33&t=11405
Regards,
CVH
Issue solved, see contribution in the same topic.
Regards,
CVH