DRAWSPHERICALTRIANGLE Draw a triangle on a sphere. drawSphericalTriangle(SPHERE, PT1, PT2, PT3); Draws the spherical triangle defined by the three input 3D points and the reference sphere. Points are given as 3D points, and are projected onto the sphere. The order of the points is not relevant. drawSphericalTriangle(SPHERE, PT1, PT2, PT3, OPTIONS); Allows to specify plot options for spherical edges, in the form of parameter name-value pairs. Example % Draw a sphere and a spherical triangle on it s = [0 0 0 2]; pts = [1 0 0;0 -1 0;0 0 1]; drawSphere(s); hold on; drawSphericalTriangle(s, pts(1,:), pts(2,:), pts(3,:), 'linewidth', 2); view(3); axis equal; See also drawSphere, fillSphericalTriangle, drawSphericalPolygon, drawSphericalEdge --------- author : David Legland INRA - TPV URPOI - BIA IMASTE created the 22/02/2005
0001 function varargout = drawSphericalTriangle(sphere, p1, p2, p3, varargin) 0002 %DRAWSPHERICALTRIANGLE Draw a triangle on a sphere. 0003 % 0004 % drawSphericalTriangle(SPHERE, PT1, PT2, PT3); 0005 % Draws the spherical triangle defined by the three input 3D points and 0006 % the reference sphere. 0007 % Points are given as 3D points, and are projected onto the sphere. The 0008 % order of the points is not relevant. 0009 % 0010 % drawSphericalTriangle(SPHERE, PT1, PT2, PT3, OPTIONS); 0011 % Allows to specify plot options for spherical edges, in the form of 0012 % parameter name-value pairs. 0013 % 0014 % Example 0015 % % Draw a sphere and a spherical triangle on it 0016 % s = [0 0 0 2]; 0017 % pts = [1 0 0;0 -1 0;0 0 1]; 0018 % drawSphere(s); hold on; 0019 % drawSphericalTriangle(s, pts(1,:), pts(2,:), pts(3,:), 'linewidth', 2); 0020 % view(3); axis equal; 0021 % 0022 % See also 0023 % drawSphere, fillSphericalTriangle, drawSphericalPolygon, 0024 % drawSphericalEdge 0025 % 0026 % --------- 0027 % author : David Legland 0028 % INRA - TPV URPOI - BIA IMASTE 0029 % created the 22/02/2005 0030 % 0031 0032 % HISTORY 0033 % 2007-06-27 manage spheres other than origin 0034 % 2008-10-30 replace intersectPlaneLine by intersectLinePlane 0035 % 2012-02-09 put drawing code into the 'drawSphericalEdge' function 0036 % 2012-10-24 add holding facility, updtate doc 0037 0038 0039 % extract data of the sphere 0040 ori = sphere(:, 1:3); 0041 0042 % extract direction vectors for each point 0043 v1 = normalizeVector3d(p1 - ori); 0044 v2 = normalizeVector3d(p2 - ori); 0045 v3 = normalizeVector3d(p3 - ori); 0046 0047 % keep hold state of current axis 0048 h = ishold; 0049 0050 % draw each spherical edge 0051 hold on; 0052 h1 = drawSphericalEdge(sphere, [v1 v2], varargin{:}); 0053 h2 = drawSphericalEdge(sphere, [v2 v3], varargin{:}); 0054 h3 = drawSphericalEdge(sphere, [v3 v1], varargin{:}); 0055 0056 % return to previous hold state if needed 0057 if ~h 0058 hold off; 0059 end 0060 0061 if nargout > 0 0062 varargout = {h1, h2, h3}; 0063 end