DRAWPLATFORM Draw a rectangular platform with a given size. drawPlatform(PLANE, SIZ) draws a rectangular platform with the dimensions specified by SIZ. If SIZ contains only one value instead of two the platform will be quadratic. drawPlatform(...,'PropertyName',PropertyValue,...) sets the value of the specified patch property. Multiple property values can be set with a single statement. See function patch for details. drawPlane3d(AX,...) plots into AX instead of GCA. H = drawPlatform(...) returns a handle H to the patch object. Example p0 = [1 2 3]; v1 = [1 0 1]; v2 = [0 -1 1]; plane = [p0 v1 v2]; axis([-10 10 -10 10 -10 10]); drawPlatform(plane, [7,3]) set(gcf, 'renderer', 'zbuffer'); See also planes3d, createPlane, patch
0001 function varargout = drawPlatform(varargin) 0002 %DRAWPLATFORM Draw a rectangular platform with a given size. 0003 % 0004 % drawPlatform(PLANE, SIZ) draws a rectangular platform with the 0005 % dimensions specified by SIZ. If SIZ contains only one value instead of 0006 % two the platform will be quadratic. 0007 % 0008 % drawPlatform(...,'PropertyName',PropertyValue,...) sets the value of 0009 % the specified patch property. Multiple property values can be set with 0010 % a single statement. See function patch for details. 0011 % 0012 % drawPlane3d(AX,...) plots into AX instead of GCA. 0013 % 0014 % H = drawPlatform(...) returns a handle H to the patch object. 0015 % 0016 % Example 0017 % 0018 % p0 = [1 2 3]; 0019 % v1 = [1 0 1]; 0020 % v2 = [0 -1 1]; 0021 % plane = [p0 v1 v2]; 0022 % axis([-10 10 -10 10 -10 10]); 0023 % drawPlatform(plane, [7,3]) 0024 % set(gcf, 'renderer', 'zbuffer'); 0025 % 0026 % See also 0027 % planes3d, createPlane, patch 0028 0029 % ------ 0030 % Author: oqilipo 0031 % E-mail: N/A 0032 % Created: 2018-08-09 0033 % Copyright 2018-2024 0034 0035 %% Parse inputs 0036 0037 % extract handle of axis to draw on 0038 [hAx, varargin] = parseAxisHandle(varargin{:}); 0039 0040 % retrieve plane and size 0041 plane = varargin{1}; 0042 siz = varargin{2}; 0043 varargin(1:2) = []; 0044 0045 % parse optional arguments 0046 p = inputParser; 0047 addRequired(p, 'plane', @(x) size(x,1)==1 && isPlane(x)) 0048 addRequired(p, 'siz', @(x)validateattributes(x,{'numeric'},... 0049 {'size',[1, nan],'positive','nonnan','real','finite'})) 0050 parse(p, plane, siz) 0051 0052 if ~isempty(varargin) 0053 if isscalar(varargin) 0054 if isstruct(varargin{1}) 0055 % if options are specified as struct, need to convert to 0056 % parameter name-value pairs 0057 varargin = [fieldnames(varargin{1}) struct2cell(varargin{1})]'; 0058 varargin = varargin(:)'; 0059 else 0060 % if option is a single argument, assume it corresponds to 0061 % plane color 0062 varargin = {'FaceColor', varargin{1}}; 0063 end 0064 end 0065 else 0066 % default face color 0067 varargin = {'FaceColor', 'm'}; 0068 end 0069 0070 if isscalar(siz) 0071 siz(2) = siz(1); 0072 end 0073 0074 0075 %% Algorithm 0076 % Calculate vertex points of the platform 0077 pts(1,:) = planePoint(plane, [1,1]*0.5.*siz); 0078 pts(2,:) = planePoint(plane, [1,-1]*0.5.*siz); 0079 pts(3,:) = planePoint(plane, [-1,-1]*0.5.*siz); 0080 pts(4,:) = planePoint(plane, [-1,1]*0.5.*siz); 0081 0082 pf.vertices = pts; 0083 pf.faces = [1 2 3 4]; 0084 0085 % Draw the patch 0086 h = patch(hAx, pf, varargin{:}); 0087 0088 0089 %% Parse outputs 0090 % Return handle to plane if needed 0091 if nargout > 0 0092 varargout{1} = h; 0093 end 0094 0095 end 0096