private static alglib.ndimensional_pfunc CreateCircleOfKnownRadiusDistanceFunction(double radius) { return(delegate(double[] c, double[] x, ref double func, object obj) { var circle = new Circle2(new Vector2(c[0], c[1]), radius); var point = new Vector2(x[0], x[1]); func = circle.DistanceFromCircle(point); }); }
private static void CircleDistanceFunction(double[] c, double[] x, ref double func, object obj) { var cx = c[0]; var cy = c[1]; var r = c[2]; if (r < 0) { func = double.PositiveInfinity; // negative radius } else { var circle = new Circle2(new Vector2(c[0], c[1]), c[2]); var point = new Vector2(x[0], x[1]); func = circle.DistanceFromCircle(point); } }