def surface_areas(d): ''' input: origin-to-planes distances. volume_calc: the natural or unscaled volume of the polyhedron. area_p: areas of all the planes. points_p: interception points on the planes, grouped by plane. return: area_ps: the area of each plane family (sum of areas of surfaces of a plane family). ''' global Gamma_ratio ps_setd_mingled(number_planes, planes, d) planes_c = [p.as_list() for p in planes] pr = enclosure(planes_c) volume_calc = pr[0] # the natural or unscaled volume of the polyhedron. area_p = pr[1] # areas of all the planes. points_p = pr[2] # interception points on the planes, grouped by plane. area_ps = [ ] # area of each plane family: sum of areas of surfaces of a plane family. index_start = 0 for subset_n in number_planes: index_end = index_start + subset_n area_ps.append(np.sum(area_p[index_start:index_end])) index_start = index_end global volume diameter = 20.0 volume = 4.0 / 3.0 * np.pi * ( diameter * 0.5)**3 # this volume was used to scale the calculated volume. area_ps = np.array(area_ps) * np.power(volume / volume_calc, 2.0 / 3) return area_ps
def intersection_point(number_planes, planes, d): ''' Calculate the intersection points of surfaces of a plane family. ''' ps_setd_mingled(number_planes, planes, d) planes_c = [p.as_list() for p in planes] pr = enclosure(planes_c) points_p = pr[2] return points_p
def surface_areas(d): ''' input: origin-to-planes distances. volume_calc: the natural or unscaled volume of the polyhedron. area_p: areas of all the planes. points_p: interception points on the planes, grouped by plane. return: area_ps: the area of each plane family (sum of areas of surfaces of a plane family). ''' ps_setd_mingled(number_planes, planes, d) planes_c = [p.as_list() for p in planes] pr = enclosure(planes_c) volume_calc = pr[0] # the natural or unscaled volume of the polyhedron. area_p = pr[1] # areas of all the planes. points_p = pr[2] # interception points on the planes, grouped by plane. # print points_p area_ps = [ ] # area of each plane family: sum of areas of surfaces of a plane family. index_start = 0 for subset_n in number_planes: index_end = index_start + subset_n area_ps.append(np.sum(area_p[index_start:index_end])) index_start = index_end # diameter = 1.0e-9 # volume = 4.0/3.0*np.pi* (diameter*0.5)**3 # this volume was used to scale the calculated volume. area_ps = np.array(area_ps) * np.power(volume / volume_calc, 2.0 / 3) Vn, En, vl = vertices_number(number_planes, planes, d) edge_sort = edge_length_sort(number_planes, planes, d, vl) edge_length_f, edge_length_o = edge_length_fraction( edge_sort, volume, volume_calc) return area_ps, edge_length_f, edge_length_o
def enclose_polyhedron(number_planes, planes, volume=0.0): ''' uses multiple planes to enclose a polyhedron, and calculates the polyhedron's geometric parameters. number_planes: number of planes of each subset. [list of integers] planes: planes of all subsets. Its length equals the sum of 'number_planes'. [list of Plane3D] volume: a given volume to scale the calculated volume to this value. If it is zero, the unscaled volume is used. returns: [q, fractional_area, vertices, scale]. Note: 1. This function handles one volume at a time. For multiple volumes at constant height-ratios, eg. for plotting q-d curves, use enclose_polyhedron_multivol(), which is faster. ''' planes_c = [p.as_list() for p in planes] pr = enclosure(planes_c) # call enclosure() which is implemented in C volume_calc = pr[0] # the natural or unscaled volume of the polyhedron area_p = pr[1] # areas of all the planes points_p = pr[2] # interception points on the planes, grouped by plane # area of each plane family: sum of areas of surfaces of a plane family area_ps = [] index_start = 0 for subset_n in number_planes: index_end = index_start + subset_n area_ps.append(np.sum(area_p[index_start : index_end])) index_start = index_end area_ps = np.array(area_ps) # convert a list to a numpy.ndarray # total surface area area_sum = np.sum(area_ps) # weight of each surface family f_ps = area_ps / area_sum # array operation: all elements are devided. # surface-area-to-volume ratio q = area_sum / volume_calc # scale the surface areas, point coordinates according to volume if volume!=0.0: r = np.power(volume / volume_calc, 1.0/3) # correct q, f_ps, points_p, (optionally, areal_ps, area_sum) q = q / r # f_ps remains the same for p in points_p: # p is a list of points on one plane for xyz in p: xyz[0] = xyz[0]*r xyz[1] = xyz[1]*r xyz[2] = xyz[2]*r # area_ps = area_ps * (r*r) # array operation: all elements are scaled. # area_sum = area_sum * (r*r) return (q, f_ps, points_p, volume) else: # r=1.0 # volume is the natural volume_calc. return (q, f_ps, points_p, volume_calc)