11"""Plot sound fields etc."""
22
33import matplotlib .pyplot as plt
4- from matplotlib .patches import Polygon
4+ from matplotlib .patches import PathPatch
5+ from matplotlib .path import Path
56from matplotlib .collections import PatchCollection
67from mpl_toolkits .mplot3d import Axes3D
78import numpy as np
@@ -69,7 +70,7 @@ def secondarysource_2d(x0, n0, grid=None):
6970 ax .add_artist (ss )
7071
7172
72- def loudspeaker_2d (x0 , n0 , a0 = None , w = 0.08 , h = 0.08 , index = False , grid = None ):
73+ def loudspeaker_2d (x0 , n0 , a0 = None , size = 0.08 , index = False , grid = None ):
7374 """Draw loudspeaker symbols at given locations, angles."""
7475 x0 = np .asarray (x0 )
7576 n0 = np .asarray (n0 )
@@ -84,29 +85,29 @@ def loudspeaker_2d(x0, n0, a0=None, w=0.08, h=0.08, index=False, grid=None):
8485 if grid is not None :
8586 x0 , n0 = _visible_secondarysources_2d (x0 , n0 , grid )
8687
87- # coordinates of loudspeaker symbol
88- v01 = np .asarray ([[- h , - h , - h / 2 , - h / 2 , - h ], [- w / 2 , w / 2 , w / 2 ,
89- - w / 2 , - w / 2 ], [0 , 0 , 0 , 0 , 0 ]])
90- v02 = np .asarray (
91- [[- h / 2 , 0 , 0 , - h / 2 ], [- w / 6 , - w / 2 , w / 2 , w / 6 ], [0 , 0 , 0 , 0 ]])
92-
93- v01 = v01 .T
94- v02 = v02 .T
88+ # normalized coordinates of loudspeaker symbol (see IEC 60617-9)
89+ codes , coordinates = zip (* (
90+ (Path .MOVETO , [- 0.62 , 0.21 ]),
91+ (Path .LINETO , [- 0.31 , 0.21 ]),
92+ (Path .LINETO , [0 , 0.5 ]),
93+ (Path .LINETO , [0 , - 0.5 ]),
94+ (Path .LINETO , [- 0.31 , - 0.21 ]),
95+ (Path .LINETO , [- 0.62 , - 0.21 ]),
96+ (Path .CLOSEPOLY , [0 , 0 ]),
97+ (Path .MOVETO , [- 0.31 , 0.21 ]),
98+ (Path .LINETO , [- 0.31 , - 0.21 ]),
99+ ))
100+ coordinates = np .column_stack ([coordinates , np .zeros (len (coordinates ))])
101+ coordinates *= size
95102
96103 for x00 , n00 , a00 in zip (x0 , n0 , a0 ):
97104 # rotate and translate coordinates
98105 R = util .rotation_matrix ([1 , 0 , 0 ], n00 )
99- v1 = np .inner (v01 , R ) + x00
100- v2 = np .inner (v02 , R ) + x00
106+ transformed_coordinates = np .inner (coordinates , R ) + x00
101107
102- # add coordinates to list of patches
103- polygon = Polygon (v1 [:, :- 1 ], True )
104- patches .append (polygon )
105- polygon = Polygon (v2 [:, :- 1 ], True )
106- patches .append (polygon )
108+ patches .append (PathPatch (Path (transformed_coordinates [:, :2 ], codes )))
107109
108- # set facecolor (two times due to split patches)
109- fc .append ((1 - a00 ) * np .ones (3 ))
110+ # set facecolor
110111 fc .append ((1 - a00 ) * np .ones (3 ))
111112
112113 # add collection of patches to current axis
0 commit comments