-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetInteriorPoint.m
90 lines (72 loc) · 2.68 KB
/
getInteriorPoint.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
function a = getInteriorPoint(gamma, gammap)
%GETINTERIORPOINT Compute a point in the interior of a curve.
% A = GETINTERIORPOINT(gamma, gammap) computes a point A in the interior of
% the curve gamma, which is negatively oriented. gamma and gammap are
% discretizations of gamma(t) and gamma'(t) with equispaced points in
% [0, 2*pi[.
%
% Author: Olivier Sète, v 0.1, 14 Septembre 2016.
% Try the center of mass of gamma:
a = mean(gamma);
% Check that a is in the interior of gamma:
if ( isInteriorPoint(a, gamma) )
return
end
% Check orientation of gamma:
signeadArea = 2*pi*mean(real(gamma) .* imag(gammap));
if ( signeadArea >= 0 )
error('Orientation of the curve is positive, but must be negative.')
end
% Get an interior point by moving inwards from a boundary point.
% We try different boundary points and (up to) two scalings:
len = length(gamma);
if ( len < 4 )
startIndices = 1;
else
startIndices = [floor(len/4), floor(len/2), floor(len*3/4), len];
end
% Find eligible points:
a = [];
for jj = 1:length(startIndices)
startIndex = startIndices(jj);
scale = max(abs(gamma(startIndex)), abs(gammap(startIndex)))*(0.1:0.1:1).';
% Get points interior to gamma:
anew = inwardPoints(gamma, gammap, startIndex, scale);
% If no points were found, try once more with smaller step-size:
if ( isempty(anew) )
scale = scale/10;
anew = inwardPoints(gamma, gammap, startIndex, scale);
end
a = [a; anew];
end
if ( isempty(a) )
error('No interior points found by this method.')
else
% Compute the distance to the boundary:
for jj = 1:length(a)
distance(jj,1) = min(abs(gamma - a(jj,1)));
end
% Pick the point that is furthest from the boundary:
[~, I] = max(distance);
a = a(I);
end
end
function out = isInteriorPoint(a, gamma)
%ISINTERIORPOINT Check if a is in the interior of gamma.
gamma = [gamma; gamma(1)]; % Last point = first point.
argchange = unwrap(angle(gamma-a)); % Continuous arg(f) along gamma.
winding = (argchange(end)-argchange(1))/(2*pi); % Change of Argument.
out = ( abs(winding) > 0.5 );
end
function a = inwardPoints(gamma, gammap, startIndex, scale)
%INWARDPOINTS COnstruct points by moving inwards from a boundary point.
% Since gamma is negatively oriented, the inner normal at gamma(t) is
% gamma(t) - 1i * gammap(t).
a = gamma(startIndex) - 1i*gammap(startIndex) * scale;
% Check which points are in the interior of gamma and pick these:
isIntPt = zeros(size(a));
for j = 1:length(a)
isIntPt(j,1) = isInteriorPoint(a(j), gamma);
end
a = a(isIntPt == 1);
end