Python等值线生成(TIN三角网)

更新时间:2023-07-06 09:41:17 阅读: 评论:0

Python等值线⽣成(TIN三⾓⽹)
基于TIN三⾓⽹⽣成不光滑等值线
等值线功能实现
英语元音和辅音等值点插值
在⼀条边上按照⾼程值线性插值,计算出待插值⾼程的x,y坐标,并将插值的结果实例成⼀个点类,⽅便统⼀管理,如下所⽰:
#插值函数
def Interpolation(edge,n,i):
if(edge.BeginPoint.H>edge.EndPoint.H):
Hmax=edge.BeginPoint
Hmin=edge.EndPoint
计算机英语
elif(edge.BeginPoint.H<edge.EndPoint.H):
Hmin=edge.BeginPoint
Hmax=edge.EndPoint
if(n>Hmin.H and n<Hmax.H):
dy=Hmax.Y-Hmin.Y
dx=Hmax.X-Hmin.X
linescale=(n-Hmin.H)/(Hmax.H-Hmin.H)
x=Hmin.X+linescale*dx
y=Hmin.Y+linescale*dy
name="{0}-{1}".format(n,i)
eqpoint=Point(name,x,y,n)
return eqpoint
el:
return0
TIN 边界边查找
遍历TIN的每个三⾓形边,我们认为具有邻接三⾓形的边在TIN内部,不具有邻接三⾓形的边是边界边。我们的数据特点是只具有开曲线,所以找到边界边作为某条等值线的⽣成起点⾄关重要,代码如下:
#边界边列表
def BorderTri(Triangle_List):
Border_list=[]
for i in range(0,len(Triangle_List)):
if(len(Triangle_List[i].BaLine.Belonging_Triangle)==1):
Border_list.append(Triangle_List[i].BaLine)
研究生现场确认地点
英语新闻if(len(Triangle_List[i].newLine1.Belonging_Triangle)==1):
Border_list.append(Triangle_List[i].newLine1)
if(len(Triangle_List[i].newLine2.Belonging_Triangle)==1):
Border_list.append(Triangle_List[i].newLine2)
return  Border_list
单个三⾓形内⽣长等值线
在定位的三⾓形内⽣长等值线,根据⼀个三⾓形有且仅有两个等值点,在三⾓形的另外两条边上插值第⼆个等值点,并将所在的边作为新的⽣长起点,如下所⽰:
#⼀个三⾓形内⽣长等值线
def Grow_Eq(triangle,eqedge,n):
point=0
edges=[triangle.wLine2]
vaginacontest
for edge in edges:
if(edge==eqedge):
continue
el:
point=Interpolation(edge,n,edge.Belonging_Triangle[0])
if(point!=0):
break
return edge,point
⼀条等值线⽣成
从边界边的⼀侧按单个三⾓形⽣长等值线,直⾄⽣长到TIN对侧的另⼀条边界边⼀条等值线⽣长完成。
#查找等值点输出等值线序列点
def Equivalent_point(Triangle_List,n):
point=0
eqlinelist=[]
Border_list=bor=BorderTri(Triangle_List)
for borderedge in Border_list:
edge=borderedge
point=Interpolation(edge,n,edge.Belonging_Triangle[0])
if(point!=0):
eqlinelist.append(point)
break
#根据邻接三⾓形⽣成等值线
index=edge.Belonging_Triangle[0]
[edge,point]=Grow_Eq(Triangle_List[index],edge,n)
eqlinelist.append(point)
while(len(edge.Belonging_Triangle)==2):
index=edge.Belonging_Triangle[1]
[edge,point]=Grow_Eq(Triangle_List[index],edge,n)
eqlinelist.append(point)
return eqlinelist
按等⾼距⽣成全部等值线
在TIN的最低点到最⾼点的⾼程范围内,按照⼀定的等⾼距,由低到⾼逐步⽣成每条等值线,直⾄全局等值线⽣成,代码如下:# 全局等⾼线
def Contour_Line(Point_List,Triangle_List,d):
eqlinlists=[]
Hmax=EPSILON
Hmin=1/EPSILON
for p in Point_List:
if(p.H>Hmax):
Hmax=p.H
if(p.H<Hmin):
Hmin=p.H
n=Hmin+d
while(n<Hmax):
eqlinlist=Equivalent_point(Triangle_List,n)
eqlinlists.append(eqlinlist)
n=n+d
return eqlinlists
可视化结果
可视化代码
'''*******************窗体********************'''
# ⽣成⼀个窗体界⾯命名为window
window=tk.Tk()
window.title('TIN')
# 在窗体上⽣成⼀块画布⽤于绘制导线图
canvas = tk.Canvas(window,width=800,height=600,bg ='white')
canvas.place(x=190,y=10)
#画等值线
def Draw_Equivalent_line(eqpointlists,Point_List):
xyminmax=XYMinMax(Point_List)
for eqpointlist in eqpointlists:
for i in range(0,len(eqpointlist)-1):
gxgy1=GaussToScreenCor(xyminmax,eqpointlist[i].X,eqpointlist[i].Y)
gxgy2=GaussToScreenCor(xyminmax,eqpointlist[i+1].X,eqpointlist[i+1].Y)            oval = ate_oval(gxgy1[0]-1, gxgy1[1]-1, gxgy1[0]+1, gxgy1[1]+1)            ova2 = ate_oval(gxgy1[0]-1, gxgy1[1]-1, gxgy1[0]+1, gxgy1[1]+1)            Connect_Point(gxgy1,gxgy2,'red')
bullet train#********调试********
path="D:\等⾼线点数据.txt"
point_list=ReadDataTXT(path)
Net=CreatTIN(point_list)
Draw_TIN(point_list,Net[0])
eqs=Contour_Line(point_list,Net[1],30)
Draw_Equivalent_line(eqs,point_list)
window.mainloop()
'''*******************所有代码在此之上********************'''
等值线(未平滑)
全部代码
#插值函数
the top
def Interpolation(edge,n,i):
if(edge.BeginPoint.H>edge.EndPoint.H):
Hmax=edge.BeginPoint
Hmin=edge.EndPoint
elif(edge.BeginPoint.H<edge.EndPoint.H):
Hmin=edge.BeginPoint
Hmax=edge.EndPoint
if(n>Hmin.H and n<Hmax.H):
dy=Hmax.Y-Hmin.Y
dx=Hmax.X-Hmin.X
linescale=(n-Hmin.H)/(Hmax.H-Hmin.H)
x=Hmin.X+linescale*dx
y=Hmin.Y+linescale*dy
name="{0}-{1}".format(n,i)
eqpoint=Point(name,x,y,n)
return eqpoint
el:
return0
#边界边列表
def BorderTri(Triangle_List):
Border_list=[]
for i in range(0,len(Triangle_List)):
if(len(Triangle_List[i].BaLine.Belonging_Triangle)==1):
Border_list.append(Triangle_List[i].BaLine)
if(len(Triangle_List[i].newLine1.Belonging_Triangle)==1):
Border_list.append(Triangle_List[i].newLine1)
if(len(Triangle_List[i].newLine2.Belonging_Triangle)==1):
soon的意思Border_list.append(Triangle_List[i].newLine2)
Border_list.append(Triangle_List[i].newLine2)
return  Border_list
#⼀个三⾓形内⽣长等值线
def Grow_Eq(triangle,eqedge,n):
point=0
edges=[triangle.wLine2]
for edge in edges:
if(edge==eqedge):
continue
el:
point=Interpolation(edge,n,edge.Belonging_Triangle[0])
if(point!=0):
涨价 英文break
return edge,point
#查找等值点输出等值线序列点
def Equivalent_point(Triangle_List,n):
point=0
eqlinelist=[]
Border_list=bor=BorderTri(Triangle_List)
for borderedge in Border_list:
edge=borderedge
point=Interpolation(edge,n,edge.Belonging_Triangle[0])
if(point!=0):
eqlinelist.append(point)
break
#根据邻接三⾓形⽣成等值线
index=edge.Belonging_Triangle[0]
[edge,point]=Grow_Eq(Triangle_List[index],edge,n)
eqlinelist.append(point)
while(len(edge.Belonging_Triangle)==2):
index=edge.Belonging_Triangle[1]
[edge,point]=Grow_Eq(Triangle_List[index],edge,n)
eqlinelist.append(point)
return eqlinelist
# 全局等⾼线
def Contour_Line(Point_List,Triangle_List,d):
eqlinlists=[]
Hmax=EPSILON
Hmin=1/EPSILON
for p in Point_List:
if(p.H>Hmax):
Hmax=p.H
if(p.H<Hmin):
Hmin=p.H
n=Hmin+d
while(n<Hmax):
eqlinlist=Equivalent_point(Triangle_List,n)
eqlinlists.append(eqlinlist)
n=n+d
return eqlinlists
'''*******************窗体********************'''
# ⽣成⼀个窗体界⾯命名为window
window=tk.Tk()
window.title('TIN')
# 在窗体上⽣成⼀块画布⽤于绘制导线图
canvas = tk.Canvas(window,width=800,height=600,bg ='white') canvas.place(x=190,y=10)
# 画出数据点
def Draw_Point(Point_List):
xyminmax=XYMinMax(Point_List)
for point in Point_List:
gxgy=GaussToScreenCor(xyminmax,point.X,point.Y)
oval = ate_oval(gxgy[0]-1, gxgy[1]-1, gxgy[0]+1, gxgy[1]+1)
oval = ate_oval(gxgy[0]-1, gxgy[1]-1, gxgy[0]+1, gxgy[1]+1) #ate_text(gxgy[0]-13,gxgy[1],text=point.PointName)
# 画出TIN⽹
def Connect_Point(list1,list2,color):
line = ate_line(list1[0], list1[1],list2[0],list2[1],fill = color)
def Draw_TIN(Point_List,Line_List):
xyminmax=XYMinMax(Point_List)
abridge
for line in Line_List:
gxgy1=GaussToScreenCor(xyminmax,line.BeginPoint.X,line.BeginPoint.Y)
gxgy2=GaussToScreenCor(xyminmax,line.EndPoint.X,line.EndPoint.Y)
oval = ate_oval(gxgy1[0]-1, gxgy1[1]-1, gxgy1[0]+1, gxgy1[1]+1)
ova2 = ate_oval(gxgy1[0]-1, gxgy1[1]-1, gxgy1[0]+1, gxgy1[1]+1)        Connect_Point(gxgy1,gxgy2,'black')
#画等值线
def Draw_Equivalent_line(eqpointlists,Point_List):
xyminmax=XYMinMax(Point_List)
for eqpointlist in eqpointlists:
for i in range(0,len(eqpointlist)-1):
gxgy1=GaussToScreenCor(xyminmax,eqpointlist[i].X,eqpointlist[i].Y)
gxgy2=GaussToScreenCor(xyminmax,eqpointlist[i+1].X,eqpointlist[i+1].Y)            oval = ate_oval(gxgy1[0]-1, gxgy1[1]-1, gxgy1[0]+1, gxgy1[1]+1)            ova2 = ate_oval(gxgy1[0]-1, gxgy1[1]-1, gxgy1[0]+1, gxgy1[1]+1)            Connect_Point(gxgy1,gxgy2,'red')
#********调试********
path="D:\等⾼线点数据.txt"
point_list=ReadDataTXT(path)
Draw_Point(point_list)
Net=CreatTIN(point_list)
Draw_TIN(point_list,Net[0])
eqs=Contour_Line(point_list,Net[1],10)
Draw_Equivalent_line(eqs,point_list)
window.mainloop()
'''*******************所有代码在此之上********************'''

本文发布于:2023-07-06 09:41:17,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/90/168738.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

上一篇:时钟表盘代码
下一篇:眼镜专业英语
标签:等值线   等值   插值   具有
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图