1## Copyright (C) 2021 David Legland 2## All rights reserved. 3## 4## Redistribution and use in source and binary forms, with or without 5## modification, are permitted provided that the following conditions are met: 6## 7## 1 Redistributions of source code must retain the above copyright notice, 8## this list of conditions and the following disclaimer. 9## 2 Redistributions in binary form must reproduce the above copyright 10## notice, this list of conditions and the following disclaimer in the 11## documentation and/or other materials provided with the distribution. 12## 13## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' 14## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 17## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 20## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 21## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23## 24## The views and conclusions contained in the software and documentation are 25## those of the authors and should not be interpreted as representing official 26## policies, either expressed or implied, of the copyright holders. 27 28function varargout = drawPlatform(plane, siz, varargin) 29%DRAWPLATFORM Draw a rectangular platform with a given size. 30% 31% drawPlatform(PLANE, SIZ) draws a rectangular platform with the 32% dimensions specified by SIZ. If SIZ contains only one value instead of 33% two the platform will be quadratic. 34% 35% drawPlatform(...,'PropertyName',PropertyValue,...) sets the value of 36% the specified patch property. Multiple property values can be set with 37% a single statement. See function patch for details. 38% 39% drawPlane3d(AX,...) plots into AX instead of GCA. 40% 41% H = drawPlatform(...) returns a handle H to the patch object. 42% 43% Example 44% 45% p0 = [1 2 3]; 46% v1 = [1 0 1]; 47% v2 = [0 -1 1]; 48% plane = [p0 v1 v2]; 49% axis([-10 10 -10 10 -10 10]); 50% drawPlatform(plane, [7,3]) 51% set(gcf, 'renderer', 'zbuffer'); 52% 53% See also 54% planes3d, createPlane, patch 55 56% ------ 57% Author: oqilipo 58% Created: 2018-08-09 59% Copyright 2018 60 61%% Parse inputs 62 63% extract axis handle 64if isAxisHandle(plane) 65 hAx = plane; 66 plane = siz; 67 siz = varargin{1}; 68 varargin(1) = []; 69else 70 hAx = gca; 71end 72 73% parse optional arguments 74p = inputParser; 75addRequired(p, 'plane', @(x) size(x,1)==1 && isPlane(x)) 76addRequired(p, 'siz', @(x)validateattributes(x,{'numeric'},... 77 {'size',[1, nan],'positive','nonnan','real','finite'})) 78parse(p, plane, siz) 79 80if ~isempty(varargin) 81 if length(varargin) == 1 82 if isstruct(varargin{1}) 83 % if options are specified as struct, need to convert to 84 % parameter name-value pairs 85 varargin = [fieldnames(varargin{1}) struct2cell(varargin{1})]'; 86 varargin = varargin(:)'; 87 else 88 % if option is a single argument, assume it corresponds to 89 % plane color 90 varargin = {'FaceColor', varargin{1}}; 91 end 92 end 93else 94 % default face color 95 varargin = {'FaceColor', 'm'}; 96end 97 98if numel(siz) == 1 99 siz(2) = siz(1); 100end 101 102 103%% Algorithm 104% Calculate vertex points of the platform 105pts(1,:) = planePoint(plane, [1,1]*0.5.*siz); 106pts(2,:) = planePoint(plane, [1,-1]*0.5.*siz); 107pts(3,:) = planePoint(plane, [-1,-1]*0.5.*siz); 108pts(4,:) = planePoint(plane, [-1,1]*0.5.*siz); 109 110pf.vertices = pts; 111pf.faces = [1 2 3 4]; 112 113% Draw the patch 114h = patch(hAx, pf, varargin{:}); 115 116 117%% Parse outputs 118% Return handle to plane if needed 119if nargout > 0 120 varargout{1} = h; 121end 122 123end 124 125