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.
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.
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