Home > matGeom > geom3d > drawPlatform.m

drawPlatform

PURPOSE ^

DRAWPLATFORM Draw a rectangular platform with a given size.

SYNOPSIS ^

function varargout = drawPlatform(plane, siz, varargin)

DESCRIPTION ^

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function  varargout = drawPlatform(plane, siz, 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 % Created: 2018-08-09
0032 % Copyright 2018
0033 
0034 %% Parse inputs
0035 
0036 % extract axis handle
0037 if isAxisHandle(plane)
0038     hAx = plane;
0039     plane = siz;
0040     siz = varargin{1};
0041     varargin(1) = [];
0042 else
0043     hAx = gca;
0044 end
0045 
0046 % parse optional arguments
0047 p = inputParser;
0048 addRequired(p, 'plane', @(x) size(x,1)==1 && isPlane(x))
0049 addRequired(p, 'siz', @(x)validateattributes(x,{'numeric'},...
0050     {'size',[1, nan],'positive','nonnan','real','finite'}))
0051 parse(p, plane, siz)
0052 
0053 if ~isempty(varargin)
0054     if length(varargin) == 1
0055         if isstruct(varargin{1})
0056             % if options are specified as struct, need to convert to
0057             % parameter name-value pairs
0058             varargin = [fieldnames(varargin{1}) struct2cell(varargin{1})]';
0059             varargin = varargin(:)';
0060         else
0061             % if option is a single argument, assume it corresponds to
0062             % plane color
0063             varargin = {'FaceColor', varargin{1}};
0064         end
0065     end
0066 else
0067     % default face color
0068     varargin = {'FaceColor', 'm'};
0069 end
0070 
0071 if numel(siz) == 1
0072     siz(2) = siz(1);
0073 end
0074 
0075 
0076 %% Algorithm
0077 % Calculate vertex points of the platform
0078 pts(1,:) = planePoint(plane, [1,1]*0.5.*siz);
0079 pts(2,:) = planePoint(plane, [1,-1]*0.5.*siz);
0080 pts(3,:) = planePoint(plane, [-1,-1]*0.5.*siz);
0081 pts(4,:) = planePoint(plane, [-1,1]*0.5.*siz);
0082 
0083 pf.vertices = pts;
0084 pf.faces = [1 2 3 4];
0085 
0086 % Draw the patch
0087 h = patch(hAx, pf, varargin{:});
0088 
0089 
0090 %% Parse outputs
0091 % Return handle to plane if needed
0092 if nargout > 0
0093     varargout{1} = h;
0094 end
0095 
0096 end
0097

Generated on Wed 16-Feb-2022 15:10:47 by m2html © 2003-2019