Hier werden die Unterschiede zwischen zwei Versionen gezeigt.
Beide Seiten der vorigen Revision Vorhergehende Überarbeitung Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
ws1415:projekte_im_wintersemester_2014_15:nuetzliche_programmschnipsel [2014/11/27 10:23] stefanborn [3d-Dreiecke zeichnen] |
ws1415:projekte_im_wintersemester_2014_15:nuetzliche_programmschnipsel [2016/05/10 14:46] (aktuell) |
||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
===== Nützliche Programmschnipsel ===== | ===== Nützliche Programmschnipsel ===== | ||
+ | |||
+ | ==== Test für Objektorientierte Dreiecke ==== | ||
+ | <code Python> | ||
+ | import numpy as np | ||
+ | import matplotlib.pyplot as plt | ||
+ | from mpl_toolkits.mplot3d import Axes3D | ||
+ | import matplotlib.tri as mtri | ||
+ | from scipy.spatial import Delaunay | ||
+ | |||
+ | |||
+ | |||
+ | xinput=[1,2,3,4] | ||
+ | yinput=[1,2,3,4] | ||
+ | |||
+ | z=[] | ||
+ | x=[] | ||
+ | y=[] | ||
+ | |||
+ | |||
+ | def do(xinput,yinput): | ||
+ | xlange=len(xinput) | ||
+ | ylange=len(yinput) | ||
+ | for i in range((xlange*ylange)): | ||
+ | z.append(np.random.uniform(1,3,size=None)) | ||
+ | |||
+ | for i in range(xlange): | ||
+ | for ii in range(xlange): | ||
+ | x.append(i) | ||
+ | |||
+ | for i in range(ylange): | ||
+ | for ii in range(ylange): | ||
+ | y.append(ii) | ||
+ | do(xinput,yinput) | ||
+ | |||
+ | Array=np.array([x,y]).T | ||
+ | def triang(x,y,z): | ||
+ | global tri | ||
+ | |||
+ | tri = Delaunay(Array) | ||
+ | fig = plt.figure() | ||
+ | ax = fig.add_subplot(1, 1, 1, projection='3d') | ||
+ | ax.plot_trisurf(x, y, z, triangles=tri.simplices, cmap=plt.cm.Spectral) | ||
+ | |||
+ | triang(x,y,z) | ||
+ | dreiecke=[] | ||
+ | def eckpunkte(simplices): | ||
+ | for bla in range(len(simplices)): | ||
+ | dreieck=[] | ||
+ | sxyz=tri.simplices[bla] | ||
+ | #x | ||
+ | sx=sxyz[0] | ||
+ | ssx=Array[sx] | ||
+ | dreieck.append(ssx) | ||
+ | |||
+ | #y | ||
+ | sy=sxyz[1] | ||
+ | ssy=Array[sy] | ||
+ | dreieck.append(ssy) | ||
+ | |||
+ | #z | ||
+ | sz=sxyz[2] | ||
+ | ssz=Array[sz] | ||
+ | dreieck.append(ssz) | ||
+ | dreiecke.append(dreieck) | ||
+ | eckpunkte(tri.simplices) | ||
+ | print dreiecke | ||
+ | |||
+ | |||
+ | plt.show() | ||
+ | </code> | ||
+ | ==== Funktionierende Triangulierung ==== | ||
+ | |||
+ | <code Python> | ||
+ | def Show(NAME): | ||
+ | |||
+ | import numpy as np | ||
+ | import matplotlib.pyplot as plt | ||
+ | from mpl_toolkits.mplot3d import Axes3D | ||
+ | import matplotlib.tri as mtri | ||
+ | from scipy.spatial import Delaunay | ||
+ | |||
+ | rangey=[] | ||
+ | rangex=[] | ||
+ | z=[] | ||
+ | myArray = np.loadtxt(NAME) | ||
+ | zeilen,spalten=myArray.shape | ||
+ | |||
+ | for i in range(zeilen): | ||
+ | for ii in range(zeilen): | ||
+ | rangex.append(i) | ||
+ | |||
+ | for i in range(spalten): | ||
+ | for i in range(spalten): | ||
+ | rangey.append(i) | ||
+ | reader=open(NAME,'r') | ||
+ | z1=reader.read() | ||
+ | reader.close() | ||
+ | z1=z1.replace("\n","") | ||
+ | z1=(z1.split()) | ||
+ | |||
+ | for word in z1: | ||
+ | z.append(word) | ||
+ | z=map(int,z) | ||
+ | |||
+ | tri = Delaunay(np.array([rangex,rangey]).T) | ||
+ | fig = plt.figure() | ||
+ | ax = fig.add_subplot(1, 1, 1, projection='3d') | ||
+ | ax.plot_trisurf(rangex, rangey, z, triangles=tri.simplices, cmap=plt.cm.BrBG) | ||
+ | plt.show() | ||
+ | print len(tri.simplices) | ||
+ | |||
+ | if __name__ == '__main__': | ||
+ | Show("montblanc1.asc") | ||
+ | </code> | ||
+ | |||
+ | |||
==== 3d-Punkte zeichnen ==== | ==== 3d-Punkte zeichnen ==== |