2017-09-16 9 views
0

Ich fange gerade mit pyqtgraph an und möchte 3D-Flächen in sphärischen Koordinaten erstellen. Ich habe mir das Beispiel GLSurfacePlot.py aus der Dokumentation angesehen, aber es gibt nur Plots in kartesischen Koordinaten.Sphärische Koordinaten plotten in pyqtgraph

Dies ist die Handlung I (es ist ein Halbwellendipol Abstrahlcharakteristik) machen wollen:

enter image description here

Wie r (theta, phi) mit pyqtgraph zeichnen?

EDIT: ich es mit matplotlib mplot3d tun könnte, hier ist das Skript:

import matplotlib.pyplot as plt 
import numpy as np 
from mpl_toolkits.mplot3d import Axes3D 

k = 2*np.pi 
long = 0.5 
theta = np.linspace(0, np.pi, 361) 
phi = np.linspace(0, 2*np.pi, 361) 
PHI, THETA = np.meshgrid(phi, theta) 
R = np.absolute((np.cos(k*long/2*np.cos(THETA))-np.cos(k*long/2))/np.sin(THETA)) 
R = np.nan_to_num(R) 
X = R * np.sin(THETA) * np.cos(PHI) 
Y = R * np.sin(THETA) * np.sin(PHI) 
Z = R * np.cos(THETA) 

fig = plt.figure() 
ax = fig.add_subplot(111, projection = '3d') 
cmap = plt.get_cmap('jet') 
plot = ax.plot_surface(X, Y, Z, rstride=10, cstride=10, facecolors=cmap(R),linewidth=0, antialiased=False, alpha=1) 

plt.show() 

Das Problem ist, dass es zu langsam ist, wenn Drehen und Zoomen es, und ich brauche auf jeden Fall, dass die Funktion für meine Anwendung , deshalb versuche ich es mit pyqtgraph zu machen.

+0

Sie könnten die mathematische Gleichung setzen – eyllanesc

+0

Was meinst du? – Jorge

+0

Ich meine, was ist die Gleichung 'r (Theta, Phi)' ohne Verwendung von Code. – eyllanesc

Antwort

0

diese Art von Gleichungen Zeichnung ist nicht möglich, durch GLSurfacePlotItem, in diesem Fall, dass Sie GLMeshItem, aber dafür verwenden, müssen Sie eine geeignete MeshData schaffen müssen, so dauert es als Referenz sphere die folgende Funktion zu erhalten:

def DipoleData(rows, cols, func, args=None): 
    verts = np.empty((rows+1, cols, 3), dtype=float) 
    phi = (np.arange(rows+1) * 2*np.pi *(1+2/rows)/ rows).reshape(rows+1, 1) 
    th = ((np.arange(cols) * np.pi/cols).reshape(1, cols)) 

    if args is not None: 
     r = func(th, phi, *args) 
    else: 
     r = func(th, phi) 
    s = r* np.sin(th) 
    verts[...,2] = r * np.cos(th) 
    verts[...,0] = s * np.cos(phi) 
    verts[...,1] = s * np.sin(phi) 

    verts = verts.reshape((rows+1)*cols, 3)[cols-1:-(cols-1)] ## remove redundant vertexes from top and bottom 
    faces = np.empty((rows*cols*2, 3), dtype=np.uint) 
    rowtemplate1 = ((np.arange(cols).reshape(cols, 1) + np.array([[0, 1, 0]])) % cols) + np.array([[0, 0, cols]]) 
    rowtemplate2 = ((np.arange(cols).reshape(cols, 1) + np.array([[0, 1, 1]])) % cols) + np.array([[cols, 0, cols]]) 
    for row in range(rows): 
     start = row * cols * 2 
     faces[start:start+cols] = rowtemplate1 + row * cols 
     faces[start+cols:start+(cols*2)] = rowtemplate2 + row * cols 
    faces = faces[cols:-cols] ## cut off zero-area triangles at top and bottom 

    ## adjust for redundant vertexes that were removed from top and bottom 
    vmin = cols-1 
    faces[faces<vmin] = vmin 
    faces -= vmin 
    vmax = verts.shape[0]-1 
    faces[faces>vmax] = vmax 

    return gl.MeshData(vertexes=verts, faces=faces) 

Es wird dann im folgenden Beispiel verwendet:

app = QtGui.QApplication([]) 
w = gl.GLViewWidget() 
w.opts['distance'] = 3 
w.show() 
w.setWindowTitle('Half Wave Dipole Radiation Pattern') 

def r_theta_phi(theta, phi, k, l): 
    return np.absolute((np.cos((k*l/2)*np.cos(theta)) -np.cos(k*l/2))/np.sin(theta)) 

p = 2*np.pi 
q = 0.5 

md = DipoleData(100, 100, r_theta_phi, args=(p, q)) 
colors = np.ones((md.faceCount(), 4), dtype=float) 
colors[:,0] = np.linspace(0.1, 0.2, colors.shape[0]) 
colors[:,1] = np.linspace(0.2, 0.9, colors.shape[0]) 
colors[:,2] = np.linspace(0.0, 0.1, colors.shape[0]) 
md.setFaceColors(colors) 
m = gl.GLMeshItem(meshdata=md, smooth=False) 
w.addItem(m) 

ax = gl.GLAxisItem() 
ax.setSize(100,100,100) 
w.addItem(ax) 

g = gl.GLGridItem() 
g.scale(0.2, 0.2, 0.2) 
w.addItem(g) 

## Start Qt event loop unless running in interactive mode. 
if __name__ == '__main__': 
    import sys 
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'): 
     QtGui.QApplication.instance().exec_() 

Beziehen, was in der folgenden Abbildung dargestellt wird:

enter image description here

+0

Hmmm, es ist ganz anders als das, wie es aussehen sollte. http://www.antenna-theory.com/antennas/norm3D1lam.jpg – Jorge

+0

Sie können mir bitte das Buch erzählen, vielleicht ist die Gleichung, die Sie mir gegeben haben, eine andere, ich bin ein Electronica Student und ich habe es in anderen Programmen und ich simuliert etwas ähnliches bekommen. : P – eyllanesc

+0

Antennentheorie: Analyse und Design. Konstantin A. Balanis. (Seiten 182-183). Hier können Sie sich eine Aufnahme ansehen, die ich daraus gemacht habe: https://gyazo.com/467868b5353b8eb1d8fb7b35f6d4833b. Ich interessiere mich nur für die normalisierte Größe, also nehme ich den Ausdruck innerhalb der Klammern. Es ist ein einfacherer Ausdruck als der, den ich an dich übergeben habe, weil er bereits die Werte k und l ersetzt hat. Ich habe es mit Matplotlib mplot3d geplottet und habe die erwartete Grafik, aber es ist zu langsam, deshalb möchte ich pyqtgraph verwenden. – Jorge