Beispiel #1
0
def spline_curve_kv_norm2():
    """ Creates a spline Curve without knot vector normalization """
    curve = BSpline.Curve(normalize_kv=False)
    curve.degree = 3
    curve.ctrlpts = [[5.0, 5.0], [10.0, 10.0], [20.0, 15.0], [35.0, 15.0], [45.0, 10.0], [50.0, 5.0]]
    curve.knotvector = [0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 3.0, 3.0, 3.0]
    return curve
Beispiel #2
0
def spline_curve():
    """ Creates a spline Curve """
    curve = BSpline.Curve()
    curve.degree = 3
    curve.ctrlpts = [[5.0, 5.0], [10.0, 10.0], [20.0, 15.0], [35.0, 15.0], [45.0, 10.0], [50.0, 5.0]]
    curve.knotvector = [0.0, 0.0, 0.0, 0.0, 0.33, 0.66, 1.0, 1.0, 1.0, 1.0]
    return curve
Beispiel #3
0
 def dowork(self,ch, method, properties, body):
     data=json.loads(body)
     points=data['points']
     RADIUS=data['RADIUS']
     WIDTH=data['WIDTH']
     HEIGHT=data['HEIGHT']
     SPREAD=data['SPREAD']
     curve = BSpline.Curve()
     curve.degree = 3
     curve.delta = 0.005
     lpoints = points
     curve.ctrlpts = lpoints
     curve.knotvector = knotvector.generate(3, len(curve.ctrlpts))
     curve_points = curve.evalpts
     temppixels = np.full((WIDTH, HEIGHT), 0.0)
     sl=SpreadLines(temppixels,255) 
     sl.drawline(curve_points)
     print(sl.img_data.max())
     data={}
     data['WIDTH']=WIDTH
     data['HEIGHT']=HEIGHT
     data['pixels']=temppixels.tolist()
     message=json.dumps(data)
     self.channel.basic_publish(exchange='',routing_key='feronia_result',body=message)
     ch.basic_ack(delivery_tag = method.delivery_tag)
Beispiel #4
0
    def build_geomdl(cls,
                     degree,
                     knotvector,
                     control_points,
                     weights=None,
                     normalize_knots=False):
        if weights is not None:
            curve = NURBS.Curve(normalize_kv=normalize_knots)
        else:
            curve = BSpline.Curve(normalize_kv=normalize_knots)
        curve.degree = degree
        if isinstance(control_points, np.ndarray):
            control_points = control_points.tolist()
        curve.ctrlpts = control_points
        if weights is not None:
            if isinstance(weights, np.ndarray):
                weights = weights.tolist()
            curve.weights = weights
        if isinstance(knotvector, np.ndarray):
            knotvector = knotvector.tolist()
        curve.knotvector = knotvector

        result = SvGeomdlCurve(curve)
        result.u_bounds = curve.knotvector[0], curve.knotvector[-1]
        return result
Beispiel #5
0
def get_norms(surf, timestep_limit):
    # create a 2D bezier curve
    curve = BSpline.Curve()
    curve.degree = 3

    ctrl_points = [[np.random.uniform(0, 0.2), np.random.uniform(0, 0.2)],
                   [np.random.uniform(0, 0.5), np.random.uniform(0, 0.5)],
                   [np.random.uniform(0.25, 0.75), np.random.uniform(0.25, 0.75)],
                   [np.random.uniform(0.5, 0.75), np.random.uniform(0.5, 0.75)],
                   [np.random.uniform(0.8, 1), np.random.uniform(0.8, 1.0)]]

    curve.set_ctrlpts(ctrl_points)
    curve.knotvector = utilities.generate_knot_vector(curve.degree, len(curve.ctrlpts))
    curve.sample_size = timestep_limit
    curve.evaluate()
    points_c = curve.evalpts
    norms = normal(surf, points_c)
    angles = []  # pitch, yaw
    traj = []  # x,y,z
    for i in range(len(norms)):
        nu = np.array(norms[i][1])
        yaw = 180.0*np.arctan2(np.abs(nu[1]), np.abs(nu[0]))/np.pi
        ca = np.linalg.norm(nu[0:2])
        pitch = 180.0*np.arctan2(nu[2], ca)/np.pi
        angles.append([pitch, yaw])
        point = np.array(norms[i][0])
        traj.append(np.array([point[0], point[1], point[2], pitch, yaw]))
    return traj, norms, curve
Beispiel #6
0
def draw(size):
    data = []
    data = np.ones((size, size), np.uint16) * 65535
    for _ in range(2):
        pnum = randint(15, 100)
        a = random() * TWOPI + linspace(0, TWOPI, pnum)
        points = column_stack((cos(a), sin(a))) * (1500 + random() * 100)
        curve = BSpline.Curve()
        curve.degree = 3
        # lpoints=list(list([i[0]+randint(-WOBBLE,WOBBLE),i[1]+randint(-WOBBLE,WOBBLE)]) for i in points)
        # curve.ctrlpts=lpoints
        # print(curve.ctrlpts)

        curve.delta = 0.00001
        # curve_points=curve.evalpts
        #         for t in curve_points:
        #             data[int(round(t[0]+size/2)),int(round(t[1]+size/2))]=65535
        # print(int(round(t[0]+size/2)),int(round(t[1]+size/2)))

        for decay in range(DECAYLENGTH):
            # print(crange[decay])
            lpoints = list(
                list([
                    i[0] + randint(-WOBBLE, WOBBLE), i[1] +
                    randint(-WOBBLE, WOBBLE)
                ]) for i in points)
            curve.ctrlpts = lpoints
            curve.knotvector = knotvector.generate(3, len(curve.ctrlpts))
            curve_points = curve.evalpts
            for t in curve_points:
                data[int(round(t[0] + size / 2)),
                     int(round(t[1] + size / 2))] += int(crange[decay])

    return data
def bspline_curve3d():
    """ Creates a B-Spline 3-dimensional curve instance """
    curve = BSpline.Curve()
    curve.degree = 2
    curve.ctrlpts = [[1, 1, 0], [2, 1, -1], [2, 2, 0]]
    curve.knotvector = [0, 0, 0, 1, 1, 1]
    return curve
def gen_kernel(num_spline_dots=6, curve_degree=5, kernel_size=(19, 19)):
    curve = BSpline.Curve()
    knot_dots = []

    knot_dots = []
    small_kernel_size = (int(np.round(kernel_size[0] / 1.5)),
                         int(np.round(kernel_size[1] / 1.5)))
    for i in range(num_spline_dots):
        knot_dots += [[
            np.random.randint(0, small_kernel_size[0]),
            np.random.randint(0, small_kernel_size[1])
        ]]

    curve.degree = curve_degree
    curve.ctrlpts = knot_dots
    curve.knotvector = generate_knot_vector(curve.degree, len(curve.ctrlpts))
    curve.delta = 0.005
    curve.evaluate()
    pts = np.array(curve.evalpts)
    pts[:, 0] -= (pts[:, 0].min() - 2)
    pts[:, 1] -= (pts[:, 1].min() - 2)
    k_dim = int(np.ceil(pts.max())) + 2

    k = kern_from_grid(pts, k_dim)
    cm_k = np.round(calculate_center_mass(k), 0).astype(int)
    dim_k_c = 2 * max(list(np.array(k.shape) - cm_k) + list(cm_k))
    if dim_k_c % 2 == 0: dim_k_c += 1

    k = expand(k, (dim_k_c, dim_k_c))
    k /= np.sum(k)
    return k
Beispiel #9
0
def swing_leg_planning():
    curve = BSpline.Curve()
    curve.ctrlpts = (
        (-0.2, 0), (-0.3, -0.03), (0., 0.3), (0.3, 0.), (0.2, 0.))  # 控制点
    curve.delta = 0.01  # 数据间隔
    curve.degree = 4  # degree应该小于控制点数量
    curve.knotvector = utilities.generate_knot_vector(curve.degree,
                                                      len(curve.ctrlpts))
    curve.evaluate()
    x = []
    dx = []
    y = []
    dy = []
    t_list = np.linspace(0, 1, 101)
    for t in t_list:
        tmp = curve.derivatives(t, order=1)
        x.append(tmp[0][0])
        dx.append(tmp[1][0])
        y.append(tmp[0][1])
        dy.append(tmp[1][1])
    plt.plot(x, y)
    plt.xlim((-0.3, 0.3))
    plt.ylim((-0.1, 0.5))
    plt.grid()
    plt.show()
def bspline_curve3d():
    """ Creates a 3-dimensional B-Spline curve instance """
    # Create a curve instance
    curve = BSpline.Curve()

    # Set curve degree
    curve.degree = 4

    # Set control points
    curve.ctrlpts = [[5.0, 15.0, 0.0], [10.0, 25.0, 5.0], [20.0, 20.0, 10.0],
                     [15.0, -5.0, 15.0], [7.5, 10.0, 20.0], [12.5, 15.0, 25.0],
                     [15.0, 0.0, 30.0], [5.0, -10.0, 35.0], [10.0, 15.0, 40.0],
                     [5.0, 15.0, 30.0]]

    # Set knot vector
    curve.knotvector = [
        0.0, 0.0, 0.0, 0.0, 0.0, 0.1, 0.3, 0.5, 0.7, 0.9, 1.0, 1.0, 1.0, 1.0,
        1.0
    ]

    # Set sample size
    curve.sample_size = SAMPLE_SIZE

    # Return the instance
    return curve
Beispiel #11
0
def geomdl_method(degree, ctrl_points):
    """Generate by geomdl package"""
    print(util.Section('B-Spline using geomdl Package'))
    # construct
    curve = BSpline.Curve()
    curve.degree = degree
    curve.ctrlpts = ctrl_points
    curve.knotvector = utilities.generate_knot_vector(degree, len(ctrl_points))
    curve.evaluate(step=0.01)

    print(
        f'knots length = {len(curve.knotvector)}, knots = {curve.knotvector}')
    print(f'c(0) = {curve.evaluate_single(0)}')
    print(f'c(0.5) = {curve.evaluate_single(0.5)}')
    print(f'c(0.6) = {curve.evaluate_single(0.6)}')
    print(f'c(1.0) = {curve.evaluate_single(1.0)}')

    # plot
    ctrl_plot_points = np.array(ctrl_points)
    curve_points = np.array(curve.evalpts)
    fig = plt.figure('B-Spline using geomdl Package')
    ax = fig.add_subplot(111)
    ax.plot(ctrl_plot_points[:, 0],
            ctrl_plot_points[:, 1],
            'g.-.',
            label='Control Points')
    ax.plot(curve_points[:, 0], curve_points[:, 1], 'b', label='BSpline Curve')
    ax.grid(True)
    ax.set_title('B-Spline using geomdl Package')
    ax.legend(loc='best')
    plt.show(block=False)
def spline2mask(crl, width, height, delta=.05, new_shape=None):
    c, r, l = crl if type(crl) == list else crl.tolist()
    cps = []
    for i in range(len(c)):
        ip = (i + 1) % len(c)
        cps.append([c[i], r[i], l[ip], c[ip]])
    connecs = []
    for i in range(len(cps)):
        curve = BSpline.Curve()
        curve.degree = 3
        curve.ctrlpts = cps[i]
        curve.knotvector = utilities.generate_knot_vector(
            curve.degree, len(curve.ctrlpts))
        # print('delta',delta)
        curve.delta = delta
        curve.evaluate()
        connecs.append(curve.evalpts)

    polygon = np.array(connecs).flatten().tolist()
    img = Image.new('L', (height, width), 255)
    ImageDraw.Draw(img).polygon(polygon, outline=0, fill=0)
    if new_shape is None:
        new_shape = (height, width)
    mask = np.array(img.resize(new_shape, Image.NEAREST))
    #print(mask.shape, width, height, downscale,int(width//downscale), int(height//downscale))
    return mask == False
Beispiel #13
0
def interpolate_Bspline(stepsBtwFrame,
                        currentPos,
                        nextPos,
                        liftHeight,
                        draw=False):
    # This function returns a list of 2-D trajectory points. Need to use IK to convert to joint angles afterwards
    # The return looks like [[0,0], [0,0], [0,0], [0,0], ... [0,0]] length=stepsBtwFrame
    # next = [x, z]
    # curr = [x, z]

    x_offset = 5  # Top control point height above liftheight
    z_offset = 30  # End control point position outside leg stroke

    # Pick up leg and make a full curve down to a upper position of wall

    halfZstroke = (nextPos[1] - currentPos[1]) / 2.0  # half stroke
    halfZstroke_and_offset = halfZstroke + z_offset  # half stroke plus offset outside the stroke

    ctrlPoint = [
        [0.0, -halfZstroke_and_offset / 2.5], [liftHeight, -halfZstroke],
        [liftHeight + x_offset, 0.0], [liftHeight, 2 * halfZstroke]
    ]  # there was one more point: [self.liftHeight/2, 0.0, halfZstroke_and_offset/3.0]

    nurbs = BSpline.Curve()

    # Set unweighted control points

    allPts = [currentPos]
    for i in range(len(ctrlPoint)):
        allPts.append(ctrlPoint[i])

    allPts.append(nextPos)

    nurbs.degree = 2  # Degree of the curve, order = degree+1

    nurbs.ctrlpts = allPts

    # Auto-generate knot vector
    nurbs.knotvector = utilities.generate_knot_vector(nurbs.degree,
                                                      len(nurbs.ctrlpts))

    # depending on how long the looping time is and how smooth you want the trajectory to be,
    # this value should be carefully tuned
    nurbs.sample_size = stepsBtwFrame + 1  # The total # of points that goes to pts = nurbs._curve_points

    nurbs.evaluate()  # need to put start and stop points

    pts = nurbs.evalpts  #[1:(stepsBtwFrame+1)]
    if draw == True:
        ##################### For climbing between 2 walls #####################
        plt.plot([nurbs.evalpts[i][0] for i in range(nurbs.sample_size)],
                 [nurbs.evalpts[i][1] for i in range(nurbs.sample_size)])
        plt.xlabel("x")
        plt.ylabel("z")
        #plt.xlim([-200, 10])
        #plt.ylim([-200, 200])
        plt.show(block=True)

    return pts
Beispiel #14
0
def test_bspline_curve_loadsave():
    curve_save = BSpline.Curve()
    curve_save.degree = C_DEGREE
    curve_save.ctrlpts = C_CTRLPTS3D
    curve_save.knotvector = C_KV
    curve_save.save(FILE_NAME)

    curve_load = BSpline.Curve()
    curve_load.load(FILE_NAME)

    # Remove save file
    os.remove(FILE_NAME)

    assert curve_save.degree == curve_load.degree
    assert curve_save.knotvector == curve_load.knotvector
    assert curve_save.ctrlpts == curve_load.ctrlpts
    assert curve_save.dimension == curve_load.dimension
def gen_kern_seq(num_spline_dots=12, kernel_size=(19, 38)):
    curve_degree = num_spline_dots - 1
    curve = BSpline.Curve()
    small_kernel_size = (int(np.round(kernel_size[0] / 1.5)) - 1,
                         int(np.round(kernel_size[1] / 1.5)) - 1)
    phi = np.random.rand() * 2 * np.pi
    knot_dots = [[
        small_kernel_size[0] * np.cos(phi), small_kernel_size[1] * np.sin(phi)
    ]]
    for i in range(1, num_spline_dots - 1):
        knot_dots += [[
            np.random.randint(0, small_kernel_size[0]),
            np.random.randint(0, small_kernel_size[1])
        ]]

    phi = np.random.rand() * 2 * np.pi
    knot_dots += [[
        small_kernel_size[0] * np.cos(phi), small_kernel_size[1] * np.sin(phi)
    ]]
    curve.degree = curve_degree
    curve.ctrlpts = knot_dots
    curve.knotvector = generate_knot_vector(curve.degree, len(curve.ctrlpts))

    curve1, curve2 = split_curve(curve, np.random.rand() * 0.2 + 0.4)

    curve1.delta = 0.005
    curve2.delta = 0.005
    curve1.evaluate()
    curve2.evaluate()

    pts_1 = np.array(curve1.evalpts)
    pts_1[:, 0] -= (pts_1[:, 0].min() - 2)
    pts_1[:, 1] -= (pts_1[:, 1].min() - 2)

    pts_2 = np.array(curve2.evalpts)
    pts_2[:, 0] -= (pts_2[:, 0].min() - 2)
    pts_2[:, 1] -= (pts_2[:, 1].min() - 2)

    k_dim = int(max(np.ceil(pts_1.max()), np.ceil(pts_2.max()))) + 2

    k1 = kern_from_grid(pts_1, k_dim + 1)
    k2 = kern_from_grid(pts_2, k_dim + 1)

    cm_k1 = np.round(calculate_center_mass(k1), 0).astype(int)
    dim_k1_c = 2 * max(list(np.array(k1.shape) - cm_k1) + list(cm_k1))

    cm_k2 = np.round(calculate_center_mass(k2), 0).astype(int)
    dim_k2_c = 2 * max(list(np.array(k2.shape) - cm_k2) + list(cm_k2))

    dim_final = max(dim_k1_c, dim_k2_c)
    if dim_final % 2 == 0: dim_final += 1

    k1 = expand(k1, (dim_final, dim_final))
    k2 = expand(k2, (dim_final, dim_final))

    k1 /= k1.sum()
    k2 /= k2.sum()
    return k1, k2
Beispiel #16
0
def generate_bspline(degree, control_points, knots, delta=0.005):
    curve = BSpline.Curve()
    curve.degree = degree
    curve.ctrlpts = control_points
    curve.knotvector = knots
    curve.delta = delta
    curve_points = curve.evalpts
    curve_points = np.asarray(curve_points)
    return curve, curve_points
    def render_to_tolerance(self, tolerance):
        curve = BSpline.Curve()
        curve.degree = self.degree
        curve.ctrlpts = self.control.tolist()
        curve.knotvector = self.knots.tolist()
        curve.sample_size = max(
            2, math.ceil(self.length_upper_bound() / tolerance))

        return burin.types.BSpline(curve, tolerance)
def test_bspline_curve3d_evaluate():
    curve = BSpline.Curve()
    curve.degree = C_DEGREE
    curve.ctrlpts = C_CTRLPTS3D
    curve.knotvector = C_KV
    curve.sample_size = SAMPLE_SIZE

    # Expected output
    res = [[1.0, 1.0, 0.0], [1.4375, 1.0625, -0.375], [1.75, 1.25, -0.5], [1.9375, 1.5625, -0.375], [2.0, 2.0, 0.0]]

    assert curve.evalpts == res
Beispiel #19
0
def nurbs(suc, pre, n=400):
    assert len(suc) == len(pre)
    xs = np.linspace(0, 1, len(suc) + 2).tolist()
    pts = np.array([xs[::-1] + xs[1:],
                    [0] + suc[::-1] + [0] + pre + [0]]).transpose().tolist()
    crv = BSpline.Curve()
    crv.degree = 2
    crv.ctrlpts = pts
    crv.knotvector = knotvector.generate(crv.degree, crv.ctrlpts_size)
    airfoil = np.array([crv.evaluate_single(t) for t in np.linspace(0, 1, n)])
    return airfoil[:, 0], airfoil[:, 1]
Beispiel #20
0
def getQuadBezier(P0, P1, P2, Degree=2, nSample=50):
    """
    返回一个QuadBezier对象, P0 P1 P2为控制点,Degree大于2可能报错,nSample为采样数目
    """
    curve = BSpline.Curve()
    curve.ctrlpts = [P0, P1, P2]
    curve.degree = Degree
    curve.knotvector = utilities.generate_knot_vector(curve.degree,
                                                      len(curve.ctrlpts))
    curve.sample_size = nSample
    return curve
Beispiel #21
0
def resample_coords_smooth(coords, sample_size=120, degree=3):
    """Resamples an array of coordinates while smoothing out the new values with a b-spline."""

    #Prevents code from breaking when the stroke contains too few values.
    while coords.shape[0] < degree + 1:
        coords = np.concatenate((coords, np.expand_dims(coords[-1], axis=0)), axis=0)

    curve = BSpline.Curve()
    curve.degree = degree
    curve.ctrlpts = coords.tolist()
    curve.knotvector = generate_knot_vector(degree, len(curve.ctrlpts))
    curve.sample_size = sample_size
    return np.array(curve.evalpts)
Beispiel #22
0
 def __init__(self, robot_id, plane_id):
     self.sys_t = 0                 # 系统时间
     self.l0 = 1.0                  # 腿长
     self.para = [20.0, -9.8, 1.0]  # [m, g, l0]机器人参数
     self.status = 'air'
     self.contact_status = [0, 0]
     self.robot_id = robot_id
     self.plane_id = plane_id
     self.dic_vel_jac = {}         # 由速度索引的控制雅可比矩阵
     # self.dic_air_time = {}        # 速度索引半周期
     # self.dic_sup_time = {}        # 速度索引的支撑时间
     self.pair_table = np.array([])
     # -----------本周期相关变量------------------
     self.start_time = 0             # 本周起的起始时间
     self.this_x = np.array([])     # 起始顶点状态
     self.des_v = 0                 # 参考速度
     self.des_pair = []             # 理想pair
     self.des_air_time = 0
     self.des_sup_time = 0
     self.this_pair = []            # 本周期的仿真pair
     self.this_du = np.array([])    # 无系数du
     self.this_u = np.array([])     # 本周期控制量
     self.this_T_half = 0           # 本半周期时间间隔
     self.this_t = 0                # 本周期时间
     self.this_curve_l = BSpline.Curve()
     self.this_curve_r = BSpline.Curve()
     self.a_begin = np.array([])    # 离地点速度方向
     self.p_begin = np.array([])
     self.a_end = np.array([])      # 着地点速度方向
     self.p_end = np.array([])
     self.status_change = True      # 初始默认有一个状态转换
     self.cycle_cnt = 1             # 半周期计数
     # 支撑阶段相关数据
     self.path_gen = []             # 质心路径生成器
     self.t_sup_max = 0
     self.t_sup_begin = 0             # 支撑相初始时间
def test_bspline_curve_loadsave(bspline_curve3d):
    fname = FILE_NAME + ".pickle"

    bspline_curve3d.save(fname)

    curve_load = BSpline.Curve()
    curve_load.load(fname)

    # Remove save file
    os.remove(fname)

    assert bspline_curve3d.degree == curve_load.degree
    assert bspline_curve3d.knotvector == curve_load.knotvector
    assert bspline_curve3d.ctrlpts == curve_load.ctrlpts
    assert bspline_curve3d.dimension == curve_load.dimension
def bs_curve():
    """ Creates a 3rd order 2D B-spline Curve instance """
    # Create a curve instance
    curve = BSpline.Curve()

    # Set curve degree
    curve.degree = 3

    # Set control points
    curve.ctrlpts = [[5.0, 5.0], [10.0, 10.0], [20.0, 15.0], [35.0, 15.0], [45.0, 10.0], [50.0, 5.0]]

    # Set knot vector
    curve.knotvector = [0.0, 0.0, 0.0, 0.0, 0.33, 0.66, 1.0, 1.0, 1.0, 1.0]

    return curve
Beispiel #25
0
def curve_test():
    print("Running curve test...")
    # Create the curve instance
    crv = BSpline.Curve()
    # Set degree
    crv.degree = 1
    # Set control points
    crv.ctrlpts = [[0, 0], [1, 1]]
    # Set knot vector
    crv.knotvector = [0, 0, 1, 1]

    # Get curve points
    points = crv.evalpts

    #assign every 10th pt to a list, as well as start and finish
    focus_pts = []
    focus_pts.append(points[0])
    k = 0
    for pt in points:
        if ((k % 10) == 0):
            focus_pts.append(pt)
            #print(pt)
    focus_pts.append(points[len(points) - 1])

    print(focus_pts)

    #my_pos should be fed by encoder readings, not by speculation of success
    my_pos = focus_pts[0]
    theta = 0

    for pt in focus_points:
        if (pt != my_pos):
            gamma = math.atan2((pt[1] - my_pos[1]) / (pt[0] - my_pos[0]))
            e_theta = theta - gamma
            e_dist = math.sqrt((pt[0] - my_pos[0])**2 + (pt[1] - my_pos[1])**2)

            #Now do the acceleration thing...
            base_power_set = [50, 50]  #or fake it in my case
            power_offsets = get_power_set(e_theta, e_dist)
            power_command = [
                base_power_set[0] + power_offsets[0],
                base_power_set[1] + power_offsets[1]
            ]

            #roboclaw.ForwardM2(address, power_command[0])
            #roboclaw.ForwardM1(address, power_command[1])

    return 1
    def create(self, ctrlpts_path):
        #Create the curve instance
        crv = BSpline.Curve()

        #Set the degree
        crv.degree = self.degree

        crv.delta = 0.005

        #Set control points
        crv.ctrlpts = exchange.import_txt(ctrlpts_path, separator=" ")

        #Generate a uniform knotvector
        crv.knotvector = knotvector.generate(crv.degree, crv.ctrlpts_size)

        #Get curve points and saving into a file
        self.bspline_points = np.array(crv.evalpts)
def Knotvector(CONTROL, degree):
    """Génère un vecteur de noeud uniforme en fonction des points
    de controle et du degré d'approximation"""

    #Creation de la courbe
    crv = BSpline.Curve()

    #Degre de la courbe
    crv.degree = degree

    #Initialisation des points de controles
    crv.ctrlpts = CONTROL.tolist()

    #Generation des knots
    crv.knotvector = knotvector.generate(crv.degree, crv.ctrlpts_size)

    return crv.knotvector
Beispiel #28
0
def splinei_lines(WIDTH,HEIGHT,MAX_SPLINE_WIDTH=120):
    curve = BSpline.Curve()
    curve.degree = 3
    curve.delta = 0.00005
    lpoints = linespread(WIDTH,HEIGHT,MAX_SPLINE_WIDTH)
    curve.ctrlpts = lpoints
    curve.knotvector = knotvector.generate(3, len(curve.ctrlpts))
    curve_points = curve.evalpts
    yield curve_points
    while True:
        for p in lpoints:
            p[1] += ((random() - 0.5) * (25) * (sin((p[0]) * (pi / WIDTH)) ** 2))
            p[0] += ((random() - 0.5) * (5) * (sin((p[0]) * (pi / WIDTH)) ** 2))
            p[2] += ((random() - 0.5) * (10) * (sin((p[0]) * (pi / WIDTH)) ** 2))
        curve.ctrlpts = lpoints
        curve_points = curve.evalpts
        yield curve_points
def BSplines_RoutinePython(CONTROL, KNOT, degree, t, dimension=2):
    """ Retourne un tableau numpy des coordonnées de la Bspline. Ses
    dérivées 1, 2 et 3. CONTROL est un tableau numpy des coordonnees
    des pts de controles et knot est une liste issu de Knotvector.
    Cette méthode utilise la fonction evaluation de NURBS Python"""

    #Creation de la courbe
    crv = BSpline.Curve()

    #Degre de la courbe
    crv.degree = degree

    #Initialisation des points de controles
    crv.ctrlpts = CONTROL.tolist()

    #Les noeuds
    crv.knotvector = KNOT

    if dimension == 2:
        BSPLINE = np.zeros((len(t), 2))
        DER1 = np.zeros((len(t), 2))
        DER2 = np.zeros((len(t), 2))
        DER3 = np.zeros((len(t), 2))

        for i in range(len(t)):
            DER = crv.derivatives(t[i], order=3)
            BSPLINE[i, :] = DER[0]
            DER1[i, :] = DER[1]
            DER2[i, :] = DER[2]
            DER3[i, :] = DER[3]

    if dimension == 3:
        BSPLINE = np.zeros((len(t), 3))
        DER1 = np.zeros((len(t), 3))
        DER2 = np.zeros((len(t), 3))
        DER3 = np.zeros((len(t), 3))

        for i in range(len(t)):
            DER = crv.derivatives(t[i], order=3)
            BSPLINE[i, :] = DER[0]
            DER1[i, :] = DER[1]
            DER2[i, :] = DER[2]
            DER3[i, :] = DER[3]

    return BSPLINE, DER1, DER2, DER3
def splinei():
    curve = BSpline.Curve()
    curve.degree = 3
    curve.delta = 0.000005
    lpoints = linespread()
    curve.ctrlpts = lpoints
    curve.knotvector = knotvector.generate(3, len(curve.ctrlpts))
    curve_points = curve.evalpts
    yield curve_points
    while True:
        for p in lpoints:
            p[1] += int((random() - 0.5) * (25) * (sin(
                (p[0]) * (pi / WIDTH))**2))
            p[0] += int((random() - 0.5) * (5) * (sin(
                (p[0]) * (pi / WIDTH))**2))
        curve.ctrlpts = lpoints
        curve_points = curve.evalpts
        yield curve_points