计算任意多边形的几何惯性矩 |
您所在的位置:网站首页 › 圆环惯性矩计算程序怎么写 › 计算任意多边形的几何惯性矩 |
考虑一个程序,该程序从封闭的节点信息中输出区域的惯性矩。 基于此,可以很容易地计算出横截面主力矩,横截面面积和横截面系数。 定义公式 区域的惯性矩为 $$ I_z = \\ int_A y ^ 2 dA \\标签{1} $$ 由 给出。这是针对横截面中的每个点计算的$ y ^ 2 $的总和。 写代码 这次,假定参数作为顶点信息数组传递。例如:
由于它是 多边形,因此可以用梯形网格划分,该梯形网格由第N个顶点,N 1个顶点及其垂直线组成。
在上图的情况下,如果将蓝色区域返回为正数,将红色区域返回为负数,则可以。 梯形的等式(1)可以直接求解,如果斜边的线性函数为$ y = ax b $,则 12I_z = \int_{x_i}^{x_{i+1}} \int_{y_i}^{y_{i+1}} y^2 dy dx = \frac{1}{12a} \left\{ ( ax_{i+1} + b )^4 - ( ax_i + b)^4 \right\} \tag{2a}但是,当$ a = 0 $(即矩形)时, 1I_z = \frac{1}{3} b^3 \left(x_{i+1} - x_i \right) \tag{2b}变为 。 码(2a)和(2b)可以原样表达。参数node为 1node = [[x1, y1], [x2, y2], ...]期望 格式。但是,它不能很好地工作,因此我认为最好使用numpy方法。 123456789101112131415161718def moment_of_inertia_of_area(nodes): nodes = move_x_to_positive(nodes) # 後述 func = reformat_nodes_to_func(nodes) # 後述 ans = 0.0 for f in func: x1, x2 = f[0], f[1] a, b = f[2][0], f[2][1] if a == 0: inte = (b ** 3) * (x2 - x1) / 3 else: inte = ((a * x2 + b) ** 4 - (a * x1 + b) ** 4) / (12 * a) ans += inte return ans出现在中间的 move_x_to_positive(node)是将x移至0或更大的功能。 reformat_nodes_to_func是作为[x1, x2, a, b]数组返回的函数。这方面取决于参数的采用方式,因此我认为有必要进行适当的调整。 123456789101112131415161718192021def move_x_to_positive(nodes): min_x = min(list(map(lambda node: node[0], nodes))) nodes = list(map(lambda node: [node[0] - min_x, node[1]], nodes)) return nodes def reformat_nodes_to_func(nodes): func_list = [ [nodes[i][0], nodes[i + 1][0], calc_slope_and_intercept( nodes[i][0], nodes[i][1], nodes[i + 1][0], nodes[i + 1][1])] for (i, x) in enumerate(nodes[:-1]) ] return func_list def calc_slope_and_intercept(xi, yi, xj, yj): try: slope = (yi - yj) / (xi - xj) y_intercept = yi - slope * xi except ZeroDivisionError: slope, y_intercept = 0, 0 return slope, y_intercept这里很脏。这是大约2年前的代码.... 好吧,如果您移动的话,就可以了! !! !! !! 这就是 的全部。优点是无需库即可进行计算。 |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |