-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPolywithHole.m
More file actions
112 lines (76 loc) · 2 KB
/
Copy pathPolywithHole.m
File metadata and controls
112 lines (76 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
n = "Enter the number of sides:";
N = input(n);
F= zeros(1,N);
X=F;
Y=F;
for s=1:N
B ="Enter x coordinate:";
C ="Enter y coordinate";
b= input(B);
c= input(C);
X(1,s)= b;
Y(1,s)= c;
end
% check if inputs are same size
if ~isequal( size(x), size(y) )
error( 'X and Y must be the same size');
end
% temporarily shift data to mean of vertices for improved accuracy
xm = mean(X);
ym = mean(Y);
x = X - xm;
y = Y - ym;
% summations for CCW boundary
xp = x( [2:end 1] );
yp = y( [2:end 1] );
a = x.*yp - xp.*y;
A = sum( a ) /2;
xc = sum( (x+xp).*a ) /6/A;
yc = sum( (y+yp).*a ) /6/A;
Ixx = (sum( (y.*y +y.*yp + yp.*yp).*a ) /12)*(-1);
Iyy = (sum( (x.*x +x.*xp + xp.*xp).*a ) /12)*(-1);
% centroidal moments
Iuu = Ixx - A*yc*yc;
Ivv = Iyy - A*xc*xc;
% replace mean of vertices
x_cen = xc + xm;
y_cen = yc + ym;
Ixx = (Iuu + A*y_cen*y_cen)*(-1);
Iyy = (Ivv + A*x_cen*x_cen)*(-1);
%For the circular hole
r=input("Enter the radius of the hole:");
areaCir= (pi*((r)^2))
cx=input("Enter the x coordinate of the center of hole:");
cy=input("Enter the y coordinate of the center of hole:");
centroidCir = [cx cy];
Icir=(5*pi*(r^4))/4;
%Verification whether the slot is inside
t=0;
for s=1:N
d = sqrt((X(s)-cx)^2+(Y(s)-cy)^2);
if (d>r)
t = t+1;
else
disp("hole is outside");
break
end
end
E = A-Ac;
if(t == N)
Cex = ((A*x_cen-Ac*cx)/A-Ac);
Cey = ((A*y_cen-Ac*cy)/A-Ac);
dcx = (Cex - cx);
dcy = (Cey - cy);
drx = (Cex - x_cen);
dry = (Cey - y_cen);
MIX=Iuu-Icir+(A*drx*drx)-(areaCir*dcx*dcx);
MIY=Ivv-Icir+(A*dry*dry)-(areaCir*dcy*dcy);
Ixx = MIX+ E*(Cex*Cex);
Iyy = MIY+ E*(Cey*Cey);
% return values
disp("Centroid point:");
Centroid = [Cex Cey]
disp("Moment of inertia on Centroidal Axis:");
Ic = [MIX MIY]
disp("Moment of inertia along X-axis and Y-axis:");
I = [ Ixx Iyy]