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