-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathmoebiuscoeffs.m
69 lines (61 loc) · 1.4 KB
/
moebiuscoeffs.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
function [A,B,C,D] = moebiuscoeffs(z,w)
%MOEBIUS Moebius transformation parameters.
% A = MOEBIUSCOEFFS(Z,W) computes the coefficients of the Moebius
% transformation taking the 3-vector Z to W, so that
%
% W = (A(1)*Z + A(2))./(A(3)*Z + A(4)).
%
% Infinities are allowed.
%
% If four output arguments are used, they will be given the A values.
% Copyright 1998-2004 by Toby Driscoll.
A = NaN*ones(1,4);
if any(isinf(w))
% Make w(2)=Inf
j = find(isinf(w));
renum = rem((j-1:j+1)+2,3)+1;
z = z(renum);
w = w(renum);
if ~any(isinf(z))
t1 = diff(z(1:2));
t2 = -diff(z(2:3));
elseif isinf(z(2))
t1 = 1;
t2 = 1;
else
% Will have to deal separately with w(2)=Inf and z(1)=Inf
j = find(isinf(z));
if j~=1
z = z([3 2 1]);
w = w([3 2 1]);
end
A(1) = w(1);
A(2) = w(3)*(z(3)-z(2)) - w(1)*z(3);
A(3) = 1;
A(4) = -z(2);
end
elseif any(isinf(z))
% We already know ~any(isinf(w))
% Make z(2)=Inf
j = find(isinf(z));
renum = rem((j-1:j+1)+2,3)+1;
z = z(renum);
w = w(renum);
t1 = -diff(w(2:3));
t2 = diff(w(1:2));
else % everything finite
t1 = -diff(z(1:2))*diff(w(2:3));
t2 = -diff(z(2:3))*diff(w(1:2));
end
if isnan(A(1))
A(1) = w(1)*t1 - w(3)*t2;
A(2) = w(3)*z(1)*t2 - w(1)*z(3)*t1;
A(3) = t1 - t2;
A(4) = z(1)*t2 - z(3)*t1;
end
if nargout==4
D = A(4);
C = A(3);
B = A(2);
A = A(1);
end