背景
etabs自定义截面
公式
This code uses the following formulas:
Area of the polygon:
A = 1 2 ∑ i = 1 n ( x i y i + 1 − x i + 1 y i ) A = \frac{1}{2} \sum_{i=1}^{n} (x_i y_{i+1} - x_{i+1} y_i) A=21i=1∑n(xiyi+1−xi+1yi)
Centroid coordinates:
C x = 1 6 A ∑ i = 1 n ( x i + x i + 1 ) ( x i y i + 1 − x i + 1 y i ) C_x = \frac{1}{6A} \sum_{i=1}^{n} (x_i + x_{i+1})(x_i y_{i+1} - x_{i+1} y_i) Cx=6A1i=1∑n(xi+xi+1)(xiyi+1−xi+1yi)
C y = 1 6 A ∑ i = 1 n ( y i + y i + 1 ) ( x i y i + 1 − x i + 1 y i ) C_y = \frac{1}{6A} \sum_{i=1}^{n} (y_i + y_{i+1})(x_i y_{i+1} - x_{i+1} y_i) Cy=6A1i=1∑n(yi+yi+1)(xiyi+1−xi+1yi)
Moment of inertia:
I
x
=
1
12
∑
i
=
0
n
−
1
(
y
i
2
+
y
i
y
i
+
1
+
y
i
+
1
2
)
(
x
i
y
i
+
1
−
x
i
+
1
y
i
)
Ix = \frac{1}{12}\sum{i=0}^{n-1} (yi^2 + yiy{i+1} + y{i+1}^2)(xi y{i+1} - x{i+1} yi)
Ix=121∑i=0n−1(yi2+yiyi+1+yi+12)(xiyi+1−xi+1yi)
I
y
=
1
12
∑
i
=
0
n
−
1
(
x
i
2
+
x
i
x
i
+
1
+
x
i
+
1
2
)
(
x
i
y
i
+
1
−
x
i
+
1
y
i
)
Iy = \frac{1}{12}\sum{i=0}^{n-1} (xi^2 + xi x{i+1} + x{i+1}^2)(xi y{i+1} - x{i+1} yi)
Iy=121∑i=0n−1(xi2+xixi+1+xi+12)(xiyi+1−xi+1yi)
I
x
y
=
1
24
∑
i
=
0
n
−
1
(
2
x
i
y
i
+
x
i
+
1
y
i
+
2
x
i
+
1
y
i
+
1
+
x
i
y
i
+
1
)
(
x
i
y
i
+
1
−
x
i
+
1
y
i
)
I{xy} = \frac{1}{24}\sum{i=0}^{n-1} (2xi yi + x{i+1} yi + 2x{i+1} y{i+1} + xi y{i+1})(xi y{i+1} - x{i+1} yi)
Ixy=241∑i=0n−1(2xiyi+xi+1yi+2xi+1yi+1+xiyi+1)(xiyi+1−xi+1yi)
其中,
n
n
n 是多边形的顶点数,
(
x
i
,
y
i
)
(xi,yi)
(xi,yi) 表示多边形中第
i
i
i 个顶点的坐标,
(
x
i
+
1
,
y
i
+
1
)
(x{i+1},y{i+1})
(xi+1,yi+1) 表示多边形中第
i
+
1
i+1
i+1 个顶点的坐标,
I
x
Ix
Ix 代表多边形相对于
x
x
x 轴的惯性矩,
I
y
Iy
Iy 代表多边形相对于
y
y
y 轴的惯性矩,
I
x
y
I_{xy}
Ixy 代表多边形相对于
x
x
x 和
y
y
y 轴的二次惯性矩。
代码
import matplotlib.pyplot as plt
def polygon_area(vertices):
n = len(vertices)
area = 0
for i in range(n):
area += (vertices[i][0] * vertices[(i + 1) % n][1] - vertices[(i + 1) % n][0] * vertices[i][1])
return 0.5 * abs(area)
def centroid(vertices):
n = len(vertices)
cx, cy = 0, 0
area = polygon_area(vertices)
for i in range(n):
factor = (vertices[i][0] * vertices[(i + 1) % n][1] - vertices[(i + 1) % n][0] * vertices[i][1])
cx += (vertices[i][0] + vertices[(i + 1) % n][0]) * factor
cy += (vertices[i][1] + vertices[(i + 1) % n][1]) * factor
return (1 / (6 * area)) * cx, (1 / (6 * area)) * cy
def moment_of_inertia(vertices):
n = len(vertices)
Ix, Iy, Ixy = 0, 0, 0
area = polygon_area(vertices)
for i in range(n):
factor = (vertices[i][0] * vertices[(i + 1) % n][1] - vertices[(i + 1) % n][0] * vertices[i][1])
Ix += (vertices[i][1]**2 + vertices[i][1]*vertices[(i + 1) % n][1] + vertices[(i + 1) % n][1]**2) * factor
Iy += (vertices[i][0]**2 + vertices[i][0]*vertices[(i + 1) % n][0] + vertices[(i + 1) % n][0]**2) * factor
Ixy += (vertices[i][0]*vertices[(i + 1) % n][1] + 2*vertices[i][0]*vertices[i][1] + 2*vertices[(i + 1) % n][0]*vertices[(i + 1) % n][1] + vertices[(i + 1) % n][0]*vertices[i][1]) * factor
return (1 / 12) * abs(Ix), (1 / 12) * abs(Iy), (1 / 24) * abs(Ixy)
def plot_polygon(vertices, centroid):
polygon = plt.Polygon(vertices, fill=None, edgecolor='r', linewidth=2)
plt.gca().add_patch(polygon)
plt.scatter(*centroid, color='blue', marker='o', s=100, label='Centroid')
plt.axis('equal')
plt.legend()
plt.show()
# 可增加,从cad中读取
vertices = [(0, 0), (30, 0), (30, 30), (0, 30), (-20, 20)]
area = polygon_area(vertices)
centroid_coordinates = centroid(vertices)
Ix, Iy, Ixy = moment_of_inertia(vertices)
print("Area:", area)
print("Centroid:", centroid_coordinates)
print("Moment of Inertia: Ix =", Ix, "Iy =", Iy, "Ixy =", Ixy)
plot_polygon(vertices, centroid_coordinates)
总结
常用的markdown编辑器可以渲染latex格式代码
常用公式可以编程