Created
May 28, 2024 08:12
-
-
Save diablowu/b382cc980b8373080eb22ceb237a2710 to your computer and use it in GitHub Desktop.
generated a dish antenna model file (mmana-gal)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import math | |
def generate_circle_points(diameter, num_points,z): | |
angles = np.linspace(0, 2 * np.pi, num_points, endpoint=False) | |
x_coords = diameter / 2 * np.cos(angles) | |
y_coords = diameter / 2 * np.sin(angles) | |
z_coords = np.full(num_points, z) | |
return x_coords, y_coords, z_coords | |
def calc_points(diameter, num_points,z): | |
x_coords, y_coords,z_coords = generate_circle_points(diameter, num_points,z) | |
return list(zip(x_coords, y_coords,z_coords)) | |
def draw(diameter, num_points, z): | |
points = calc_points(diameter, num_points,z) | |
lines = [] | |
for i,p in enumerate(points): | |
next_point = None | |
if i == num_points-1: | |
next_point = points[0] | |
else: | |
next_point = points[i+1] | |
# format: x1,y1,z1,x2,y2,z2 | |
lines.append("{},{},{},{},{},{},0.003,-1".format(p[0], p[1],p[2], next_point[0], next_point[1],next_point[2])) | |
return "\n".join(lines) | |
TPL = """ | |
* | |
1296.0 | |
***Wires*** | |
{} | |
{} | |
***Source*** | |
0, 0 | |
***Load*** | |
0, 0 | |
***Segmentation*** | |
800, 80, 2.0, 2 | |
***G/H/M/R/AzEl/X*** | |
0, 15.0, 0, 50.0, 120, 60, 0.0 | |
###Comment### | |
""" | |
class Layer: | |
diameter = 0 | |
num_points = 0 | |
z_index = 0 | |
def __init__(self, diameter, num_points, z_index): | |
self.diameter = diameter | |
self.num_points = num_points | |
self.z_index = z_index | |
def calc_diameter(z): | |
return math.sqrt(z * 5) | |
def calc_z(diameter): | |
return diameter * diameter / 5 | |
def rearrange_points(circle_points_array): | |
num_polygons = len(circle_points_array) | |
num_points_per_polygon = 36 | |
# Initialize the new_points array with empty lists | |
new_points = [[] for _ in range(num_points_per_polygon)] | |
# Iterate over each polygon and each point within the polygon | |
for polygon in circle_points_array: | |
for i in range(num_points_per_polygon): | |
new_points[i].append(polygon[i]) | |
return new_points | |
if __name__ == "__main__": | |
layer_defined = [] | |
for i in range(0, 8): | |
diameter = 1-i*0.142714 | |
layer_defined.append(Layer(diameter, 36, calc_z(diameter))) | |
segments_count = 0 | |
segments = [] | |
# 纬线计算 | |
for layer in layer_defined: | |
segments_count += layer.num_points | |
segments.append(draw(layer.diameter, layer.num_points, layer.z_index)) | |
# print(TPL.format(segments_count, "\n".join(segments))) | |
points_arr = [] | |
# # 经线 | |
for layer in layer_defined: | |
# segments_count += layer.num_points | |
points_arr.append(calc_points(layer.diameter, layer.num_points, layer.z_index)) | |
new_points = rearrange_points(points_arr) | |
max_layer = len(new_points[0]) | |
for index, index_points in enumerate(new_points): | |
for layer_index,p in enumerate(index_points): | |
# next_point = None | |
if layer_index == max_layer-1: | |
break | |
else: | |
next_point = index_points[layer_index+1] | |
segments_count += 1 | |
segments.append("{},{},{},{},{},{},0.003,-1".format(p[0], p[1],p[2], next_point[0], next_point[1],next_point[2])) | |
print(TPL.format(segments_count, "\n".join(segments))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment