Draw a plane clipped by the current axes. drawPlane3d(PLANE) draws a plane of the format: [x0 y0 z0 dx1 dy1 dz1 dx2 dy2 dz2] drawPlane3d(..., 'PropertyName', PropertyValue,...) Sets the value of the specified patch property. Multiple property values can be set with a single statement. See the function "patch" for details. drawPlane3d(AX,...) plots into AX instead of GCA. H = drawPlane3d(...) returns a handle H to the patch object. Example % Draw a plane, its main axes, and its normal vector p0 = [1 2 3]; v1 = [1 0 1]; v2 = [0 -1 1]; plane = [p0 v1 v2]; figure; axis([-10 10 -10 10 -10 10]); hold on; view(3); drawPlane3d(plane); drawLine3d([p0 v1]); drawLine3d([p0 v2]); set(gcf, 'renderer', 'zbuffer'); vn = crossProduct3d(v1, v2); drawVector3d(p0, vn); See also planes3d, createPlane, clipPlane, patch
0001 function h = drawPlane3d(plane, varargin) 0002 % Draw a plane clipped by the current axes. 0003 % 0004 % drawPlane3d(PLANE) draws a plane of the format: 0005 % [x0 y0 z0 dx1 dy1 dz1 dx2 dy2 dz2] 0006 % 0007 % drawPlane3d(..., 'PropertyName', PropertyValue,...) 0008 % Sets the value of the specified patch property. Multiple property 0009 % values can be set with a single statement. See the function "patch" for 0010 % details. 0011 % 0012 % drawPlane3d(AX,...) 0013 % plots into AX instead of GCA. 0014 % 0015 % H = drawPlane3d(...) 0016 % returns a handle H to the patch object. 0017 % 0018 % Example 0019 % % Draw a plane, its main axes, and its normal vector 0020 % p0 = [1 2 3]; 0021 % v1 = [1 0 1]; 0022 % v2 = [0 -1 1]; 0023 % plane = [p0 v1 v2]; 0024 % figure; axis([-10 10 -10 10 -10 10]); hold on; view(3); 0025 % drawPlane3d(plane); 0026 % drawLine3d([p0 v1]); 0027 % drawLine3d([p0 v2]); 0028 % set(gcf, 'renderer', 'zbuffer'); 0029 % vn = crossProduct3d(v1, v2); 0030 % drawVector3d(p0, vn); 0031 % 0032 % See also 0033 % planes3d, createPlane, clipPlane, patch 0034 0035 % ------ 0036 % Author: David Legland 0037 % e-mail: david.legland@inrae.fr 0038 % INRA - TPV URPOI - BIA IMASTE 0039 % created the 17/02/2005. 0040 % 0041 % HISTORY 0042 % 2008-10-30 replace intersectPlaneLine by intersectLinePlane, add doc 0043 % 2010-10-04 fix a bug for planes touching box by one corner 0044 % 2011-07-19 fix a bug for param by Xin KANG (Ben) 0045 % 0046 0047 % add support for drawing multiple planes at once 0048 if size(plane, 1) > 1 0049 nPlanes = size(plane, 1); 0050 hp = zeros(nPlanes, 1); 0051 for iPlane = 1:nPlanes 0052 hp(iPlane) = drawPlane3d(plane(iPlane, :), varargin{:}); 0053 end 0054 0055 if nargout > 0 0056 h = hp; 0057 end 0058 0059 return; 0060 end 0061 0062 % Parse and check inputs 0063 valFun = @(x) size(x,1)==1 && isPlane(x); 0064 defOpts.FaceColor = 'm'; 0065 [hAx, plane, varargin] = ... 0066 parseDrawInput(plane, valFun, 'patch', defOpts, varargin{:}); 0067 0068 % extract axis bounds to crop plane 0069 lim = get(hAx, 'xlim'); 0070 xmin = lim(1); 0071 xmax = lim(2); 0072 lim = get(hAx, 'ylim'); 0073 ymin = lim(1); 0074 ymax = lim(2); 0075 lim = get(hAx, 'zlim'); 0076 zmin = lim(1); 0077 zmax = lim(2); 0078 0079 poly = clipPlane(plane, [xmin xmax ymin ymax zmin zmax]); 0080 0081 % If there is no intersection point, escape. 0082 if isempty(poly) 0083 disp('plane is outside the drawing window'); 0084 if nargout > 0 0085 h = []; 0086 end 0087 return; 0088 end 0089 0090 % draw the patch 0091 htmp = patch( ... 0092 'XData', poly(:, 1), ... 0093 'YData', poly(:, 2), ... 0094 'ZData', poly(:, 3), ... 0095 'Parent', hAx, varargin{:}); 0096 0097 % Do not return axis if not requested 0098 % avoids output when called without semicolon 0099 if nargout > 0 0100 h = htmp; 0101 end 0102