Sie sind auf Seite 1von 25

Curvas no TikZ

Neste tópico falaremos sobre os diversos tipos de curvas feitos pelo TikZ, sendo eles os operadores:
to, bend, smooth e Bezier.
Nota: Use o KtikZ para fazer seus testes, por oferecer um preview em tempo real. Para isso, basta
digitar \begin{tikzpicture} e \end{tikzpicture} e começar seu desenho.

Rounded corners
Antes de iniciarmos nosso tutorial sobre curvas vejamos uma opção muito útil: rounded corners.
Esta opção permite que os cantos da figura sejam arredondados a partir de um valor numérico.

Figura 1: Exemplo do uso de rounded corners.

\ begin { tikzpicture }
\ draw (0 ,0) -- ++(5 ,0) -- ++( -2 ,2) -- ++( -3 ,0) -- cycle ;
\ draw [ rounded corners ] (6 ,0) -- ++(5 ,0) -- ++( -2 ,2) -- ++( -3 ,0) -- cycle ;
\ draw [ rounded corners =5 mm ] (12 ,0) -- ++(5 ,0) -- ++( -2 ,2) -- ++( -3 ,0) -- cycle ;
\ end { tikzpicture }

Figura 2: rounded corners em três raios diferentes.

\ begin { tikzpicture }
\ draw (0 ,0) rectangle ++(2 ,2) ;
\ draw [ rounded corners ] (3 ,0) rectangle ++(2 ,2) ;
\ draw [ rounded corners =1 cm ] (6 ,0) rectangle ++(2 ,2) ;
\ end { tikzpicture }

Régis , 2011 http://latexbr.blogspot.com/ 1


\begin{tikzpicture}
\draw (5,-4) -- (5,4);
\draw[rounded corners=5mm] (5,-4) -- (4,-4) --
(4,4) -- (5,4);
\draw[rounded corners=1cm] (4,-3) -- (1,-3) --
(1,-1) -- (-1,-1) -- (-1,1) -- (1,1) -- (1,3)
-- (4,3);
\draw[rounded corners=1cm] (4,-1) -- (2,-1) --
(2,1) -- (4,1);
\draw[rounded corners=1cm] (5,-3) -- (7,-3) --
(7,-1) -- (5,-1);
\draw[rounded corners=1cm] (5,1) -- (7,1) -- (7,3)
-- (5,3);
\draw (0,0) circle (.5);
\draw (6,-2) circle (.5);
\draw (6,2) circle (.5);
%linhas guia
\draw[red,dashed] (0,-1.5) -- ++(0,3) (-1.5,0) --
++(3,0);
\draw[red,dashed] (6,-3.5) -- ++(0,3) (4.5,-2) --
++(3,0);
\draw[red,dashed] (6,0.5) -- ++(0,3) (4.5,2) --
++(3,0);
%cotas
\draw[<->,red,rotate=45] (-.5,0) -- ++(1,0)
node[right] {$1\,cm$};
\draw[|<->|,red] (-2,-1) --
node[rotate=90,above] {$2\,cm$} (-2,1);
\draw[red,dashed] (-2,-1) -- (-.5,-1);
\draw[red,dashed] (-2,1) -- (-.5,1);
\draw[|<->|,red] (7.5,-2) --
node[rotate=90,above] {$4\,cm$} (7.5,2);
\draw[|<->|,red] (9,-4) --
node[rotate=90,above] {$8\,cm$} (9,4);
\draw[red,dashed] (5.5,-4) -- (9,-4);
\draw[red,dashed] (5.5,4) -- (9,4);
\end{tikzpicture}

Régis , 2011 http://latexbr.blogspot.com/ 2


To
O operador To é usado para adicionar um caminho da coordenada anterior para a coordenada
seguinte. Quando você escreve (A) to (B), uma linha é adicionada de A para B, exatamente como
se você tivesse escrito (A)--(B).
No entanto, se você escrever (A) to[out=90,in=180] (B) uma curva é adicionada ao caminho,
saindo do ponto A com um ângulo de 90o e chegando no ponto B com um ângulo de 180o (levando
em consideração que o ângulo 0 inicia-se do lado direito de um ponto fixo e percorre no sentido anti-
horário). É claro que podemos digitar (0,0) to[out=90,in=180] (2,3). Os pontos A e B são pontos
nomeados que são usados a partir do comando \coordinate.
Na terceira figura temos um exemplo saindo do ponto A a 45o e chegando em B a 135o .

180◦ 135◦
B
B B

90◦
45◦
A A A

Figura 3: Exemplos do operador to.

Veja o código:
\ begin { tikzpicture }
\ tikzset { >= latex }
\ tikzstyle { ponto }=[ fill = blue , circle , scale =.25]
\ coordinate [ ponto , label = left : A ] ( A ) at (0 ,0) ;
\ coordinate [ ponto , label = left : B ] ( B ) at (2 ,3) ;
\ coordinate [ ponto , label = left : A ] ( C ) at (3 ,0) ;
\ coordinate [ ponto , label = below : B ] ( D ) at (5 ,3) ;
\ coordinate [ ponto , label = left : A ] ( E ) at (6 ,0) ;
\ coordinate [ ponto , label = below : B ] ( F ) at (8 ,3) ;
% to
\ draw ( A ) to ( B ) ;
\ draw [ - >] ( C ) to [ out =90 , in =180] ( D ) ;
\ draw [ - >] ( E ) to [ out =45 , in =135] ( F ) ;
\ end { tikzpicture }

Régis , 2011 http://latexbr.blogspot.com/ 3


Veja a seguir um desenho um pouco mais elaborado:

G F

J
H E

A D

B C K

Figura 4: Mais um exemplo do operador to.

E o código:
\ begin { tikzpicture }
\ tikzstyle { ponto }=[ fill = blue , circle , scale =.25]
\ coordinate [ ponto , label = left : A ] ( A ) at (0 ,1) ;
\ coordinate [ ponto , label = below : B ] ( B ) at (1 ,0) ;
\ coordinate [ ponto , label = below : C ] ( C ) at (3 ,0) ;
\ coordinate [ ponto , label = right : D ] ( D ) at (4 ,1) ;
\ coordinate [ ponto , label = right : E ] ( E ) at (4 ,3) ;
\ coordinate [ ponto , label = above : F ] ( F ) at (3 ,4) ;
\ coordinate [ ponto , label = above : G ] ( G ) at (1 ,4) ;
\ coordinate [ ponto , label = left : H ] ( H ) at (0 ,3) ;
\ coordinate [ ponto , label = left : I ] ( I ) at (6 ,2) ;
\ coordinate [ ponto , label = above : J ] ( J ) at (8 ,3) ;
\ coordinate [ ponto , label = below : K ] ( K ) at (8 ,0) ;
% to
\ draw ( A ) to [ out = -90 , in =180] ( B ) ;
\ draw ( C ) to [ out =0 , in = -90] ( D ) ;
\ draw ( E ) to [ out =90 , in =0] ( F ) ;
\ draw ( G ) to [ out =180 , in =90] ( H ) ;
\ draw [ dashed ] ( B ) -- ( C ) ( D ) -- ( E ) ( F ) -- ( G ) ( H ) -- ( A ) ;
\ draw ( I ) to [ out =45 , in =225] ( J ) to [ out =45 , in =0] ( K ) to [ out =180 , in =225] ( I ) ;
\ end { tikzpicture }

Régis , 2011 http://latexbr.blogspot.com/ 4


Veja mais um exemplo com uma figura conhecida: arcos góticos.

Figura 5: Arcos góticos.

\ begin { tikzpicture }
\ draw [ blue ] (0 ,0) to [ out =90 , in =225] (1 ,2) to [ out = -45 , in =90] (2 ,0) ;
\ draw [ brown ] (3 ,0) to [ out =90 , in = -90] (4 ,2) to [ out = -90 , in =90] (5 ,0) ;
\ end { tikzpicture }
Veja também os exemplos Clusters of atoms e Beamer arrows.

Bend
Existem dois operadores: bend left e bend right. Ambos são usados como opção para o operador
to. O bend left funciona da seguinte forma: se você digitar bend left=45, o resultado será equivalente
a out=45,in=135. Ou seja, out=<^ angulo>,in=180 - <^ angulo>. O bend right funciona de forma
contrária.

45◦ 90◦

A B C D E F

H J L N

bend left bend right bend left bend right

G I
K M

Figura 6: Exemplo do operador bend.

\ begin { tikzpicture }
\ tikzstyle { ponto }=[ fill = blue , circle , scale =.25]
\ coordinate [ ponto , label = below : A ] ( A ) at (0 ,3) ;
\ coordinate [ ponto , label = below : B ] ( B ) at (2 ,3) ;
\ coordinate [ ponto , label = below : C ] ( C ) at (3 ,3) ;
\ coordinate [ ponto , label = below : D ] ( D ) at (5 ,3) ;
\ coordinate [ ponto , label = below : E ] ( E ) at (6 ,3) ;
\ coordinate [ ponto , label = below : F ] ( F ) at (8 ,3) ;
\ coordinate [ ponto , label = left : G ] ( G ) at (0 ,0) ;
\ coordinate [ ponto , label = left : H ] ( H ) at (0 ,2) ;
\ coordinate [ ponto , label = left : I ] ( I ) at (2 ,0) ;
\ coordinate [ ponto , label = left : J ] ( J ) at (2 ,2) ;
\ coordinate [ ponto , label = below : K ] ( K ) at (3 ,0) ;
\ coordinate [ ponto , label = right : L ] ( L ) at (5 ,2) ;
\ coordinate [ ponto , label = below : M ] ( M ) at (6 ,0) ;

Régis , 2011 http://latexbr.blogspot.com/ 5


\ coordinate [ ponto , label = right : N ] ( N ) at (8 ,2) ;
% bend
\ draw ( A ) to [ bend left ] ( B ) ;
\ draw ( C ) to [ bend left =45] ( D ) ;
\ draw ( E ) to [ bend left =90] ( F ) ;
\ draw [ - >] ( G ) to [ bend left ] ( H ) ;
\ draw [ - >] ( I ) to [ bend right =60] ( J ) ;
\ draw [ - >] ( K ) to [ bend left ] ( L ) ;
\ draw [ - >] ( M ) to [ bend right ] ( N ) ;
\ node at (4 ,4) {$45^\ circ $};
\ node at (7 ,4) {$90^\ circ $};
\ node [ left ] at ( -.5 ,1) { bend left };
\ node at (1.5 ,1) { bend right };
\ node at (4.5 ,1) { bend left };
\ node at (9 ,1) { bend right };
\ end { tikzpicture }
Veja mais um exemplo: fios de postes.

Figura 7: Fios do poste feito com bend.

\ begin { tikzpicture }
\ draw ( -1 ,0) -- (5 ,0) ;
% postes
\ fill (0 ,0) -- ++(0 ,2) -- ++( -.1 ,0) -- ++(0 ,.1) -- ++(.4 ,0) -- ++(0 , -.1) --
++( -.1 ,0) -- ++(0 , -2) -- cycle ;
\ fill (2 ,0) -- ++(0 ,2) -- ++( -.1 ,0) -- ++(0 ,.1) -- ++(.4 ,0) -- ++(0 , -.1) --
++( -.1 ,0) -- ++(0 , -2) -- cycle ;
\ fill (4 ,0) -- ++(0 ,2) -- ++( -.1 ,0) -- ++(0 ,.1) -- ++(.4 ,0) -- ++(0 , -.1) --
++( -.1 ,0) -- ++(0 , -2) -- cycle ;
% fios
\ draw [ blue ] (.25 ,2) to [ bend right ] (1.95 ,2) ;
\ draw [ blue ] (2.25 ,2) to [ bend right ] (3.95 ,2) ;
\ end { tikzpicture }

Veja mais exemplos do uso de bend em EPC Flow Charts e Mobile ad-hoc network.

Régis , 2011 http://latexbr.blogspot.com/ 6


Smooth
Esta opção faz com que os pontos de uma curva sejam conectados por uma curva suave. Mas esta
opção só é usada com o operador plot e coordinates.
Um exemplo simples é:

\draw[smooth] plot coordinates {(0,0) (1,1) (2,0) (3,1)};

No caso eu usei 4 pontos, mas pode ser qualquer quantidade a partir de 2 pontos.
Temos também a opção tension, que permite um ajuste na curva suavizando os cantos. Veja na
figura a seguir um exemplo com 4 pontos (esquerda) e um exemplo da mesma curva com várias tensões
diferentes.

tension=1.5
tension=1
B D F
tension=default
tension=0

A C E G

Figura 8: Exemplo de smooth.

\ begin { tikzpicture }[ >= latex ]


\ tikzstyle { ponto }=[ fill = blue , circle , scale =.25]
\ coordinate [ ponto , label = below : A ] ( A ) at (0 ,0) ;
\ coordinate [ ponto , label = above : B ] ( B ) at (1 ,1) ;
\ coordinate [ ponto , label = below : C ] ( C ) at (2 ,0) ;
\ coordinate [ ponto , label = above : D ] ( D ) at (3 ,1) ;
\ coordinate [ ponto , label = below : E ] ( E ) at (4 ,0) ;
\ coordinate [ ponto , label = above : F ] ( F ) at (6 ,1) ;
\ coordinate [ ponto , label = below : G ] ( G ) at (8 ,0) ;
\ draw [ red , dashed , very thin ] ( A ) -- ( B ) -- ( C ) -- ( D ) ;
\ draw [ red , dashed , very thin ] ( E ) -- ( F ) -- ( G ) ;
% smooth
\ draw [ smooth ] plot coordinates {( A ) ( B ) ( C ) ( D ) };
\ draw [ smooth ] plot coordinates {( E ) ( F ) ( G ) };
\ draw [ smooth , tension =1 , blue ] plot coordinates {( E ) ( F ) ( G ) };
\ draw [ smooth , tension =1.5 , brown ] plot coordinates {( E ) ( F ) ( G ) };
% setas
\ draw [ < -] (7 ,.85) -- (7.5 ,2) node [ right ] {\ footnotesize tension =1.5};
\ draw [ < -] (7.2 ,.65) -- (8 ,1.5) node [ right ] {\ footnotesize tension =1};
\ draw [ < -] (7.3 ,.45) -- (8.5 ,1) node [ right ] {\ footnotesize tension = default };
\ draw [ < -] (7.4 ,.3) -- (9 ,.5) node [ right ] {\ footnotesize tension =0};
\ end { tikzpicture }

Régis , 2011 http://latexbr.blogspot.com/ 7


A seguir um outro exemplo com diferentes tensões mas desta vez usando a opção smooth cycle.
Esta opção fecha o ciclo de uma figura aberta transformando-a numa figura fechada.

B F J

A C E G I K

D H L

tension=0.2 tension=0.5 tension=1

Figura 9: Exemplo de smooth cycle.

\ begin { tikzpicture }
\ tikzstyle { ponto }=[ fill = blue , circle , scale =.25]
\ coordinate [ ponto , label = left : A ] ( A ) at (0 ,0) ;
\ coordinate [ ponto , label = above : B ] ( B ) at (1 ,1) ;
\ coordinate [ ponto , label = right : C ] ( C ) at (2 ,0) ;
\ coordinate [ ponto , label = below : D ] ( D ) at (1 , -1) ;
\ coordinate [ ponto , label = left : E ] ( E ) at (4 ,0) ;
\ coordinate [ ponto , label = above : F ] ( F ) at (5 ,1) ;
\ coordinate [ ponto , label = right : G ] ( G ) at (6 ,0) ;
\ coordinate [ ponto , label = below : H ] ( H ) at (5 , -1) ;
\ coordinate [ ponto , label = left : I ] ( I ) at (8 ,0) ;
\ coordinate [ ponto , label = above : J ] ( J ) at (9 ,1) ;
\ coordinate [ ponto , label = right : K ] ( K ) at (10 ,0) ;
\ coordinate [ ponto , label = below : L ] ( L ) at (9 , -1) ;
% smooth cycle
\ draw [ smooth cycle ] plot [ tension =0.2] coordinates {( A ) ( B ) ( C ) ( D ) };
\ draw [ smooth cycle , yshift = -2.25 cm ]
plot [ tension =0.5] coordinates {( E ) ( F ) ( G ) ( H ) };
\ draw [ smooth cycle , yshift = -4.5 cm ]
plot [ tension =1] coordinates {( I ) ( J ) ( K ) ( L ) };
% texto
\ node at (1 , -2) { tension =0.2};
\ node at (5 , -2) { tension =0.5};
\ node at (9 , -2) { tension =1};
\ end { tikzpicture }

Régis , 2011 http://latexbr.blogspot.com/ 8


Mais um exemplo:

Figura 10: Carro feito com smooth cycle.

\ begin { tikzpicture }[ x =.5 , y =.5]


\ draw [ smooth cycle , tension =.55] plot coordinates {
(20 ,45) (70 ,36) (80 ,40) (85 ,80) (110 ,100)
(150 ,100) (170 ,80) (178 ,60) (185 ,40) (230 ,38) (400 ,38)
(440 ,42) (455 ,80) (478 ,102) (514 ,102) (530 ,90)
(542 ,70) (545 ,48) (555 ,49) (573 ,60) (577 ,80)
(577 ,95) (565 ,110) (563 ,150) (555 ,170) (480 ,217)
(370 ,222) (280 ,215) (175 ,157) (40 ,120) (23 ,100)
(20 ,90)
};
\ draw [ smooth cycle , tension =.55] plot coordinates {
(185 ,145) (400 ,155) (510 ,165) (465 ,205) (415 ,212) (300 ,210)
};
\ draw (130 ,50) circle (42) ;
\ draw (495 ,50) circle (42) ;
\ end { tikzpicture }
Veja os videos smooth carro 01 e smooth carro 02 no youtube.
Veja um exemplo de smooth em Temperature and rain sparklines.

Régis , 2011 http://latexbr.blogspot.com/ 9


Comparação entre out, in, bend e smooth
Veja um comparação entre as curvas com o uso de out, in, bend e smooth.

bend right

out,in smooth

Figura 11: Comparação entre out, in, bend e smooth

\ begin { tikzpicture }
\ tikzset { >= latex , inner sep =0 pt , outer sep =2 pt }
% bend
\ draw [ red ] (0 ,0) to [ bend right ] (2 ,2) ;
% out , in
\ draw [ green ] (0 ,0) to [ out =0 , in = -90] (2 ,2) ;
% smooth
\ draw [ blue , smooth , tension =.5] plot coordinates {(0 ,0) (1.75 ,.25) (2 ,2) }
% textos e flechas
\ draw [ - >] (.5 ,1.5) node [ above ] {\ tiny bend right }
to [ out = -90 , in =135] (1.3 ,.7) ;
\ draw [ - >] (0 ,1) node [ left ] {\ tiny out , in }
to [ out =0 , in =135] (1.2 ,.4) ;
\ draw [ - >] (2.5 ,1) node [ right ] {\ tiny smooth }
to [ out =180 , in =0] (1.9 ,.5) ;
% bolinhas azuis
\ fill [ blue ] (0 ,0) circle (1 pt ) ;
\ fill [ blue ] (1.75 ,.25) circle (1 pt ) ;
\ fill [ blue ] (2 ,2) circle (1 pt ) ;
\ end { tikzpicture }

Régis , 2011 http://latexbr.blogspot.com/ 10


Bézier - controls
O operador se chama controls. Bézier é um tipo de curva definida por pontos de controle
que determinam sua curvatura. Podemos definir as curvas Bézier de duas maneiras: por coordenadas
polares ou por coordenadas cartesianas.

Coordenadas Polares
Considere os pontos P1 e P2 da figura a seguir como os pontos de inı́cio e fim da curva, e considere
os pontos C1 e C2 como pontos de controle que definem a curvatura da curva. Suponha uma reta
suporte passando por P1 e C1 e outra passando por P2 e C2. Essas retas tangenciam a curva em
P1 e P2 definindo assim a curvatura da curva.

ponto de
Curva Bézier controle
C2

raio
ponto de
controle r2
C1 reta tangente a
r1 curva em P2
ponto ângulo
inicial α β
P1 P2
ponto
final
reta tangente a
curva em P1

Figura 12: Curva Bézier definida por coordenadas polares.

A sintaxe para gerar uma curva Bézier usando coordenadas polares é a seguinte:

\draw (P1) .. controls +(α : r1 ) and +(β : r2 ) .. (P2);

onde P1 é o ponto inicial, P2 é o ponto final, α e β são os ângulos de inclinação das retas tangentes
a P1 e P2, respectivamente; e r1 e r2 é o comprimento de cada reta tangente, ou seja, a distância de
P1 à C1 e P2 à C2, respectivamente.

Régis , 2011 http://latexbr.blogspot.com/ 11


Exemplo com coordenadas polares
Veja o código mais simples para geração da curva Bézier em coordenadas polares.
\ begin { tikzpicture }
\ draw (0 ,0) .. controls +(45:1) and +(60:2) .. (2 ,0) ;
\ end { tikzpicture }

C2

C1

45◦ 60◦
P1 P2
resultado final

Figura 13: Exemplo de curva Bézier definida por coordenadas polares.

A seguir um código mais completo com o uso de coordenadas previamente definidas e estilos para
visualização dos pontos. Mas lembrando que, o código anterior é suficiente para gerar a curva.
\ begin { tikzpicture }
% definicao de estilos
\ tikzset { >= latex ,
ponto /. style ={ draw , fill = blue , rectangle , scale =.5} ,
controle /. style ={ draw , blue , circle , scale =.5}
}
% coordenadas
\ coordinate [ ponto , label = below : P 1] ( p 1) at (0 ,0) ;
\ coordinate [ ponto , label = below : P 2] ( p 2) at (2 ,0) ;
\ coordinate [ controle , label = above : C 1] ( c 1) at (45:1) ;
\ coordinate ( c 2) at (60:2) ;
% coordenada necessaria para posicao correta do ponto cc 2 para desenhar a reta
tangente .
% Nao eh obrigatorio .
\ coordinate [ controle , , label = above : C 2 , xshift =4 cm ] ( cc 2) at ( c 2) ; % xshift com o
dobro da posicao do ponto .
% retas
\ draw [ blue ] ( p 1) -- ( c 1) ( p 2) -- ( cc 2) ;
% bezier
\ draw ( p 1) .. controls +( c 1) and +( c 2) .. ( p 2) ;
\ end { tikzpicture }

Régis , 2011 http://latexbr.blogspot.com/ 12


Coordenadas Cartesianas
Através de coordenadas cartesianas os pontos P1, P2, C1 e C2 são definidos pelo par ordenado (x, y).

pontos de
controle

C1 C2

ponto
inicial Curva Bézier ponto
final
P1 P2

0 x

Figura 14: Curva Bézier definida por coordenadas cartesianas.

A sintaxe para gerar uma curva Bézier usando coordenadas cartesianas é a seguinte:

\draw (P1) .. controls (C1) and (C2) .. (P2);

onde P1 é o ponto inicial, P2 é o ponto final, C1 e C2 são os pontos de controle.

Exemplo com coordenadas cartesianas


Uma curva Bézier pode ser definida por um ou dois pontos de controle para cada trecho de curva.
Veja o código mais simples para geração da curva Bézier em coordenadas cartesianas, no caso, com
um ponto de controle.
\ begin { tikzpicture }
\ draw (0 ,0) .. controls (1 ,2) .. (4 ,0) ;
\ end { tikzpicture }

C1

P1 P2
resultado final

Figura 15: Curva Bézier com um ponto de controle.

A seguir um código mais completo com o uso de coordenadas previamente definidas e estilos para
visualização dos pontos.

Régis , 2011 http://latexbr.blogspot.com/ 13


\ begin { tikzpicture }
\ tikzset { >= latex ,
ponto /. style ={ draw , fill = blue , rectangle , scale =.5} ,
controle /. style ={ draw , blue , circle , scale =.5}
}
% grade
\ draw [ color = lightgray , dashed ] (0 ,0) grid (4 ,3) ;
% coordenadas
\ coordinate [ ponto , label = below : P 1] ( p 1) at (0 ,0) ;
\ coordinate [ ponto , label = below : P 2] ( p 2) at (4 ,0) ;
\ coordinate [ controle , label = above : C 1] ( c 1) at (1 ,2) ;
% retas
\ draw [ blue ] ( p 1) -- ( c 1) -- ( p 2) ;
% bezier
\ draw ( p 1) .. controls ( c 1) .. ( p 2) ;
\ end { tikzpicture }
Se você quiser as coordenadas sem os estilos basta dar uma simplificada no código anterior.
\ begin { tikzpicture }
\ coordinate ( p 1) at (0 ,0) ;
\ coordinate ( p 2) at (4 ,0) ;
\ coordinate ( c 1) at (1 ,2) ;
% bezier
\ draw ( p 1) .. controls ( c 1) .. ( p 2) ;
\ end { tikzpicture }

Curva com dois pontos de controle


A seguir, uma curva com dois pontos de controle. Repare o uso do operador and.
\ begin { tikzpicture }
\ draw (0 ,0) .. controls (1 ,2) and (2 ,2) .. (4 ,0) ;
\ end { tikzpicture }

C1 C2

P1 P2
resultado final

Figura 16: Curva Bézier com dois pontos de controle.

\ begin { tikzpicture }
\ tikzset { >= latex ,
ponto /. style ={ draw , fill = blue , rectangle , scale =.5} ,
controle /. style ={ draw , blue , circle , scale =.5}
}
% grade
\ draw [ color = lightgray , dashed ] (0 ,0) grid (4 ,3) ;

Régis , 2011 http://latexbr.blogspot.com/ 14


% coordenadas
\ coordinate [ ponto , label = below : P 1] ( p 1) at (0 ,0) ;
\ coordinate [ ponto , label = below : P 2] ( p 2) at (4 ,0) ;
\ coordinate [ controle , label = above : C 1] ( c 1) at (1 ,2) ;
\ coordinate [ controle , label = above : C 2] ( c 2) at (2 ,2) ;
% retas
\ draw [ blue ] ( p 1) -- ( c 1) ( p 2) -- ( c 2) ;
% bezier
\ draw ( p 1) .. controls ( c 1) and ( c 2) .. ( p 2) ;
\ end { tikzpicture }
E o código somente com as coordenadas:
\ begin { tikzpicture }
\ coordinate ( p 1) at (0 ,0) ;
\ coordinate ( p 2) at (4 ,0) ;
\ coordinate ( c 1) at (1 ,2) ;
\ coordinate ( c 2) at (2 ,2) ;
% bezier
\ draw ( p 1) .. controls ( c 1) and ( c 2) .. ( p 2) ;
\ end { tikzpicture }

Exemplo de duas curvas


Daqui pra frente sempre usaremos coordenadas previamente definidas e estilos para visualização
dos pontos.
Para fazer duas curvas basta inserir um novo controls. Assim, teremos:

\draw (P1) .. controls (C1) and (C2) .. (P2)


.. controls (C3) and (C4) .. (P3);

C1 C2

P3
P1 P2

C3 C4 resultado final

Figura 17: Duas curvas Bézier.

\ begin { tikzpicture }
\ tikzset { >= latex ,
ponto /. style ={ draw , fill = blue , rectangle , scale =.5} ,
controle /. style ={ draw , blue , circle , scale =.5}
}
% grade
\ draw [ color = lightgray , dashed ] (0 , -2) grid (6 ,2) ;
% coordenadas
\ coordinate [ ponto , label = below : P 1] ( p 1) at (0 ,0) ;
\ coordinate [ ponto , label = below left : P 2] ( p 2) at (3 ,0) ;
\ coordinate [ ponto , label = above : P 3] ( p 3) at (6 ,0) ;

Régis , 2011 http://latexbr.blogspot.com/ 15


\ coordinate [ controle , label = above : C 1] ( c 1) at (1 ,1) ;
\ coordinate [ controle , label = above : C 2] ( c 2) at (2 ,1) ;
\ coordinate [ controle , label = below : C 3] ( c 3) at (4 , -1) ;
\ coordinate [ controle , label = below : C 4] ( c 4) at (5 , -1) ;
% retas
\ draw [ blue ] ( p 1) -- ( c 1) ( p 2) -- ( c 2) ( p 2) -- ( c 3) ( p 3) -- ( c 4) ;
% duas curvas bezier
\ draw ( p 1) .. controls ( c 1) and ( c 2) .. ( p 2)
.. controls ( c 3) and ( c 4) .. ( p 3) ;
\ end { tikzpicture }

Exemplo de três curvas


\draw (P1) .. controls (C1) and (C2) .. (P2)
.. controls (C3) and (C4) .. (P3)
.. controls (C5) and (C6) .. (P4);

C1 C2 C5 C6

P1 P2 P3 P4

C3 C4 resultado final

Figura 18: Três curvas Bézier.

\ begin { tikzpicture }
\ tikzset { >= latex ,
ponto /. style ={ draw , fill = blue , rectangle , scale =.5} ,
controle /. style ={ draw , blue , circle , scale =.5}
}
% grade
\ draw [ color = lightgray , dashed ] (0 , -2) grid (9 ,2) ;
% coordenadas
\ coordinate [ ponto , label = below : P 1] ( p 1) at (0 ,0) ;
\ coordinate [ ponto , label = below left : P 2] ( p 2) at (3 ,0) ;
\ coordinate [ ponto , label = below right : P 3] ( p 3) at (6 ,0) ;
\ coordinate [ ponto , label = below : P 4] ( p 4) at (9 ,0) ;
\ coordinate [ controle , label = above : C 1] ( c 1) at (1 ,1) ;
\ coordinate [ controle , label = above : C 2] ( c 2) at (2 ,1) ;
\ coordinate [ controle , label = below : C 3] ( c 3) at (4 , -1) ;
\ coordinate [ controle , label = below : C 4] ( c 4) at (5 , -1) ;
\ coordinate [ controle , label = above : C 5] ( c 5) at (7 ,1) ;
\ coordinate [ controle , label = above : C 6] ( c 6) at (8 ,1) ;
% retas
\ draw [ blue ] ( p 1) -- ( c 1) ( p 2) -- ( c 2) ( p 2) -- ( c 3) ( p 3) -- ( c 4) ( p 3) -- ( c 5)
( p 4) -- ( c 6) ;
% tres curvas bezier
\ draw ( p 1) .. controls ( c 1) and ( c 2) .. ( p 2)
.. controls ( c 3) and ( c 4) .. ( p 3)
.. controls ( c 5) and ( c 6) .. ( p 4) ;
\ end { tikzpicture }

Régis , 2011 http://latexbr.blogspot.com/ 16


Dica para desenhar curvas Bézier
Uma boa dica para desenhar curvas Bézier é traçando primeiro as retas com os quatro pontos da
curva junto com uma grade, a partir daı́ teremos uma noção de como será a curva.

P2 P2

C2 C2

C1 C1

P1 P1
resultado final

Figura 19: Exemplo

\ begin { tikzpicture }
\ tikzset { >= latex ,
ponto /. style ={ draw , fill = blue , rectangle , scale =.5} ,
controle /. style ={ draw , blue , circle , scale =.5}
}
% grade
\ draw [ color = lightgray , dashed ] (0 ,0) grid (2 ,4) ;
% coordenadas
\ coordinate [ ponto , label = below : P 1] ( p 1) at (1 ,0) ;
\ coordinate [ ponto , label = above : P 2] ( p 2) at (1 ,4) ;
\ coordinate [ controle , label = left : C 1] ( c 1) at (0 ,1) ;
\ coordinate [ controle , label = left : C 2] ( c 2) at (0 ,3) ;
% retas
\ draw [ red , dashed ] ( p 1) -- ( c 1) -- ( c 2) -- ( p 2) ;
% bezier
\ draw ( p 1) .. controls ( c 1) and ( c 2) .. ( p 2) ;
\ end { tikzpicture }

Régis , 2011 http://latexbr.blogspot.com/ 17


Vejamos agora mais alguns exemplos de curvas.

P3 P3

C4 C4

C3 C3
P2 P2

C2 C2

C1 C1

P1 P1
resultado final

Figura 20: Exemplo

\ begin { tikzpicture }
\ tikzset { >= latex ,
ponto /. style ={ draw , fill = blue , rectangle , scale =.5} ,
controle /. style ={ draw , blue , circle , scale =.5}
}
% grade
\ draw [ color = lightgray , dashed ] ( -2 ,0) grid (2 ,6) ;
% coordenadas
\ coordinate [ ponto , label = below : P 1] ( p 1) at (0 ,0) ;
\ coordinate [ ponto , label = above right : P 2] ( p 2) at (0 ,3) ;
\ coordinate [ ponto , label = above : P 3] ( p 3) at (0 ,6) ;
\ coordinate [ controle , label = right : C 1] ( c 1) at (1 ,1) ;
\ coordinate [ controle , label = right : C 2] ( c 2) at (1 ,2) ;
\ coordinate [ controle , label = left : C 3] ( c 3) at ( -1 ,4) ;
\ coordinate [ controle , label = left : C 4] ( c 4) at ( -1 ,5) ;
% retas
\ draw [ red , dashed ] ( p 1) -- ( c 1) -- ( c 2) -- ( p 2) -- ( c 3) -- ( c 4) -- ( p 3) ;
% bezier
\ draw ( p 1) .. controls ( c 1) and ( c 2) .. ( p 2)
.. controls ( c 3) and ( c 4) .. ( p 3) ;
\ end { tikzpicture }

Régis , 2011 http://latexbr.blogspot.com/ 18


C1

P2
P1
C2 resultado final

Figura 21: Exemplo

\ begin { tikzpicture }
\ tikzset { >= latex ,
ponto /. style ={ draw , fill = blue , rectangle , scale =.5} ,
controle /. style ={ draw , blue , circle , scale =.5}
}
% grade
\ draw [ color = lightgray , dashed ] (0 , -1) grid (4 ,2) ;
% coordenadas
\ coordinate [ ponto , label = below : P 1] ( p 1) at (0 ,0) ;
\ coordinate [ ponto , label = above : P 2] ( p 2) at (4 ,0) ;
\ coordinate [ controle , label = above : C 1] ( c 1) at (2 ,2) ;
\ coordinate [ controle , label = below : C 2] ( c 2) at (1 , -.5) ;
% retas
\ draw [ blue ] ( p 1) -- ( c 1) ( p 2) -- ( c 2) ;
% bezier
\ draw ( p 1) .. controls ( c 1) and ( c 2) .. ( p 2) ;
\ end { tikzpicture }

Régis , 2011 http://latexbr.blogspot.com/ 19


P2

C2

C1
P1
resultado final

Figura 22: Exemplo

\ begin { tikzpicture }
\ tikzset { >= latex ,
ponto /. style ={ draw , fill = blue , rectangle , scale =.5} ,
controle /. style ={ draw , blue , circle , scale =.5}
}
% grade
\ draw [ color = lightgray , dashed ] (0 ,0) grid (2 ,3) ;
% coordenadas
\ coordinate [ ponto , label = below : P 1] ( p 1) at (0 ,0) ;
\ coordinate [ ponto , label = above : P 2] ( p 2) at (0 ,3) ;
\ coordinate [ controle , label = above : C 1] ( c 1) at (2 ,0) ;
\ coordinate [ controle , label = below : C 2] ( c 2) at (0 ,2) ;
% retas
\ draw [ blue ] ( p 1) -- ( c 1) ( p 2) -- ( c 2) ;
% bezier
\ draw ( p 1) .. controls ( c 1) and ( c 2) .. ( p 2) ;
\ end { tikzpicture }

Régis , 2011 http://latexbr.blogspot.com/ 20


Veja também uma comparação do carro desenhado anteriormente, só que agora desenhado com
curvas Bézier, no caso tivemos que inserir mais pontos de controle.

P1

P1

Figura 23: Carro desenhado com smooth (à esquerda) e com Bézier (à direita).

Baixe o código aqui.


E por fim mais alguns exemplos de figuras conhecidas. As vezes torna-se necessário uma alteração
na escala do desenho.

Figura 24: Letra B

Baixe o código aqui.

Figura 25: Gota d’água

\ begin { tikzpicture }[ scale =.02]


\ draw [ green , dashed ] (0 ,250) - -(0 ,175) - -( -65 ,130) - -( -65 ,75) - -( -65 ,20) - -( -30 ,0)
- -(0 ,0) - -(30 ,0) - -(65 ,20) - -(65 ,75) - -(65 ,130) - -(0 ,175) - -(0 ,250) ;
\ draw (0 ,250) .. controls (0 ,175) and ( -65 ,130) .. ( -65 ,75)
.. controls ( -65 ,20) and ( -30 ,0) .. (0 ,0)
.. controls (30 ,0) and (65 ,20) ..(65 ,75)
.. controls (65 ,130) and (0 ,175) .. (0 ,250) -- cycle ;
\ end { tikzpicture }

Régis , 2011 http://latexbr.blogspot.com/ 21


P1

Figura 26: Garrafa

\ begin { tikzpicture }[ scale =.5]


\ draw ( -1.7 ,0) .. controls ( -1 , -.25) and (1 , -.25) .. (1.7 ,0)
.. controls (1.8 ,0) and (2 ,.1) .. (2 ,.3)
-- (2 ,9)
.. controls (2 ,10.2) and (.8 ,10.5) .. (.8 ,11.5)
-- (.8 ,15)
.. controls (.5 ,15.25) and ( -.5 ,15.25) .. ( -.8 ,15)
-- ( -.8 ,11.5)
.. controls ( -.8 ,10.5) and ( -2 ,10.2) .. ( -2 ,9)
-- ( -2 ,.3)
.. controls ( -2 ,.1) and ( -1.8 ,0) .. ( -1.7 ,0) ;
\ end { tikzpicture }

Régis , 2011 http://latexbr.blogspot.com/ 22


Figura 27: Taça

Nesta figura eu escolhi usar uma reflexão com o ambiente scope.


\ begin { tikzpicture }
% grade
\ draw [ lightgray , opacity =.5 , xstep =.1 , ystep =.1] (0 ,0) grid (2 ,9) ;
% eixo de simetria
\ draw [ red ] (0 ,0) -- ++(0 ,9) ;
% taca
\ draw (0 ,0) -- (1.4 ,0)
.. controls (1.4 ,0) and (1.9 ,0) .. (1.9 ,.2)
.. controls (1.9 ,.3) and (1.6 ,.2) .. (1.5 ,.2)
.. controls (1.3 ,.2) and (.2 ,.7) .. (.2 ,1.1)
-- (.2 ,3.5)
.. controls (1 ,4) and (2.3 ,5.0) .. (1.5 ,8.3)
-- (0 ,8.3) ;
\ begin { scope }[ x = -1 cm ] % -1 provoca a reflexao da figura em relacao ao eixo y .
\ draw (0 ,0) -- (1.4 ,0)
.. controls (1.4 ,0) and (1.9 ,0) .. (1.9 ,.2)
.. controls (1.9 ,.3) and (1.6 ,.2) .. (1.5 ,.2)
.. controls (1.3 ,.2) and (.2 ,.7) .. (.2 ,1.1)
-- (.2 ,3.5)
.. controls (1 ,4) and (2.3 ,5.0) .. (1.5 ,8.3)
-- (0 ,8.3) ;
\ end { scope }
\ end { tikzpicture }

Régis , 2011 http://latexbr.blogspot.com/ 23


Figura 28: Android

\ definecolor { verde }{ RGB }{164 ,202 ,57}


\ begin { tikzpicture }
% grade
\ draw [ lightgray , dashed ] ( -5 ,0) grid (5 ,11) ;
% eixo
\ draw [ red ] (0 ,0) -- (0 ,11) ;
% corpo
\ fill [ verde ] ( -.5 ,2.1) -- (.5 ,2.1) -- (.5 ,.5) arc (180:360:6.5 mm )
-- (1.8 ,2.1) -- (2.5 ,2.1) arc (270:360:5 mm )
-- (3 ,7.3) -- ( -3 ,7.3) -- ( -3 ,2.6) arc (180:270:5 mm )
-- ( -1.8 ,2.1) -- ( -1.8 ,.5) arc (180:360:6.5 mm ) -- cycle ;
% bracos
\ fill [ verde , rounded corners =6 mm ] (3.35 ,3.2) rectangle ++(1.4 ,4.2) ;
\ fill [ verde , rounded corners =6 mm ] ( -3.35 ,3.2) rectangle ++( -1.4 ,4.2) ;
% cabeca
\ fill [ verde ] ( -3 ,7.5) -- (3 ,7.5) arc (0:180:3) -- cycle ;
% olhos
\ fill [ white ] (1.4 ,8.8) circle (2 mm ) ;
\ fill [ white ] ( -1.4 ,8.8) circle (2 mm ) ;
% orelhas
\ begin { scope }[ xshift =1.4 cm , yshift =10.1 cm ]
\ begin { scope }[ rotate = -35]
\ fill [ verde , rounded corners =0.45 mm ] (0 ,0) rectangle ++(.1 ,1) ;
\ end { scope }
\ end { scope }
\ begin { scope }[ xshift = -1.4 cm , yshift =10.1 cm ]
\ begin { scope }[ rotate =35]
\ fill [ verde , rounded corners =0.45 mm ] (0 ,0) rectangle ++(.1 ,1) ;
\ end { scope }
\ end { scope }
\ end { tikzpicture }

Régis , 2011 http://latexbr.blogspot.com/ 24


Figura 29: Baleia Azul

\ begin { tikzpicture }
\ fill [ cyan ] (0 ,0) .. controls (3 ,0) and (8 , -5) .. (10 ,0)
.. controls (9 , -.5) and (8.5 ,.5) .. (8 ,0)
.. controls (8 ,.4) and (9.5 ,.3) .. (10 ,.2)
.. controls (8 ,3) and (0 ,2) .. ( -1 ,1.5)
.. controls ( -3 ,.7) and ( -2 ,0) .. ( -4 , -1)
.. controls ( -4 , -1) and ( -2 , -2) .. (0 ,0) ;
\ fill [ cyan ] (0 ,1.7) .. controls ( -1 ,3) and ( -2 ,3.5) .. ( -3 ,3.5)
.. controls ( -2.5 ,3) and ( -2.2 ,2) .. ( -1.5 ,1.2) ;
\ fill (8 ,.8) circle (1 mm ) ;
\ end { tikzpicture }

Preserve a natureza
Figura 30: Folha

\ begin { tikzpicture }[ x =2 pt , y =2 pt ]
\ fill [ green ](45.95 ,48.67) .. controls (45.95 ,48.67) and (46.45 ,13.05)
..(34.32 ,7.12)
.. controls (22.09 ,1.15) and (2.76 ,7.9) .. (12.04 ,27)
.. controls (18.9 ,41.13) and (38.33 ,32) .. (45.95 ,48.67) -- cycle ;
\ draw [ green !75! black , line width =2 pt ] (6.82 ,5.22) .. controls (9 ,5) and
(35.12 ,14.85) .. (41.95 ,36.7) ;
\ node at (20 ,0) {\ Large Preserve a natureza };
\ end { tikzpicture }

Veja três videos no youtube: bezier01, bezier02 e drawing android in LaTeX with KTikz.
Veja também o tópico Desenhando no TikZ com imagem de referência, que é uma continuação
deste tópico.

Régis , 2011 http://latexbr.blogspot.com/ 25

Das könnte Ihnen auch gefallen