|
1 | | -function [xy_data] = Extr_Data_TriangleRounded_Holes(L, H, xL, ri, ro, varargin) |
2 | | -%Extr_Data_TriangleRounded_Holes Produce extrusion data for a triangle |
3 | | -%with rounded corners and a hole at each corner. with an arbitrary |
4 | | -% [xy_data] = Extr_Data_TriangleRounded_Holes(L, W, r, h) |
5 | | -% This function returns x-y data for the triangle. |
6 | | -% You can specify: |
7 | | -% Distance between lower holes L |
8 | | -% Distance from line connecting H |
9 | | -% lower holes to uppper hole |
10 | | -% Hole inner radius ri |
11 | | -% Triangle corner radius ro |
12 | | -% Top hole offset (0-1)*L xL |
13 | | -% |
14 | | -% To see a plot showing parameter values, enter the name |
15 | | -% of the function with no arguments |
16 | | -% >> Extr_Data_TriangleRounded_Holes |
17 | | -% |
18 | | -% To see a plot created with your parameter values, |
19 | | -% add 'plot' as the final argument |
20 | | -% >> Extr_Data_TriangleRounded_Holes(10,5,1,2,'plot') |
21 | | -% |
22 | | -% Copyright 2014-2023 The MathWorks, Inc. |
23 | | - |
24 | | -% Default data to show diagram |
25 | | -if (nargin == 0) |
26 | | - L = 6; |
27 | | - H = 4; |
28 | | - ri = 1; |
29 | | - ro = 1.5; |
30 | | - xL = 0.33; |
31 | | -end |
32 | | - |
33 | | -% Check if plot should be produced |
34 | | -if (isempty(varargin)) |
35 | | - showplot = 'n'; |
36 | | -else |
37 | | - showplot = char(varargin); |
38 | | -end |
39 | | - |
40 | | -% Calculate lengths and angles |
41 | | -ang_R2H = atan2d(H,(xL*L)); |
42 | | -ang_F2H = atan2d(H,((1-xL)*L)); |
43 | | - |
44 | | -xy_data1 = [L -ro]; |
45 | | -xy_data2 = [cosd(270:-1:-90); sind(270:-1:-90)]'*ri+[L 0]; |
46 | | -xy_data3 = [cosd(-90:1:90-ang_F2H); sind(-90:1:90-ang_F2H)]'*ro+[L 0]; |
47 | | -xy_data4 = [cosd(90-ang_F2H); sind(90-ang_F2H)]'*ro+[xL*L H]; |
48 | | -xy_data5 = [cosd(90-ang_F2H:-1:(90-ang_F2H-360)); sind(90-ang_F2H:-1:(90-ang_F2H-360))]'*ri+[xL*L H]; |
49 | | -xy_data6 = [cosd(90-ang_F2H:1:(ang_R2H+90)); sind(90-ang_F2H:1:(ang_R2H+90))]'*ro+[xL*L H]; |
50 | | -xy_data7 = [cosd(ang_R2H+90); sind(ang_R2H+90)]'*ro; |
51 | | -xy_data8 = [cosd((ang_R2H+90):-1:(ang_R2H-270)); sind((ang_R2H+90):-1:(ang_R2H-270))]'*ri; |
52 | | -xy_data9 = [cosd((ang_R2H-270):1:-90); sind((ang_R2H-270):1:-90)]'*ro; |
53 | | - |
54 | | -xy_data = [xy_data1; xy_data2; xy_data3; xy_data4; xy_data5;xy_data6; xy_data7;xy_data8;xy_data9]; |
55 | | - |
56 | | -% Plot diagram to show parameters and extrusion |
57 | | -if (nargin == 0 || strcmpi(showplot,'plot')) |
58 | | - % Figure name |
59 | | - figString = ['h1_' mfilename]; |
60 | | - % Only create a figure if no figure exists |
61 | | - figExist = 0; |
62 | | - fig_hExist = evalin('base',['exist(''' figString ''')']); |
63 | | - if (fig_hExist) |
64 | | - figExist = evalin('base',['ishandle(' figString ') && strcmp(get(' figString ', ''type''), ''figure'')']); |
65 | | - end |
66 | | - if ~figExist |
67 | | - fig_h = figure('Name',figString); |
68 | | - assignin('base',figString,fig_h); |
69 | | - else |
70 | | - fig_h = evalin('base',figString); |
71 | | - end |
72 | | - figure(fig_h) |
73 | | - clf(fig_h) |
74 | | - |
75 | | - % Plot extrusion |
76 | | - patch(xy_data(:,1),xy_data(:,2),[1 1 1]*0.95,'EdgeColor','none'); |
77 | | - hold on |
78 | | - plot(xy_data(:,1),xy_data(:,2),'-','Marker','o','MarkerSize',4,'LineWidth',2); |
79 | | - |
80 | | - axis('equal'); |
81 | | - |
82 | | - % Show parameters |
83 | | - plot([0 L],[0 0],'r-d','MarkerFaceColor','r'); |
84 | | - text(L/2,H/15,'{\color{red}L}'); |
85 | | - plot([1 1]*xL*L,[0 H],'b-d','MarkerFaceColor','b'); |
86 | | - text(xL*L*1.1,H/2,'{\color{blue}H}'); |
87 | | - plot([0 ri*sin(30*pi/180)],[0 ri*cos(30*pi/180)],'k-d','MarkerFaceColor','k'); |
88 | | - text(ri*sin(30*pi/180)*0.5,0.5*ri*cos(30*pi/180),'ri'); |
89 | | - plot([0 ro*cosd(-180)],[0 ro*sind(-180)],'g-d','MarkerFaceColor','g'); |
90 | | - text(ri*cosd(-180)*0.5,H/15,'{\color{green}ro}'); |
91 | | - plot([0 xL*L],[-1 -1]*ri/2,'m-d','MarkerFaceColor','m'); |
92 | | - text(xL*L/2,-ri/2-H/15,'{\color{magenta}xL*L}'); |
93 | | - |
94 | | - title('[xy\_data] = Extr\_Data\_TriangleRounded\_Holes(L, H, ri, ro, xL);'); |
95 | | - hold off |
96 | | - box on |
97 | | - clear xy_data |
98 | | -end |
99 | | - |
100 | | - |
| 1 | +function [xy_data] = Extr_Data_TriangleRounded_Holes(L, H, xL, ri, ro, varargin) |
| 2 | +%Extr_Data_TriangleRounded_Holes Produce extrusion data for a triangle |
| 3 | +%with rounded corners and a hole at each corner. with an arbitrary |
| 4 | +% [xy_data] = Extr_Data_TriangleRounded_Holes(L, W, r, h) |
| 5 | +% This function returns x-y data for the triangle. |
| 6 | +% You can specify: |
| 7 | +% Distance between lower holes L |
| 8 | +% Distance from line connecting H |
| 9 | +% lower holes to uppper hole |
| 10 | +% Hole inner radius ri |
| 11 | +% Triangle corner radius ro |
| 12 | +% Top hole offset (0-1)*L xL |
| 13 | +% |
| 14 | +% To see a plot showing parameter values, enter the name |
| 15 | +% of the function with no arguments |
| 16 | +% >> Extr_Data_TriangleRounded_Holes |
| 17 | +% |
| 18 | +% To see a plot created with your parameter values, |
| 19 | +% add 'plot' as the final argument |
| 20 | +% >> Extr_Data_TriangleRounded_Holes(10,5,1,2,'plot') |
| 21 | +% |
| 22 | +% Copyright 2014-2023 The MathWorks, Inc. |
| 23 | + |
| 24 | +% Default data to show diagram |
| 25 | +if (nargin == 0) |
| 26 | + L = 6; |
| 27 | + H = 4; |
| 28 | + ri = 1; |
| 29 | + ro = 1.5; |
| 30 | + xL = 0.33; |
| 31 | +end |
| 32 | + |
| 33 | +% Check if plot should be produced |
| 34 | +if (isempty(varargin)) |
| 35 | + showplot = 'n'; |
| 36 | +else |
| 37 | + showplot = char(varargin); |
| 38 | +end |
| 39 | + |
| 40 | +% Calculate lengths and angles |
| 41 | +ang_R2H = atan2d(H,(xL*L)); |
| 42 | +ang_F2H = atan2d(H,((1-xL)*L)); |
| 43 | + |
| 44 | +xy_data1 = [L -ro]; |
| 45 | +xy_data2 = [cosd(270:-1:-90); sind(270:-1:-90)]'*ri+[L 0]; |
| 46 | +xy_data3 = [cosd(-90:1:90-ang_F2H); sind(-90:1:90-ang_F2H)]'*ro+[L 0]; |
| 47 | +xy_data4 = [cosd(90-ang_F2H); sind(90-ang_F2H)]'*ro+[xL*L H]; |
| 48 | +xy_data5 = [cosd(90-ang_F2H:-1:(90-ang_F2H-360)); sind(90-ang_F2H:-1:(90-ang_F2H-360))]'*ri+[xL*L H]; |
| 49 | +xy_data6 = [cosd(90-ang_F2H:1:(ang_R2H+90)); sind(90-ang_F2H:1:(ang_R2H+90))]'*ro+[xL*L H]; |
| 50 | +xy_data7 = [cosd(ang_R2H+90); sind(ang_R2H+90)]'*ro; |
| 51 | +xy_data8 = [cosd((ang_R2H+90):-1:(ang_R2H-270)); sind((ang_R2H+90):-1:(ang_R2H-270))]'*ri; |
| 52 | +xy_data9 = [cosd((ang_R2H-270):1:-90); sind((ang_R2H-270):1:-90)]'*ro; |
| 53 | + |
| 54 | +xy_data = [xy_data1; xy_data2; xy_data3; xy_data4; xy_data5;xy_data6; xy_data7;xy_data8;xy_data9]; |
| 55 | + |
| 56 | +% Plot diagram to show parameters and extrusion |
| 57 | +if (nargin == 0 || strcmpi(showplot,'plot')) |
| 58 | + % Figure name |
| 59 | + figString = ['h1_' mfilename]; |
| 60 | + % Only create a figure if no figure exists |
| 61 | + figExist = 0; |
| 62 | + fig_hExist = evalin('base',['exist(''' figString ''')']); |
| 63 | + if (fig_hExist) |
| 64 | + figExist = evalin('base',['ishandle(' figString ') && strcmp(get(' figString ', ''type''), ''figure'')']); |
| 65 | + end |
| 66 | + if ~figExist |
| 67 | + fig_h = figure('Name',figString); |
| 68 | + assignin('base',figString,fig_h); |
| 69 | + else |
| 70 | + fig_h = evalin('base',figString); |
| 71 | + end |
| 72 | + figure(fig_h) |
| 73 | + clf(fig_h) |
| 74 | + |
| 75 | + % Plot extrusion |
| 76 | + patch(xy_data(:,1),xy_data(:,2),[1 1 1]*0.95,'EdgeColor','none'); |
| 77 | + hold on |
| 78 | + plot(xy_data(:,1),xy_data(:,2),'-','Marker','o','MarkerSize',4,'LineWidth',2); |
| 79 | + |
| 80 | + axis('equal'); |
| 81 | + |
| 82 | + % Show parameters |
| 83 | + plot([0 L],[0 0],'r-d','MarkerFaceColor','r'); |
| 84 | + text(L/2,H/15,'{\color{red}L}'); |
| 85 | + plot([1 1]*xL*L,[0 H],'b-d','MarkerFaceColor','b'); |
| 86 | + text(xL*L*1.1,H/2,'{\color{blue}H}'); |
| 87 | + plot([0 ri*sin(30*pi/180)],[0 ri*cos(30*pi/180)],'k-d','MarkerFaceColor','k'); |
| 88 | + text(ri*sin(30*pi/180)*0.5,0.5*ri*cos(30*pi/180),'ri'); |
| 89 | + plot([0 ro*cosd(-180)],[0 ro*sind(-180)],'g-d','MarkerFaceColor','g'); |
| 90 | + text(ri*cosd(-180)*0.5,H/15,'{\color{green}ro}'); |
| 91 | + plot([0 xL*L],[-1 -1]*ri/2,'m-d','MarkerFaceColor','m'); |
| 92 | + text(xL*L/2,-ri/2-H/15,'{\color{magenta}xL*L}'); |
| 93 | + |
| 94 | + title('[xy\_data] = Extr\_Data\_TriangleRounded\_Holes(L, H, ri, ro, xL);'); |
| 95 | + hold off |
| 96 | + box on |
| 97 | + clear xy_data |
| 98 | +end |
| 99 | + |
| 100 | + |
0 commit comments