@c This is part of the GNU Octave Interval Package Manual.
@c Copyright 2015-2016 Oliver Heimlich.
@c See the file manual.texinfo for copying conditions.
@documentencoding UTF-8

@example
@group
@c doctest: +SKIP
## General ring contractor
function [fval, cx1, cx2] = ctc_ring (y, c1, c2, x1, x2)
    ## Forward evaluation
    x1_c1 = x1 - c1;
    x2_c2 = x2 - c2;
    sqr_x1_c1 = x1_c1 .^ 2;
    sqr_x2_c2 = x2_c2 .^ 2;
    fval = hypot (x1_c1, x2_c2);
    ## Reverse evaluation
    y = intersect (y, fval);
    sqr_y = y .^ 2;
    sqr_x1_c1 = intersect (sqr_x1_c1, sqr_y - sqr_x2_c2);
    sqr_x2_c2 = intersect (sqr_x2_c2, sqr_y - sqr_x1_c1);
    x1_c1 = sqrrev (sqr_x1_c1, x1_c1);
    x2_c2 = sqrrev (sqr_x2_c2, x2_c2);
    cx1 = intersect (x1, x1_c1 + c1);
    cx2 = intersect (x2, x2_c2 + c2);
endfunction
@end group
@group
## Ring 1 with center at (1, 3)
## Ring 2 with center at (2, -1)
ctc_ring1 = @@(y, x1, x2) ctc_ring (y, 1, 3, x1, x2);
ctc_ring2 = @@(y, x1, x2) ctc_ring (y, 2, -1, x1, x2);
@end group
@group
## Unite ring 1 with radius 3..4 and ring 2 with radius 5..6
ctc_union_of_rings = ctc_union (ctc_ring1, "[3, 4]", ...
                                ctc_ring2, "[5, 6]");
@end group
@group
## Compute a paving to approximate the union of rings
## in the area x, y = -10..10
[~, paving] = fsolve (ctc_union_of_rings, ...
                      infsup ("[-10, 10] [-10, 10]"), ...
                      struct ("Contract", true));
plot (paving(1, :), paving(2, :))
axis equal
@end group
@end example
