Exemple #1
0
def nikeLogo(x):
    if x < 0.25:
        return bezier((9, 8), (0, 2), (-4, 0), (-6, 0), x, 0.25)
    elif x < 0.5:
        return bezier((-6, 0), (-9, 0), (-10, 3), (-6, 7), x - (0.25), 0.25)
    elif x < 0.75:
        return bezier((-6, 7), (-7, 4), (-6, 3), (-5, 3), x - (0.5), 0.25)
    else:
        return bezier((-5, 3), (-3, 3), (0, 4), (9, 8), x - (0.75), 0.25)
def paint_canvas(x, y, colors):
	"""creates the png file and colors colors it
	"""
	sys.setrecursionlimit(15000)
	padding = 1
	point1hat = math.atan((y[3] - y[0])/(x[3] - x[0])) + math.pi

	if x[75] - x[0] < 0:
		point1hat = math.pi + point1hat
	point2hat = math.atan((y[-1] - y[-3])/(x[-1] - x[-3]))
	if x[-1] - x[-75] < 0:
		point2hat = math.pi + point2hat

	closeIt = bezier((x[0],y[0]), point1hat, (x[-1],y[-1]), point2hat)	#calls bezier function in order to close the open loop
	xnew = x + closeIt[0]
	ynew = y + closeIt[1]

	canvas = Image.new("RGB",(int(round(max(xnew)- min(xnew)))+2*padding, int(round((max(ynew) - min(ynew))))+2*padding))
	pixels = canvas.load()

	for i in range(len(xnew)):
		pixels[xnew[i]+padding+0, ynew[i]+padding+0] = (255, 255, 255)

	imagepath = "images/techtest.png"
	canvas.save(imagepath)
	centers = findZones(imagepath)

	for i in range(len(centers)):
		flood(pixels,centers[i], color = colors[i%len(colors)], visited = [])

	canvas = canvas.resize((1000,1000), Image.NEAREST)
	canvas.save(imagepath)	
Exemple #3
0
 def test_derivative_multidimensional(self):
     np.random.seed(123)
     w = np.random.rand(4, 3)
     f = lambda t: bezier.bezier(w, t)
     g = numdifftools.Jacobian(f)
     np.testing.assert_array_almost_equal(np.squeeze(g(.9)),
                                          bezier.bezier_deriv(w, .9))
Exemple #4
0
    def test_second_derivative_multidimensional(self):
        np.random.seed(123)
        w = np.random.rand(4, 3)
        f = lambda t: bezier.bezier(w, t)

        g2 = [numdifftools.Derivative((lambda t: f(t)[i]), n=2)(.9)
              for i in range(len(w[0]))]

        g2 = np.squeeze(g2)
        np.testing.assert_array_almost_equal(g2,
                                             bezier.bezier_second_deriv(w, .9))
Exemple #5
0
def plot_bezier_curve(control_points, **kwargs):
    colors = default_style_colors()
    x, y = list(zip(*control_points))
    times = np.linspace(0, 1, num=1000)
    curve = [bezier(control_points, t) for t in times]
    curve_x, curve_y = zip(*curve)
    plot_kwargs = {"color": colors[1], "marker": "o"}  # set default style
    plot_kwargs.update(kwargs)
    plt.plot(x, y, **plot_kwargs)
    plt.plot(curve_x, curve_y, color=colors[0])
    plt.axis(axis_bounds(x, y))
    plt.show()
def run_furgale():
    bezier_order = 4

    bezier_params = np.random.rand(bezier_order, 3)
    bezier_params *= 10
    bez = lambda t: bezier(bezier_params, t)
    bezderiv = lambda t: np.squeeze(numdifftools.Jacobian(lambda tt: bez(tt))(t))

    t0 = 1.23
    r0 = cayley(bez(t0))
    w0 = angular_velocity_from_cayley_deriv(bez(t0), bezderiv(t0))

    print 'Params:'
    print bezier_params
    print 'Rotation'
    print r0

    print 'Numeric right:', angular_velocity_right(lambda t: cayley(bez(t)), t0)
    print 'Analytic global:', w0

    print 'Numeric left:', angular_velocity_left(lambda t: cayley(bez(t)), t0)
    print 'Analytic local:', np.dot(r0, w0)
Exemple #7
0
def desenha():
    global globVector

    glClear(GL_COLOR_BUFFER_BIT)

    # desenho do quadrado
    glBegin(GL_QUADS)
    glColor3f(0.75, 0.75, 0.75)
    for ponto in quadrado:
        glVertex2f(ponto.coord_x, ponto.coord_y)
    glEnd()

    # desenho dos pontos de controle da curva
    if pontos.__len__() > 0:
        glPointSize(12.0)
        glBegin(GL_POINTS)
        glColor3f(1.0, 0.0, 0.0)
        for ponto in pontos:
            glVertex2f(ponto.coord_x, ponto.coord_y)
        glEnd()

        # desenho das linhas entre os pontos de controle
        if pontos.__len__() > 1:
            glBegin(GL_LINE_STRIP)
            glColor3f(0.0, 1.0, 1.0)
            for ponto in pontos:
                glVertex2f(ponto.coord_x, ponto.coord_y)
            glEnd()

            # desenho da curva de bezier (linhas conectando os pontos computados pelo De Casteljau
            glBegin(GL_LINE_STRIP)
            glColor3f(1.0, 1.0, 1.0)
            globVector = bezier.bezier(pontos, fator)
            glEnd()

            glPointSize(6.0)

            # desenho dos pontos
            glBegin(GL_POINTS)
            glColor3f(0.0, 1.0, 0.0)
            globVector.append(pontos[-1])
            for p in globVector:
               glVertex2d(p.coord_x, p.coord_y)
            glEnd()

            # pintura da area delimitada pela curva
            poligono = [ponto_b] + [ponto_a] + globVector
            glEnable(GL_BLEND)
            glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

            # pintura da area delimitada pela curva
            glBegin(GL_POLYGON)
            glColor4f(0.0,0.0,0.3,0.7)
            for p in poligono:
                glVertex2d(p.coord_x, p.coord_y)
            glEnd()

        else:
            aux = pontos[0]
            glVertex2d(aux.coord_x, aux.coord_y)

    glFlush()
Tu_b_mean[1] = 0.1570
Tv_b_mean[1] = 0.0668
Tw_b_mean[1] = 0.0935

#%% test2 (first optimization step) -------------------------------------------

it = 1

# compute input points
[vv_P, ww_P] = multiObjGrad_Rij(uu_b, uu_exp, vv_b, vv_exp, ww_b, ww_exp, vv_P,
                                ww_P, index_probes, it)
[Tv_0, Tw_0] = multiObjGrad_Ti(Tu_b_mean, 0.1482, Tv_b_mean, 0.0337, Tw_b_mean,
                               0.0469, Tv_0, Tw_0, it)

# Bezier curves
[uu_0, zuu_0] = bezier(uu_P[:, :, 2], Nsample)
[vv_0, zvv_0] = bezier(vv_P[:, :, 2], Nsample)
[ww_0, zww_0] = bezier(ww_P[:, :, 2], Nsample)

# Write input for test2
numpy.savetxt(os.path.join(test2, 'constant/vvBarInlet'),
              numpy.array([zvv_0, vv_0]).T,
              header='(',
              footer=')',
              comments='')
numpy.savetxt(os.path.join(test2, 'constant/wwBarInlet'),
              numpy.array([zww_0, ww_0]).T,
              header='(',
              footer=')',
              comments='')
def fit_bezier_1d(ts, ys, bezier_order):
    jacobian = np.array([bezier_coefs(t, bezier_order) for t in ts])
    residual = np.array([bezier(np.zeros(bezier_order), t) - y for t, y in zip(ts, ys)])
    return np.linalg.lstsq(jacobian, -residual)[0]
 def evaluate(self, t):
     return bezier.bezier(self._controls, t)
Exemple #11
0
 def test_derivative(self):
     w = np.array([1.7, 2.8, 1.4, -3.6])
     f = lambda t: bezier.bezier(w, t)
     g = numdifftools.Gradient(f)
     np.testing.assert_array_almost_equal(g(.9),
                                          bezier.bezier_deriv(w, .9))
Exemple #12
0
 def test_second_derivative(self):
     w = np.array([1.7, 2.8, 1.4, -3.6])
     f = lambda t: bezier.bezier(w, t)
     g2 = numdifftools.Hessdiag(f)
     np.testing.assert_array_almost_equal(g2(.9),
                                          bezier.bezier_second_deriv(w, .9))