0001 function varargout = fillSphericalTriangle(sphere, p1, p2, p3, varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 ori = sphere(:, 1:3);
0018 r = sphere(4);
0019
0020
0021 v1 = normalizeVector3d(p1 - ori);
0022 v2 = normalizeVector3d(p2 - ori);
0023 v3 = normalizeVector3d(p3 - ori);
0024
0025
0026 plane = createPlane(v1, v1);
0027
0028
0029 pp2 = planePosition(intersectLinePlane([ori v2], plane), plane);
0030 pp3 = planePosition(intersectLinePlane([ori v3], plane), plane);
0031
0032
0033 nTri = 5;
0034 s = linspace(0, 1, nTri);
0035 t = linspace(0, 1, nTri);
0036 ns = length(s);
0037 nt = length(t);
0038 s = repmat(s, [nt, 1]);
0039 t = repmat(t', [1, ns]);
0040
0041
0042 xp = s * pp2(1) + t .* (1-s) * pp3(1);
0043 yp = s * pp2(2) + t .* (1-s) * pp3(2);
0044
0045
0046 x = plane(1) * ones(size(xp)) + plane(4) * xp + plane(7) * yp - ori(1);
0047 y = plane(2) * ones(size(xp)) + plane(5) * xp + plane(8) * yp - ori(2);
0048 z = plane(3) * ones(size(xp)) + plane(6) * xp + plane(9) * yp - ori(3);
0049
0050
0051 norm = hypot(hypot(x, y), z);
0052 xn = x ./ norm * r + ori(1);
0053 yn = y ./ norm * r + ori(2);
0054 zn = z ./ norm * r + ori(3);
0055
0056
0057 if nargout == 0
0058
0059 surf(xn, yn, zn, 'FaceColor', 'g', 'EdgeColor', 'none', varargin{:});
0060
0061 elseif nargout == 1
0062
0063 h = surf(xn, yn, zn, 'FaceColor', 'g', 'EdgeColor', 'none', varargin{:});
0064 varargout = {h};
0065
0066 elseif nargout == 3
0067
0068 varargout = {x, y, z};
0069 end