def to_surface(mesh): """ Convert Mesh object into pyny.Surface object (used for visualization) Inputs: mesh (Mesh) Return: pyny.Surface - converted mesh """ vert = mesh.vertices faces = mesh.faces surface = [] for i in range(faces.shape[0]): points = vert[faces[i], :] surface.append(pyny.Polygon(np.array(points))) return pyny.Surface(surface)
def integrateOverFace(self, tup, scheme=quadpy.t2._wandzura_xiao.wandzura_xiao_6()): key, vertices = tup polygon = pyny.Polygon(vertices, False) param = polygon.get_parametric(True, tolerance=0.001) param /= np.linalg.norm(param[:3]) i = np.argmax(np.abs(param[:3])) if self.eqTol(param[i], 0, 0.001): raise ArithmeticError('Face is not planar') reducedVertex = np.delete(vertices, i, axis=1) triangles = scipy.spatial.Delaunay(reducedVertex).simplices triangleMesh = pymesh.triangle() triangleMesh.verbosity = 0 triangleMesh.points = np.array(reducedVertex) triangleMesh.triangles = triangles triangleMesh.max_area = 0.05 triangleMesh.run() mesh = triangleMesh.mesh integrals = scheme.integrate( partial(self.rhoface, param=param, i=i), mesh.vertices[mesh.elements].transpose([1, 0, 2])) return key, integrals.sum(0)
# room.plot_rir() # room.plot() # room height room_height = random.uniform(2.4, 5.5) # Polygon generator function - set irregularity and spikeyness of polygon poly_points_floor, poly_points_ceil, cent = L_shape_room(height=room_height) # Room center (not important so far) room_centre = [cent.x, cent.y] # v_vec = np.array([0.,0.,1.]) poly1 = pyny.Polygon(np.array(poly_points_floor), make_ccw=True) poly2 = pyny.Polygon(np.array(poly_points_ceil), make_ccw=True) polyhedron = pyny.Polyhedron.by_two_polygons(poly1, poly2) polys = polyhedron.polygons poly_coords = [] for pgns in polys: poly_coords.append(poly1) print(poly_coords) alpha = np.random.uniform(0.1, 0.9) # m = pra.Material(energy_axbsorption=0.03) alpha = alpha**2 room = pra.Room.from_corners(np.array(poly1.points)[:, :2].T, fs=16000,
def Vonoroi_SH(self, mesh_size=0.1): """ Generates a equally spaced mesh on the Solar Horizont (SH). Computes the Voronoi diagram from a set of points given by pairs of (azimuth, zenit) values. This discretization completely covers all the Sun positions. The smaller mesh size, the better resolution obtained. It is important to note that this heavily affects the performance. The generated information is stored in: * **.t2vor_map** (*ndarray*): Mapping between time vector and the Voronoi diagram. * **.vor_freq** (*ndarray*): Number of times a Sun position is inside each polygon in the Voronoi diagram. * **.vor_surf** (*``pyny.Surface``*): Voronoi diagram. * **.vor_centers** (*ndarray`*): Mass center of the ``pyny.Polygons`` that form the Voronoi diagram. :param mesh_size: Mesh size for the square discretization of the Solar Horizont. :type mesh_size: float (in radians) :param plot: If True, generates a visualization of the Voronoi diagram. :type plot: bool :returns: None .. note:: In future versions this discretization will be improved substantially. For now, it is quite rigid and only admits square discretization. """ from scipy.spatial import Voronoi from pyny3d.utils import sort_numpy state = pyny.Polygon.verify pyny.Polygon.verify = False # Sort and remove NaNs xy_sorted, order_back = sort_numpy(self.azimuth_zenit, col=1, order_back=True) # New grid x1 = np.arange(-np.pi, np.pi, mesh_size) y1 = np.arange(-mesh_size*2, np.pi/2+mesh_size*2, mesh_size) x1, y1 = np.meshgrid(x1, y1) centers = np.array([x1.ravel(), y1.ravel()]).T # Voronoi vor = Voronoi(centers) # Setting the SH polygons pyny_polygons = [pyny.Polygon(vor.vertices[v], False) for v in vor.regions[1:] if len(v) > 3] raw_surf = pyny.Surface(pyny_polygons) # Classify data into the polygons discretization map_ = raw_surf.classify(xy_sorted, edge=True, col=1, already_sorted=True) map_ = map_[order_back] # Selecting polygons with points inside vor = [] count = [] for i, poly_i in enumerate(np.unique(map_)[1:]): vor.append(raw_surf[poly_i]) bool_0 = map_==poly_i count.append(bool_0.sum()) map_[bool_0] = i # Storing the information self.t2vor_map = map_ self.vor_freq = np.array(count) self.vor_surf = pyny.Surface(vor) self.vor_centers = np.array([poly.get_centroid()[:2] for poly in self.vor_surf]) pyny.Polygon.verify = state
import numpy as np import pyny3d.geoms as pyny polygon = np.array([[0, 0, 0], [7, 0, 0], [7, 10, 2], [0, 10, 2]]) pyny.Polygon(polygon) pyny.Polygon.verify = False pyny.Polygon(polygon) pyny.Polygon.verify = True surface_poly = [ np.array([[0, 0, 0], [7, 0, 0], [7, 10, 2], [0, 10, 2]]), np.array([[0, 10, 2], [7, 10, 2], [3, 15, 3.5]]), np.array([[0, 10, 2], [3, 15, 3.5], [0, 15, 3.5]]), np.array([[7, 10, 2], [15, 10, 2], [15, 15, 3.5], [3, 15, 3.5]]) ] pyny.Place(surface_poly) pyny.Polygon.verify = False pyny.Place(surface_poly) polygon = pyny.Polygon(np.array([[0, 0, 0], [7, 0, 0], [7, 10, 2], [0, 10, 2]])) polygon.get_parametric(True, tolerance=0.01) array([0, 14, -70, 0]) non_polygon = pyny.Polygon(