Home > matGeom > geom3d > drawSphericalTriangle.m

drawSphericalTriangle

PURPOSE ^

DRAWSPHERICALTRIANGLE Draw a triangle on a sphere.

SYNOPSIS ^

function varargout = drawSphericalTriangle(varargin)

DESCRIPTION ^

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function varargout = drawSphericalTriangle(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 % ------
0028 % Author: David Legland
0029 % E-mail: david.legland@inrae.fr
0030 % Created: 2005-02-22
0031 % Copyright 2005-2024 INRA - TPV URPOI - BIA IMASTE
0032 
0033 % extract handle of axis to draw on
0034 [hAx, varargin] = parseAxisHandle(varargin{:});
0035 
0036 sphere = varargin{1};
0037 p1 = varargin{2};
0038 p2 = varargin{3};
0039 p3 = varargin{4};
0040 varargin(1:4) = [];
0041 
0042 % extract data of the sphere
0043 ori = sphere(:, 1:3);
0044 
0045 % extract direction vectors for each point
0046 v1  = normalizeVector3d(p1 - ori);
0047 v2  = normalizeVector3d(p2 - ori);
0048 v3  = normalizeVector3d(p3 - ori);
0049 
0050 % keep hold state of current axis
0051 holdState = ishold(hAx);
0052 hold(hAx, 'on');
0053 
0054 % draw each spherical edge
0055 h1 = drawSphericalEdge(hAx, sphere, [v1 v2], varargin{:});
0056 h2 = drawSphericalEdge(hAx, sphere, [v2 v3], varargin{:});
0057 h3 = drawSphericalEdge(hAx, sphere, [v3 v1], varargin{:});
0058 
0059 % return to previous hold state if needed
0060 if ~holdState
0061     hold(hAx, 'off');
0062 end
0063 
0064 if nargout > 0
0065     varargout = {h1, h2, h3};
0066 end

Generated on Thu 21-Nov-2024 11:30:22 by m2html © 2003-2022