修复几个边界条件bug
This commit is contained in:
59
core.py
59
core.py
@@ -158,24 +158,31 @@ def intersection_angle(
|
||||
circle_line_or_rg_intersection = solve_circle_intersection(
|
||||
rg, rc, rg_x, rg_y, rc_x, rc_y
|
||||
) # 两圆的交点
|
||||
(
|
||||
circle_line_or_rg_intersection_x,
|
||||
circle_line_or_rg_intersection_y,
|
||||
) = circle_line_or_rg_intersection
|
||||
if (
|
||||
ground_surface(circle_line_or_rg_intersection_x)
|
||||
> circle_line_or_rg_intersection_y
|
||||
): # 交点在地面线以下,就可以不积分
|
||||
# 找到暴露弧和地面线的交点
|
||||
circle_line_or_rg_intersection = circle_ground_surface_intersection(
|
||||
rc, rc_x, rc_y, ground_surface
|
||||
)
|
||||
if circle_line_or_rg_intersection:
|
||||
(
|
||||
circle_line_or_rg_intersection_x,
|
||||
circle_line_or_rg_intersection_y,
|
||||
) = circle_line_or_rg_intersection
|
||||
if (
|
||||
ground_surface(circle_line_or_rg_intersection_x)
|
||||
> circle_line_or_rg_intersection_y
|
||||
): # 交点在地面线以下,就可以不积分
|
||||
# 找到暴露弧和地面线的交点
|
||||
circle_line_or_rg_intersection = circle_ground_surface_intersection(
|
||||
rc, rc_x, rc_y, ground_surface
|
||||
)
|
||||
theta1 = None
|
||||
np_circle_intersection = np.array(circle_intersection)
|
||||
theta2_line = np_circle_intersection - np.array([rc_x, rc_y])
|
||||
theta2 = math.atan(theta2_line[1] / theta2_line[0])
|
||||
np_circle_line_or_rg_intersection = np.array(circle_line_or_rg_intersection)
|
||||
theta1_line = np_circle_line_or_rg_intersection - np.array([rc_x, rc_y])
|
||||
theta1 = math.atan(theta1_line[1] / theta1_line[0])
|
||||
if not circle_line_or_rg_intersection:
|
||||
if rc_y - rc > rg: # rg在rc下面
|
||||
# 捕捉线太低了,对高塔无保护,θ_1从-90°开始计算。
|
||||
theta1 = -math.pi / 2
|
||||
else:
|
||||
theta1_line = np_circle_line_or_rg_intersection - np.array([rc_x, rc_y])
|
||||
theta1 = math.atan(theta1_line[1] / theta1_line[0])
|
||||
return np.array([theta1, theta2])
|
||||
|
||||
|
||||
@@ -187,7 +194,10 @@ def distance_point_line(point_x, point_y, line_x, line_y, k) -> float:
|
||||
|
||||
def func_calculus_pw(theta, max_w):
|
||||
w_fineness = 0.01
|
||||
w_samples, d_w = np.linspace(0, max_w, int(max_w / w_fineness), retstep=True)
|
||||
segments = int(max_w / w_fineness)
|
||||
if segments < 2: # 最大最小太小,没有可以积分的
|
||||
return 0
|
||||
w_samples, d_w = np.linspace(0, max_w, segments, retstep=True)
|
||||
cal_w_np = abs(angel_density(w_samples)) * np.sin(theta - (w_samples - math.pi / 2))
|
||||
r_pw = np.sum((cal_w_np[:-1] + cal_w_np[1:])) / 2 * d_w
|
||||
return r_pw
|
||||
@@ -282,7 +292,8 @@ def tangent_line_k(line_x, line_y, center_x, center_y, radius, init_k=10.0):
|
||||
for ind, k_cdi in enumerate(list(k_candidate)):
|
||||
k = k_candidate[ind]
|
||||
k_candidate[ind] = None
|
||||
for bar in range(0, 30):
|
||||
max_iteration = 30
|
||||
for bar in range(0, max_iteration):
|
||||
fk = (k * center_x - center_y - k * line_x + line_y) ** 2 - (
|
||||
radius ** 2
|
||||
) * (k ** 2 + 1)
|
||||
@@ -304,13 +315,17 @@ def tangent_line_k(line_x, line_y, center_x, center_y, radius, init_k=10.0):
|
||||
if abs(dd - radius) < 1:
|
||||
k_candidate[ind] = k
|
||||
break
|
||||
# 解决数值稳定性
|
||||
if bar == max_iteration - 1:
|
||||
if abs(math.atan(k)) * 180 / math.pi > 89:
|
||||
k_candidate[ind] = k
|
||||
# 把k转化成相应的角度,从x开始,逆时针为正
|
||||
k_angle = []
|
||||
for kk in k_candidate:
|
||||
# if kk is None:
|
||||
# abc = 123
|
||||
# # tangent_line_k(line_x, line_y, center_x, center_y, radius)
|
||||
# pass
|
||||
if kk is None:
|
||||
abc = 123
|
||||
tangent_line_k(line_x, line_y, center_x, center_y, radius)
|
||||
pass
|
||||
if kk >= 0:
|
||||
k_angle.append(math.atan(kk))
|
||||
if kk < 0:
|
||||
@@ -327,7 +342,9 @@ def func_ng(td): # 地闪密度
|
||||
def circle_ground_surface_intersection(radius, center_x, center_y, ground_surface):
|
||||
# 最笨的办法,一个个去试
|
||||
x_series = np.linspace(0, radius, int(radius / 0.001)) + center_x
|
||||
part_to_be_squared = radius ** 2 - (x_series - center_x) ** 2 # 有可能出现-0.00001的数值,只是一个数值稳定问题。
|
||||
part_to_be_squared = (
|
||||
radius ** 2 - (x_series - center_x) ** 2
|
||||
) # 有可能出现-0.00001的数值,只是一个数值稳定问题。
|
||||
part_to_be_squared[
|
||||
(part_to_be_squared < 0) & (abs(part_to_be_squared) < 1e-3)
|
||||
] = 0 # 强制为0
|
||||
|
||||
Reference in New Issue
Block a user