Also, be nice to others! Read the FreeCAD code of conduct!

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

#lowhangingfruit

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:

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)
```

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.wmayer wrote:It's known that when the three input points are collinear then you can't compute a circle.

Try a horizontal line with its extremes. Now try to two horizontal lines with one extreme coincident.

The formula is just the result of simplifying the radicals on the existing implementation, which is done using Sage's simplify_radical() function.wmayer wrote:And since the formula looks horribly complicated I am not even sure it's correct or which other problems it causes.

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.

I will give it a try...wmayer wrote:I think it's best to use that and adapt it to the 2d case.

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

https://github.com/FreeCAD/FreeCAD/pull/767