[euler_bend] speed up integration
This commit is contained in:
parent
2275bf415a
commit
cfec9e8c76
1 changed files with 19 additions and 8 deletions
|
|
@ -69,14 +69,25 @@ def euler_bend(
|
||||||
num_points_arc = num_points - 2 * num_points_spiral
|
num_points_arc = num_points - 2 * num_points_spiral
|
||||||
|
|
||||||
def gen_spiral(ll_max: float) -> NDArray[numpy.float64]:
|
def gen_spiral(ll_max: float) -> NDArray[numpy.float64]:
|
||||||
xx = []
|
if ll_max == 0:
|
||||||
yy = []
|
return numpy.zeros((num_points_spiral, 2))
|
||||||
for ll in numpy.linspace(0, ll_max, num_points_spiral):
|
|
||||||
qq = numpy.linspace(0, ll, 1000) # integrate to current arclength
|
resolution = 100000
|
||||||
xx.append(trapezoid( numpy.cos(qq * qq / 2), qq))
|
qq = numpy.linspace(0, ll_max, resolution)
|
||||||
yy.append(trapezoid(-numpy.sin(qq * qq / 2), qq))
|
dx = numpy.cos(qq * qq / 2)
|
||||||
xy_part = numpy.stack((xx, yy), axis=1)
|
dy = -numpy.sin(qq * qq / 2)
|
||||||
return xy_part
|
|
||||||
|
dq = ll_max / (resolution - 1)
|
||||||
|
ix = numpy.zeros(resolution)
|
||||||
|
iy = numpy.zeros(resolution)
|
||||||
|
ix[1:] = numpy.cumsum((dx[:-1] + dx[1:]) / 2) * dq
|
||||||
|
iy[1:] = numpy.cumsum((dy[:-1] + dy[1:]) / 2) * dq
|
||||||
|
|
||||||
|
ll_target = numpy.linspace(0, ll_max, num_points_spiral)
|
||||||
|
x_target = numpy.interp(ll_target, qq, ix)
|
||||||
|
y_target = numpy.interp(ll_target, qq, iy)
|
||||||
|
|
||||||
|
return numpy.stack((x_target, y_target), axis=1)
|
||||||
|
|
||||||
xy_spiral = gen_spiral(ll_max)
|
xy_spiral = gen_spiral(ll_max)
|
||||||
xy_parts = [xy_spiral]
|
xy_parts = [xy_spiral]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue