Skip to content

Commit

Permalink
Initial commit R2024a
Browse files Browse the repository at this point in the history
  • Loading branch information
smiller01985 committed Aug 22, 2024
1 parent a6e37b5 commit 23f0b5f
Show file tree
Hide file tree
Showing 603 changed files with 5,957 additions and 0 deletions.
101 changes: 101 additions & 0 deletions MPL_Core/Libraries/Extrusions/Extr_Data_Box.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
function [xy_data] = Extr_Data_Box(box_ox, box_ix, varargin)
%Extr_Data_Box Produce extrusion data for a hollow box.
% [xy_data] = Extr_Data_Box(box_ox, box_ix, <box_oy>, <box_iy>)
% This function returns x-y data for a hollow box.
% You can specify:
% Box outer width (x) box_ox
% Box inner width (x) box_ix
% (optional) Box outer height (y) box_oy
% (optional) Box inner height (y) box_iy
%
% To see a plot showing parameter values, enter the name
% of the function with no arguments
% >> Extr_Data_Box
%
% To see a plot created with your parameter values,
% add 'plot' as the final argument
% >> Extr_Data_Box(10,5,'plot')

% Copyright 2013-2024 The MathWorks, Inc.

% Default data to show diagram
if (nargin == 0)
box_ox = 15;
box_ix = 12;
box_oy = 10;
box_iy = 5;
elseif (nargin <= 3)
box_oy = box_ox;
box_iy = box_ix;
elseif (nargin > 3)
box_oy = varargin{1};
box_iy = varargin{2};
end

if (nargin==0)
showplot = 'plot';
elseif (nargin==3 || nargin==5)
showplot = varargin(end);
else
showplot = 'n';
end

% Generate extrusion data
x_signs = [1 -1 -1 1]';
y_signs = [1 1 -1 -1]';
xy_data = [box_ox/2*x_signs box_oy/2*y_signs];
if(box_ix>0 && box_iy>0)
xy_data = [xy_data;box_ox/2 box_oy/2;box_ix/2*y_signs box_iy/2*x_signs;box_ix/2 box_iy/2];
end

% Plot diagram to show parameters and extrusion
if (nargin == 0 || strcmpi(showplot,'plot'))

% Figure name
figString = ['h1_' mfilename];
% Only create a figure if no figure exists
figExist = 0;
fig_hExist = evalin('base',['exist(''' figString ''')']);
if (fig_hExist)
figExist = evalin('base',['ishandle(' figString ') && strcmp(get(' figString ', ''type''), ''figure'')']);
end
if ~figExist
fig_h = figure('Name',figString);
assignin('base',figString,fig_h);
else
fig_h = evalin('base',figString);
end
figure(fig_h)
clf(fig_h)

% Get max axis dimension
maxd = max(box_ox,box_oy);

% Plot extrusion
patch(xy_data(:,1),xy_data(:,2),[1 1 1]*0.90,'EdgeColor','none');
hold on
plot(xy_data(:,1),xy_data(:,2),'-','Marker','o','MarkerSize',4,'LineWidth',2);
axis('equal');
axis([-1.1 1.1 -1.1 1.1]*maxd/2);

% Show parameters
hold on

plot([-1 1]*box_ox/2,[0 0],'r-d','MarkerFaceColor','r');
text(0.25*box_ox,0.025*maxd,'{\color{red}box\_ox}');

plot([0 0],[-1 1]*box_oy/2,'g-d','MarkerFaceColor','g');
text(0,-0.4*box_oy,'{\color{green}box\_oy}');

if(box_ix>0 && box_iy>0)
plot([-1 1]*box_ix/2,[1 1]*0.25*box_iy,'b-d','MarkerFaceColor','b');
text(0.25*box_ix,0.03*maxd+0.25*box_iy,'{\color{blue}box\_ix}');

plot([-1 -1]*0.25*box_ix,[-1 1]*box_iy/2,'k-d','MarkerFaceColor','k');
text(-0.25*box_ix+0.03*maxd,0.4*box_iy,'{\color{black}box\_iy}');
end
title('[xy\_data] = Extr\_Data\_Box(box\_ox, box\_ix, <box\_oy, box\_iy>);');
hold off
box on
clear xy_data
end
178 changes: 178 additions & 0 deletions MPL_Core/Libraries/Extrusions/Extr_Data_BoxFillet.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
function [xy_data] = Extr_Data_BoxFillet(box_ox, box_oy, rad_o, varargin)
%Extr_Data_BoxFillet Produce extrusion data for a rectangle with rounded corners.
% [xy_data] = Extr_Data_BoxFillet(height, width, radius, varargin)
% This function returns x-y data for a rectangle with rounded corners.
% You can specify:
% Outer width box_ox
% Outer height box_oy
% Radius, outer fillet rad_o
% Inner width box_ix
% Inner height box_iy
% Radius, inner fillet rad_i
%
% To see a plot showing parameter values, enter the name
% of the function with no arguments
% >> Extr_Data_BoxFillet
%
% To see a plot created with your parameter values,
% add 'plot' as the final argument
% >> Extr_Data_BoxFillet(6,4,1,2,4,0,5,'plot')

% Copyright 2012-2024 The MathWorks, Inc.

% Default data to show diagram
if (nargin == 0)
box_oy = 6;
box_ox = 4;
rad_o = 1;
box_ix = 2;
box_iy = 4;
rad_i = 0.5;
end

if (nargin == 3 || nargin == 4)
box_ix = 0;
box_iy = 0;
rad_i = 0;
end

if (nargin >= 6)
box_ix = varargin{1};
box_iy = varargin{2};
rad_i = varargin{3};
end

if (nargin == 4 || nargin == 7)
showplot = varargin{end};
else
showplot = 'n';
end

% Check if plot should be produced
if (isempty(varargin))
showplot = 'n';
end

% Create outer profile
if (rad_o>0)
xyset1 = [box_ox/2-rad_o box_oy/2;-box_ox/2+rad_o box_oy/2];
xyset3 = [-box_ox/2 -rad_o+box_oy/2;-box_ox/2 -box_oy/2+rad_o];
xyset5 = [-box_ox/2+rad_o -box_oy/2;box_ox/2-rad_o -box_oy/2];
xyset7 = [box_ox/2 -box_oy/2+rad_o;box_ox/2 box_oy/2-rad_o];

xyset2 = [Extr_Data_Ring(rad_o,0,91,179)];
xyset2(:,1) = xyset2(:,1)+(-box_ox/2+rad_o);
xyset2(:,2) = xyset2(:,2)+(box_oy/2-rad_o);
xyset4 = [Extr_Data_Ring(rad_o,0,181,269)];
xyset4(:,1) = xyset4(:,1)+(-box_ox/2+rad_o);
xyset4(:,2) = xyset4(:,2)+(-box_oy/2+rad_o);
xyset6 = [Extr_Data_Ring(rad_o,0,271,359)];
xyset6(:,1) = xyset6(:,1)+(box_ox/2-rad_o);
xyset6(:,2) = xyset6(:,2)+(-box_oy/2+rad_o);
xyset8 = [Extr_Data_Ring(rad_o,0,1,89)];
xyset8(:,1) = xyset8(:,1)+(box_ox/2-rad_o);
xyset8(:,2) = xyset8(:,2)+(box_oy/2-rad_o);
xy_data = [xyset1; xyset2; xyset3; xyset4; xyset5; xyset6; xyset7; xyset8];
else
xyset1 = [box_ox/2 box_oy/2];
xyset3 = [-box_ox/2 box_oy/2];
xyset5 = [-box_ox/2 -box_oy/2];
xyset7 = [box_ox/2 -box_oy/2];
xy_data = [xyset1; xyset3; xyset5; xyset7];
end


% Create inner profile
if (box_ix>0 && box_iy>0)
xy_data = [xy_data; xy_data(1,:)];
if(rad_i>0)
xyset1 = [box_ix/2-rad_i box_iy/2;-box_ix/2+rad_i box_iy/2];
xyset3 = [-box_ix/2 -rad_i+box_iy/2;-box_ix/2 -box_iy/2+rad_i];
xyset5 = [-box_ix/2+rad_i -box_iy/2;box_ix/2-rad_i -box_iy/2];
xyset7 = [box_ix/2 -box_iy/2+rad_i;box_ix/2 box_iy/2-rad_i];

xyset2 = [Extr_Data_Ring(rad_i,0,91,179)];
xyset2(:,1) = xyset2(:,1)+(-box_ix/2+rad_i);
xyset2(:,2) = xyset2(:,2)+(box_iy/2-rad_i);
xyset4 = [Extr_Data_Ring(rad_i,0,181,269)];
xyset4(:,1) = xyset4(:,1)+(-box_ix/2+rad_i);
xyset4(:,2) = xyset4(:,2)+(-box_iy/2+rad_i);
xyset6 = [Extr_Data_Ring(rad_i,0,271,359)];
xyset6(:,1) = xyset6(:,1)+(box_ix/2-rad_i);
xyset6(:,2) = xyset6(:,2)+(-box_iy/2+rad_i);
xyset8 = [Extr_Data_Ring(rad_i,0,1,89)];
xyset8(:,1) = xyset8(:,1)+(box_ix/2-rad_i);
xyset8(:,2) = xyset8(:,2)+(box_iy/2-rad_i);
xy_data_in = [xyset1; xyset2; xyset3; xyset4; xyset5; xyset6; xyset7; xyset8; xyset1(1,:)];
else
xyset1 = [box_ix/2 box_iy/2];
xyset3 = [-box_ix/2 box_iy/2];
xyset5 = [-box_ix/2 -box_iy/2];
xyset7 = [box_ix/2 -box_iy/2];
xy_data_in = [xyset1; xyset3; xyset5; xyset7;xyset1];
end

xy_data = [xy_data;flipud(xy_data_in)];
end

% Plot diagram to show parameters and extrusion
if (nargin == 0 || strcmpi(showplot,'plot'))

% Figure name
figString = ['h1_' mfilename];
% Only create a figure if no figure exists
figExist = 0;
fig_hExist = evalin('base',['exist(''' figString ''')']);
if (fig_hExist)
figExist = evalin('base',['ishandle(' figString ') && strcmp(get(' figString ', ''type''), ''figure'')']);
end
if ~figExist
fig_h = figure('Name',figString);
assignin('base',figString,fig_h);
else
fig_h = evalin('base',figString);
end
figure(fig_h)
clf(fig_h)

% Plot extrusion
patch(xy_data(:,1),xy_data(:,2),[1 1 1]*0.90,'EdgeColor','none');
hold on
plot(xy_data(:,1),xy_data(:,2),'-','Marker','o','MarkerSize',4,'LineWidth',2);
axis('equal');
axis([-1.1 1.1 -1.1 1.1]*max(box_oy/2,box_ox/2));

% Show parameters
hold on

plot([0 0],[-box_oy/2 box_oy/2],'r-d','MarkerFaceColor','r');
text(0,-box_oy/2*0.5,'{\color{red}box\_oy}','HorizontalAlignment','right');

plot([-box_ox/2 box_ox/2],[0 0],'g-d','MarkerFaceColor','g');
text(box_ox/2*0.25,box_oy*0.025,'{\color{green}box\_ox}');

radius_label_angle = 45*(pi/180);
plot([box_ox/2-rad_o box_ox/2-rad_o*(1-cos(radius_label_angle))],[box_oy/2-rad_o box_oy/2-rad_o*(1-sin(radius_label_angle))],'k-d','MarkerFaceColor','k');
text(box_ox/2-rad_o/2*(cos(radius_label_angle))*0.0,box_oy/2-rad_o/2*(sin(radius_label_angle))*0.0,'{\color{black}rad\_o}','HorizontalAlignment','center');
[box_ox/2-rad_o/2*(cos(radius_label_angle)),box_oy/2-rad_o/2*(sin(radius_label_angle))];

if(box_ix > 0 && box_iy > 0)
plot([1 1]*box_ix*0.25,[-box_iy/2 box_iy/2],'b-d','MarkerFaceColor','b');
text(box_ix*0.25,-box_iy/2*0.5,'{\color{blue}box\_iy}');

plot([-box_ix/2 box_ix/2],[1 1]*box_iy*0.25,'c-d','MarkerFaceColor','c');
text(-box_ix/2,box_iy*0.22,'{\color{cyan}box\_ix}');
end

if (rad_i>0)
radius_label_angle = 45*(pi/180);
plot([-box_ix/2+rad_i -box_ix/2+rad_i*(1-cos(radius_label_angle))],[box_iy/2-rad_i box_iy/2-rad_i*(1-sin(radius_label_angle))],'k-d','MarkerFaceColor','k');
text(-box_ix/2+rad_i/2*(cos(radius_label_angle))*0.0,box_iy/2-rad_i/2*(sin(radius_label_angle))*0.0,'{\color{black}rad\_i}','HorizontalAlignment','center');
[-box_ix/2+rad_i/2*(cos(radius_label_angle)),box_iy/2-rad_i/2*(sin(radius_label_angle))];
end

title(['[xy\_data] = Extr\_Data\_BoxFillet(box\_ox, box\_oy, rad\_o,<box\_ix, box\_iy, rad\_i>);']);
hold off
box on
clear xy_data
end
20 changes: 20 additions & 0 deletions MPL_Core/Libraries/Extrusions/Extr_Data_Calc_Area.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function area = Extr_Data_Calc_Area(xy_poly)
%Extr_Data_Calc_Area Compute area of a planar polygon
% area = Extr_Data_Calc_Area(xy_data)
% Returns the area for a planar polygon specified by an N x 2 matrix.
% This method will produce the wrong answer for self-intersecting
% polygons (one side crosses over another). It will work correctly for
% triangles, regular and irregular polygons, convex or concave polygons.
%
% Area is equal to one-half the sum of the determinants:
%
% | x_i y_i |
% | |
% | x_{i+1} y_{i+1} |
%
% as i ranges over [1, N] and i+1 is computed in modular fashion.

% Copyright 2017-2024 The MathWorks, Inc.

area = sum(sum(xy_poly .* ([1 -1] .* circshift(xy_poly, [-1 1])))) / 2;

11 changes: 11 additions & 0 deletions MPL_Core/Libraries/Extrusions/Extr_Data_Calc_Perimeter.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function perimeter = Extr_Data_Calc_Perimeter(xy_poly)
%Extr_Data_Calc_Perimeter Compute perimeter of a planar polygon
% perimeter = Extr_Data_Calc_Perimeter(xy_poly)
% Returns the perimeter for a planar polygon specified by an N x 2 matrix.

% Copyright 2017-2024 The MathWorks, Inc.

seg_vectors = circshift(xy_poly, -1) - xy_poly; % Vectors along each polygon segment
perimeter = sum(sqrt(sum(seg_vectors .* seg_vectors, 2))); % Sum of segment lengths


Loading

0 comments on commit 23f0b5f

Please sign in to comment.