1
1
"""Plot sound fields etc."""
2
2
3
3
import matplotlib .pyplot as plt
4
- from matplotlib .patches import Polygon
4
+ from matplotlib .patches import PathPatch
5
+ from matplotlib .path import Path
5
6
from matplotlib .collections import PatchCollection
6
7
from mpl_toolkits .mplot3d import Axes3D
7
8
import numpy as np
@@ -69,7 +70,7 @@ def secondarysource_2d(x0, n0, grid=None):
69
70
ax .add_artist (ss )
70
71
71
72
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 ):
73
74
"""Draw loudspeaker symbols at given locations, angles."""
74
75
x0 = np .asarray (x0 )
75
76
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):
84
85
if grid is not None :
85
86
x0 , n0 = _visible_secondarysources_2d (x0 , n0 , grid )
86
87
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
95
102
96
103
for x00 , n00 , a00 in zip (x0 , n0 , a0 ):
97
104
# rotate and translate coordinates
98
105
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
101
107
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 )))
107
109
108
- # set facecolor (two times due to split patches)
109
- fc .append ((1 - a00 ) * np .ones (3 ))
110
+ # set facecolor
110
111
fc .append ((1 - a00 ) * np .ones (3 ))
111
112
112
113
# add collection of patches to current axis
0 commit comments