コード例 #1
0
ファイル: aclab2.py プロジェクト: ankursharma319/python_misc
def bezier_spline_aerofoil(file_path):
    """
    creates a Bezier spline aerofoil with
    certain lower curve control points
    """
    # control points
    p = np.array([[1.0, 0.0], [0.5, 0.08], [0.0, -0.05]])
    q = np.array([[0.0, 0.1], [0.4, 0.2], [1.0, 0.0]])
    # weights
    zp = np.array([1, 1, 1, 1])
    zq = np.array([1, 1, 1, 1])
    # calculate degree
    n = np.float(p.shape[0])
    m = np.float(p.shape[0])
    # calculate connection point
    q_start = p_end = (n / (m + n)) * p[-1, :] + (m / (m + n)) * q[0, :]
    # and add to control points
    pp = np.vstack([p, p_end])
    qq = np.vstack([q_start, q])

    lower = rational_bezier(pp, zp)
    upper = rational_bezier(qq, zq)

    # open .dat file for writing to
    data_file = open(file_path + "aerofoil.dat", "w")
    # write lower surface to file
    for i in range(0, 100):
        data_file.write("%.11f %.11f\n" % (lower[i, 0], lower[i, 1]))
    # for windows use " " instead of "\t"
    # write upper surface to file
    for i in range(0, 101):
        data_file.write("%.11f %.11f\n" % (upper[i, 0], upper[i, 1]))
    # for windows use " " instead of "\t"
    # close .dat file
    data_file.close()
コード例 #2
0
def parametric_aerofoil(w):

    p = np.array([[1, 0], [0.5, 0.08], [0.0, -0.05]])
    q = np.array([[0, 0.1], [0.4, 0.2], [1, 0.0]])
    # weights
    zp = np.array([1, 1, 1, 1])
    zq = np.array([1, 1, w, 1])

    # calculate degree
    n = np.float(np.shape(p)[0])
    m = np.float(np.shape(p)[0])

    # calculate connection point
    q_start = p_end = (n / (m + n)) * p[-1, :] + (m / (m + n)) * q[0, :]

    # and add to control points
    pp = np.vstack([p, p_end])
    qq = np.vstack([q_start, q])

    # calculate two curves
    lower = rational_bezier(pp, zp)
    upper = rational_bezier(qq, zq)

    points = np.vstack([lower[0:100], upper])

    return points
コード例 #3
0
def parametric_aerofoil(w, file_path):
    """
    Generates and saves a parametric bezier spline aerofoil.

    w -- weighting of points
         If w is a float it is used as the weighting of point u(2)
         If w is an array it must contain four values, used as weighitngs of
         points u(1), u(2), l(1), l(2) respectively.
    file_path -- path to write aerofoil.dat within
    """
    lower = np.array([[1.0, 0.0],
                      [0.5, 0.08],
                      [0.0, -0.05]])
    n = float(len(lower))
    upper = np.array([[0.0, 0.1],
                      [0.4, 0.2],
                      [1.0, 0.0]])
    m = float(len(upper))
    connect = np.add(np.multiply(upper[0], m / (m + n)),
                     np.multiply(lower[n - 1], n / (m + n)))
    lower = np.concatenate((lower, [connect]))
    upper = np.concatenate(([connect], upper))
    if type(w) is float or type(w) is np.float64:
        l_bez = lab1.rational_bezier(lower, [1, 1, 1, 1])
        u_bez = lab1.rational_bezier(upper, [1, 1, w, 1])
    else:
        l_bez = lab1.rational_bezier(lower, [1, w[2], w[3], 1])
        u_bez = lab1.rational_bezier(upper, [1, w[0], w[1], 1])
    u_bez = np.delete(u_bez, 0, axis=0)
    aero_spline = np.concatenate((l_bez, u_bez), axis=0)
    aerofoil_file = open(file_path + "aerofoil.dat", "w")
    aerofoil_file.write("MyFoil\n" + serialize_array(aero_spline).strip())
コード例 #4
0
def bezier_spline_aerofoil():
    
    # define the control points:
    #p = np.array(...)
    #q = np.array(...)
    ### BEGIN SOLUTION
    p = np.array([[1, 0.0], [0.5, 0.08], [0.0, -0.05]])
    q = np.array([[0.0, 0.1], [0.4, 0.2], [1, 0.0]])
    ### END SOLUTION
    
    # weights
    zp = np.array([1, 1, 1, 1])
    zq = np.array([1, 1, 1, 1])
    
    # calculate degree
    #n = ...
    #m = ...
    ### BEGIN SOLUTION
    n = np.float(np.shape(p)[0])
    m = np.float(np.shape(p)[0])
    ### END SOLUTION
    
    # calculate connection point
    # q_start = p_end = ...
    ### BEGIN SOLUTION
    q_start = p_end = (n/(m+n))*p[-1,:]+(m/(m+n))*q[0,:]
    ### END SOLUTION
    
    # and add to control points
    pp = np.vstack([p, p_end])
    qq = np.vstack([q_start, q])
    
    # calculate two curves 
    # lower = ...
    # upper = ...
    ### BEGIN SOLUTION
    lower = rational_bezier(pp, zp)
    upper = rational_bezier(qq, zq)
    ### END SOLUTION
    
    # and join together (removing repeat point at leading edge):
    ### BEGIN SOLUTION
    points = np.vstack([lower[0:100], upper])
    ### END SOLUTION

    return points
コード例 #5
0
def bezier_spline_aerofoil(file_path):
    """ Generates and saves a bezier spline aerofoil with predefined values """
    lower = np.array([[1.0, 0.0],
                      [0.5, 0.08],
                      [0.0, -0.05]])
    n = float(len(lower))
    upper = np.array([[0.0, 0.1],
                      [0.4, 0.2],
                      [1.0, 0.0]])
    m = float(len(upper))
    connect = np.add(np.multiply(upper[0], m / (m + n)),
                     np.multiply(lower[n - 1], n / (m + n)))
    lower = np.concatenate((lower, [connect]))
    upper = np.concatenate(([connect], upper))
    l_bez = lab1.rational_bezier(lower, [1, 1, 1, 1])
    u_bez = lab1.rational_bezier(upper, [1, 1, 1, 1])
    u_bez = np.delete(u_bez, len(u_bez) - 1, axis=0)
    aero_spline = np.concatenate((l_bez, u_bez))
    aerofoil_file = open(file_path + "aerofoil.dat", "w")
    aerofoil_file.write("MyFoil\n" + serialize_array(aero_spline).strip())