• aalitao77
    了解作者
  • Python
    开发工具
  • 48KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 3
    下载次数
  • 2021-04-24 18:54
    上传日期
Python用于生成多边形骨料的混凝土细观模型
随机骨料.zip
  • 多边形
  • __pycache__
  • randomparticle.cpython-36.pyc
    7.3KB
  • tkinterui.cpython-36.pyc
    3KB
  • tkinterui.py
    4.3KB
  • figure.png
    19.5KB
  • temp1.py
    358B
  • result2
    32KB
  • main1.py
    255B
  • result1
    3.4KB
  • randomparticle.py
    8.3KB
内容介绍
# /usr/bin/env python # -*- coding:utf-8 -*- import numpy as np import random from pyautocad import Autocad, APoint import pickle import os import matplotlib.pyplot as plt import matplotlib as mpl import math from numpy.linalg import * import pandas class RandomParticle(object): def __init__(self, modulewidth, modulelength, radiuslower, radiusupper, volumefraction, distancefactor): self.modulewidth = modulewidth self.modulelength = modulelength self.radiuslower = radiuslower self.radiusupper = radiusupper self.volumefraction = volumefraction self.distancefactor = distancefactor self.acad = Autocad(create_if_not_exists=True) def circlePolyganGeneration(self): circleinfo = [] polyganinfo = [] random.seed(1000) radius = random.uniform(self.radiuslower, self.radiusupper) xcordlist = np.array( [random.uniform(self.distancefactor * radius, self.modulewidth - self.distancefactor * radius)]) ycordlist = np.array( [random.uniform(self.distancefactor * radius, self.modulelength - self.distancefactor * radius)]) rlist = np.array([radius]) polyganinfo.append(self.polyganGeneration(xcordlist[-1], ycordlist[-1], rlist[-1])) volumeexistance = polyganinfo[-1][2] / (self.modulewidth * self.modulelength) while volumeexistance < self.volumefraction: radius = random.uniform(self.radiuslower, self.radiusupper) xcord = random.uniform(self.distancefactor * radius, self.modulewidth - self.distancefactor * radius) ycord = random.uniform(self.distancefactor * radius, self.modulelength - self.distancefactor * radius) overlapcount = 0 for i in range(len(xcordlist)): position1 = np.array([xcord, ycord]) position2 = np.array([xcordlist[i], ycordlist[i]]) radius1 = radius radius2 = rlist[i] if self.overlapJudgement(radius1, position1, radius2, position2): overlapcount += 1 if overlapcount == 0: # 等价于np.concatenate((ycordlist,[ycord])) xcordlist = np.append(xcordlist, xcord) ycordlist = np.append(ycordlist, ycord) rlist = np.append(rlist, radius) polyganinfo.append(self.polyganGeneration(xcordlist[-1], ycordlist[-1], rlist[-1])) volumeexistance += polyganinfo[-1][2] / (self.modulewidth * self.modulelength) circleinfo = [xcordlist, ycordlist, rlist] return circleinfo, polyganinfo def overlapJudgement(self, radius1, position1, radius2, position2): distance = sum((position1 - position2) ** 2) ** 0.5 if distance <= (radius1 + radius2) * self.distancefactor: return True else: return False def cadDrawingParticle(self, particleinfo): for i in range(len(particleinfo[0])): self.acad.doc.SendCommand('c %f,%f,0 %f\n' % (particleinfo[0][i], particleinfo[1][i], particleinfo[2][i])) def cadDrawingRec(self): self.acad.doc.SendCommand('rec 0,0 %f,%f\n' % (self.modulelength, self.modulewidth)) def cadDrawingRegion(self): self.acad.doc.SendCommand('region all \n') def cadDrawingUnion(self): self.acad.doc.SendCommand('union all \n') def cadDrawingSave(self, path): self.acad.doc.SaveAs(path) def informationSave(self, particleinfo, filename): path = os.path.join(os.getcwd(), filename) with open(path, 'wb') as f: pickle.dump(particleinfo, f) def particleDistribution(self, particleinfo): mpl.rcParams['font.sans-serif'] = 'NSimSun,Times New Roman' x = particleinfo[2] fig, (ax0, ax1) = plt.subplots(nrows=2, figsize=(9, 6)) # 第二个参数是柱子宽一些还是窄一些,越大越窄越密 ax0.hist(x, 100, normed=1, histtype='bar', facecolor='yellowgreen', alpha=0.75) ##pdf概率分布图,一万个数落在某个区间内的数有多少个 ax0.set_title('Size Distribution') ax1.hist(x, 20, normed=1, histtype='bar', facecolor='pink', alpha=0.75, cumulative=True, rwidth=0.8) # cdf累计概率函数,cumulative累计。比如需要统计小于5的数的概率 ax1.set_title("Cucumative Size Distribution") fig.subplots_adjust(hspace=0.4) plt.savefig(os.path.join(os.getcwd(), 'figure')) def cadDrawingPolygan(self, polyganinfo): for polygan in polyganinfo: for j in range(len(polygan[0]) - 1): p1 = APoint(polygan[0][j], polygan[1][j]) p2 = APoint(polygan[0][j + 1], polygan[1][j + 1]) self.acad.model.AddLine(p1, p2) def polyganGeneration(self, xcenter, ycenter, r0): # 产生多边形 polyganinfo = [] corner = random.choice(np.array([4, 5, 7])) if corner == 4: angle = np.random.uniform(0, 360, 4) while not self.angleDifference(angle): angle = np.random.uniform(0, 360, 4) # 保证x,y为相邻坐标点组成的x或y坐标矩阵。x为三维向量 angle = np.sort(angle) # 该圆心对应的多边形有三个顶点,这三个顶点的x坐标为: x = np.array([xcenter + r0 * math.cos(theta / 180 * math.pi) for theta in angle]) y = np.array([ycenter + r0 * math.sin(theta / 180 * math.pi) for theta in angle]) # 增加起点用于面积计算和连线 x = np.append(x, x[0]) y = np.append(y, y[0]) s = self.polyganAreaCalculation(x, y) return [x, y, s] elif corner == 5: angle = np.random.uniform(0, 360, 5) while not self.angleDifference(angle): angle = np.random.uniform(0, 360, 5) # 保证x,y为相邻坐标点组成的x或y坐标矩阵。x为五维向量 angle = np.sort(angle) # 该圆心对应的多边形有三个顶点,这三个顶点的x坐标为: x = np.array([xcenter + r0 * math.cos(theta / 180 * math.pi) for theta in angle]) y = np.array([ycenter + r0 * math.sin(theta / 180 * math.pi) for theta in angle]) x = np.append(x, x[0]) y = np.append(y, y[0]) s = self.polyganAreaCalculation(x, y) return [x, y, s] else: angle = np.random.uniform(0, 360, 7) while not self.angleDifference(angle): angle = np.random.uniform(0, 360, 7) # 保证x,y为相邻坐标电组成的x或y坐标矩阵。x为7维向量 angle = np.sort(angle) # 该圆心对应的多边形有三个顶点,这三个顶点的x坐标为: x = np.array([xcenter + r0 * math.cos(theta / 180 * math.pi) for theta in angle]) y = np.array([ycenter + r0 * math.sin(theta / 180 * math.pi) for theta in angle]) x = np.append(x, x[0]) y = np.append(y, y[0]) s = self.polyganAreaCalculation(x, y) return [x, y, s] def triangleAreaCalculationTheta(self, circlecenter, theta1, theta2, radius): # 由正弦定理计算三角形面积,theta1,theta2为角度 theta = abs(theta1 - theta2) area = 0.5 * radius ** 2 * math.sin(theta * math.pi / 180) def triangleAreaCalculationPoint(self, circlecenter, point1, point2): # 由向量定理计算三角形面积 A = np.array([[1, circlecenter[0], circlecenter[1]], [1, point1[0], point1[1]], [1, point2[0], point2[1]]]) area = 0.5 * det(A) def polyganAreaCalculation(self, x, y): s = 0 for i in range(len(x) - 1)
评论
    相关推荐
    • 任意多边形.rar
      python 调用 cad 随机骨料模型
    • matlabcnhelp.rar
      matlab中文帮助很难找的,快速下载
    • MobilePolice.rar
      移动警察,车牌识别,车牌定位系统源代码,已经运用在移动车载稽查系统中。
    • SVM(matlab).rar
      支持向量机(SVM)实现的分类算法源码[matlab]
    • svm.zip
      用MATLAB编写的svm源程序,可以实现支持向量机,用于特征分类或提取
    • Classification-MatLab-Toolbox.rar
      模式识别matlab工具箱,包括SVM,ICA,PCA,NN等等模式识别算法,很有参考价值
    • VC++人脸定位实例.rar
      一个经典的人脸识别算法实例,提供人脸五官定位具体算法及两种实现流程.
    • QPSK_Simulink.rar
      QPSK的Matlab/Simulink的调制解调仿真系统,给出接收信号眼图及系统仿真误码率,包含载波恢复,匹配滤波,定时恢复等重要模块,帮助理解QPSK的系统
    • LPRBPDemo2009KV.rar
      车牌识别,神经网络算法,识别率高达95%,识别时间低于80ms。
    • MODULATION.RAR
      这个源程序代码包提供了通信系统中BPSK,QPSK,OQPSK,MSK,MSK2,GMSK,QAM,QAM16等调制解调方式 用matlab的实现,以及它们在AWGN和Rayleigh信道下的通信系统实现及误码率性能