## Ticket 0003018: Sketcher Arc End Points + Rim Point fails with "NaN"

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules

Kunda1
Posts: 6452
Joined: Thu Jan 05, 2017 9:03 pm

### Ticket 0003018: Sketcher Arc End Points + Rim Point fails with "NaN"

Discussion thread for issue #3018: Sketcher Arc End Points + Rim Point fails with "NaN"
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
abdullah
Posts: 3174
Joined: Sun May 04, 2014 3:16 pm

### Re: Ticket 0003018: Sketcher Arc End Points + Rim Point fails with "NaN"

wmayer
Posts: 15291
Joined: Thu Feb 19, 2009 10:32 am

### Re: Ticket 0003018: Sketcher Arc End Points + Rim Point fails with "NaN"

It's known that when the three input points are collinear then you can't compute a circle. However, the PR doesn't take care of this and thus will again create NaN's for this case.
And since the formula looks horribly complicated I am not even sure it's correct or which other problems it causes.

In the Mesh module there is a function to calculate the circumcircle of a triangle: https://github.com/FreeCAD/FreeCAD/blob ... s.cpp#L903

I think it's best to use that and adapt it to the 2d case. Here is a Python version of it:

Code: Select all

``````import math

def centerOfCircumCircle(p0,p1,p2):
u = p1-p0
v = p2-p1
w = p0-p2

uu =  u*u
vv =  v*v
ww =  w*w
uv = -(u*v)
vw = -(v*w)
uw = -(u*w)

w0 = (2 * math.sqrt(uu * ww - uw * uw) * uw / (uu * ww))
w1 = (2 * math.sqrt(uu * vv - uv * uv) * uv / (uu * vv))
w2 = (2 * math.sqrt(vv * ww - vw * vw) * vw / (vv * ww))
wx = w0 + w1 + w2
if wx == 0:
raise Exception("Points are collinear")

x = (w0*p0.x + w1*p1.x + w2*p2.x)/wx
y = (w0*p0.y + w1*p1.y + w2*p2.y)/wx
z = (w0*p0.z + w1*p1.z + w2*p2.z)/wx
return vec3(x,y,z)
``````

Code: Select all

``````vec3=FreeCAD.Vector

p0=vec3(0,0)
p1=vec3(1,1)
p2=vec3(2,2)
centerOfCircumCircle(p0,p1,p2) # => Exception: Points are collinear

p2=vec3(2,4)
centerOfCircumCircle(p0,p1,p2) # => Vector (-3.0000000000000013, 4.000000000000003, 0.0)
``````
abdullah
Posts: 3174
Joined: Sun May 04, 2014 3:16 pm

### Re: Ticket 0003018: Sketcher Arc End Points + Rim Point fails with "NaN"

wmayer wrote:It's known that when the three input points are collinear then you can't compute a circle.
This is not a problem for the sketcher. It just needs that the segments to draw the curve after two clicks are not giving NaN so that it can be drawn in the creation process, which is satisfied by the proposed solution. Afterwards, the solver takes care and will show conflicting constraints.

Try a horizontal line with its extremes. Now try to two horizontal lines with one extreme coincident.
wmayer wrote:And since the formula looks horribly complicated I am not even sure it's correct or which other problems it causes.
The formula is just the result of simplifying the radicals on the existing implementation, which is done using Sage's simplify_radical() function.

The problem with the original implementation is precisely that it has radicals which go to infinite while their limit together does not. So horrible expression outperforms beautiful expression.

So, for the simplified solution, if a solution exists it should not give NaN.
wmayer wrote:I think it's best to use that and adapt it to the 2d case.
I will give it a try...
abdullah
Posts: 3174
Joined: Sun May 04, 2014 3:16 pm

### Re: Ticket 0003018: Sketcher Arc End Points + Rim Point fails with "NaN"

wmayer wrote:I think it's best to use that and adapt it to the 2d case
Gotta admit the solution is better: