91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 4KB
    文件類型: .py
    金幣: 1
    下載: 0 次
    發布日期: 2021-06-01
  • 語言: Python
  • 標簽: DP??python??

資源簡介

實現了道格拉斯普克算法的Python源代碼,用于處理數據壓縮

資源截圖

代碼片段和文件信息

#?-*-?coding=utf-8?-*-

import?gpxpy
import?gpxpy.gpx
import?math
from?pyproj?import?Proj

#定義一個點類
class?cPoint:
????x=0.0
????y=0.0
????index=0

????def?__init__(selfxyindex):
????????self.x=x
????????self.y=y
????????self.index=index



#定義道格拉斯普克算法類
class?Douglas:
????cPoints=[]?#存儲點的列表
????D=1??????#在道格拉斯普克算法中需要自定義設置的閾值
????def?__init__(selfcPoints):
????????self.cPoints=cPoints
????def?compress(selfp1p2):
????????oPoints=[]
????????swichvalue=False
????????#判斷是否需要進行抽稀算法
????????#直線一般式方程的3個系數


????????A=(p1.y-p2.y)/math.sqrt(math.pow(p1.y-p2.y2)+math.pow(p1.x-p2.x2))
????????B=(p2.x-p1.x)/math.sqrt(math.pow(p1.y-p2.y2)+math.pow(p1.x-p2.x2))
????????C=(p1.x*p2.y-p2.x*p1.y)/math.sqrt(math.pow(p1.y-p2.y2)+math.pow(p1.x-p2.x2))
????????m=self.cPoints.index(p1)
????????n=self.cPoints.index(p2)
????????#print?m
????????#print?n
????????distance=[]
????????middle=None
????????if(n==m+1):????#判斷起點和終點之間是否有點
????????????return
????????#計算中間點到直線的距離
????????for?i?in?range(m+1n):
????????????d=abs(A*self.cPoints[i].x+B*self.cPoints[i].y+C)/math.sqrt(math.pow(A2)+math.pow(B2))
????????????distance.append(d)
????????dmax=max(distance)
????????#print?distance
????????if?dmax>self.D:
????????????swichvalue=True
????????else:
????????????swichvalue=False
????????#for?i?in?range(09):
????????????#print?self.cPoints[i].x
????????if(swichvalue==False):
????????????for?j?in?range(m+1n):
????????????????#del?self.cPoints[j]
????????????????self.cPoints[j].x=0
????????else:
????????????for?h?in?range(m+1n):
????????????????if(abs(A*self.cPoints[h].x+B*self.cPoints[h].y+C)/math.sqrt(math.pow(A2)+math.pow(B2))==dmax):
????????????????????middle=self.cPoints[h]
????????????self.compress(p1middle)
????????????self.compress(middlep2)

????????#for?i?in?range(0len(self.cPoints)):
????????????#if?self.cPoints[i].x!=0:
????????????????#oPoints.append(self.cPoints[i])

????????return?oPoints



????def?__init__(selfmpoin

評論

共有 條評論