Code covered by the BSD License

# SimMechanics Parameterized Part Examples

### Steve Miller (view profile)

07 May 2012 (Updated )

Parameterized parts for SimMechanics, including MATLAB functions for defining extrusions.

```function [xy_data] = Extr_Data_RectRounded(height, width, radius, varargin)
%Extr_Data_RectRounded Produce extrusion data for a rectangle with rounded corners.
%   [xy_data] = Extr_Data_RectRounded(height, width, radius, varargin)
%   This function returns x-y data for a rectangle with rounded corners.
%   You can specify:
%       Height          height
%       Width           width
%
%   To see a plot showing parameter values, enter the name
%   of the function with no arguments
%   >> Extr_Data_RectRounded
%
%   To see a plot created with your parameter values,
%   add 'plot' as the final argument
%   >> Extr_Data_RectRounded(6,4,1,'plot')

% Copyright 2012 The MathWorks, Inc.

% DEFAULT DATA TO SHOW DIAGRAM
if (nargin == 0)
height = 6;
width = 4;
end

% CHECK IF PLOT SHOULD BE PRODUCED
if (isempty(varargin))
showplot = 'n';
else
showplot = varargin;
end

% CALCULATE QUARTER ELLIPSE

xy_data = [xyset1; xyset2; xyset3; xyset4; xyset5; xyset6; xyset7; xyset8];

% PLOT DIAGRAM TO SHOW PARAMETERS AND EXTRUSION
if (nargin == 0 || strcmpi(showplot,'plot'))
% PLOT EXTRUSION
plot(xy_data(:,1),xy_data(:,2),'b-o','LineWidth',1.5);
axis('square');
axis([-1.1 1.1 -1.1 1.1]*max(height/2,width/2));

% SHOW PARAMETERS
hold on

plot([0 0],[-height/2 height/2],'r-d','MarkerFaceColor','r');
text(0,height/2*0.5,'{\color{red}height}');

plot([-width/2 width/2],[0 0],'g-d','MarkerFaceColor','g');
text(width/2*0.5,height*0.01,'{\color{green}width}');