python最速曲線


最速曲線については
http://zhidao.baidu.com/s/daily/2014-04-21/1403015178.html
内容は比較的豊富で、また比較的に面白いです
さいそくどきょくせんしき
理論解はずっと前からあったが,次のようになった.
参照:https://blog.csdn.net/WhoisPo/article/details/47149395
#              
import math

x0 = 10;
y0 = 10;
etof = 1e-2; #   ,   0
.1
a0 = 0; #       
a1 = math.pi / 30;

dex = 0.1; #     
dey = 0.1;

while (1):
    a_init = (a0 + a1) / 2; #       

    a = a_init;
    dx = dex; #     
    dy = 1/math.tan(a) * dx;
    while (dy > dey):
        dx = dx / 10; #     
        dy = 1/math.tan(a) * dx;
    #end
    x = dx;
    y = dy;
    while (x + dx <= x0):
        yt = y +1/math.tan(a) * dx;
        if (yt < 0):
            break; #          ,  
        #end
        if (math.sin(a) / math.sqrt(y) * math.sqrt(yt) >= 1): #      
            a = -a;
            yt = y + 1/math.tan(a) * dx;
        #end
        at = math.asin(math.sin(a) / math.sqrt(y) * math.sqrt(yt));
        x = x + dx;
        y = yt;
        a = at;

        dy = 1/math.tan(a) * dx;
        while (dy < dey / 10 and dx < dex): #       
            dx = dx * 10;
            dy = 1/math.tan(a) * dx;
        #end
    #end

    if (abs(y - y0) < etof and x + dx > x0):
        break;
    #end
    if (x + dx <= x0 or y < y0):
        a1 = a_init;
    else:
        a0 = a_init;
    #end
#end

a = (a0 + a1) / 2;

# scatter(0, 0, 'go');
dx = dex;
dy = 1/math.tan(a) * dx;
while (dy > dey):
    dx = dx / 10;
    dy = 1/math.tan(a) * dx;
#end
# scatter(dx, dy, 'go');
x = dx;
y = dy;
while (x + dx <= x0):
    yt = y + 1/math.tan(a) * dx;
    if (math.sin(a) / math.sqrt(y) * math.sqrt(yt) >= 1):
        a = -a;
        yt = y + 1/math.tan(a) * dx;
    #end
    at = math.asin(math.sin(a) / math.sqrt(y) * math.sqrt(yt));
    x = x + dx;
    y = yt;
    a = at;
    # scatter(x, y, 'go');
    dy = 1/math.tan(a) * dx;
    while (dy < dey / 10 and dx < dex):
        dx = dx * 10;
        dy = 1/math.tan(a) * dx;
    #end