curvas no tikz
TRANSCRIPT
Curvas no TikZ
Neste topico 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, bastadigitar \begin{tikzpicture} e \end{tikzpicture} e comecar seu desenho.
Rounded corners
Antes de iniciarmos nosso tutorial sobre curvas vejamos uma opcao muito util: rounded corners.Esta opcao permite que os cantos da figura sejam arredondados a partir de um valor numerico.
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 =5mm] (12,0) -- ++(5 ,0) -- ++(-2,2) -- ++(-3,0) -- cycle;
\end{tikzpicture}
Figura 2: rounded corners em tres raios diferentes.
\begin{tikzpicture}
\draw (0,0) rectangle ++(2 ,2);
\draw[rounded corners] (3,0) rectangle ++(2 ,2);
\draw[rounded corners =1cm] (6,0) rectangle ++(2 ,2);
\end{tikzpicture}
Regis , 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}
Regis , 2011 http://latexbr.blogspot.com/ 2
To
O operador To e usado para adicionar um caminho da coordenada anterior para a coordenadaseguinte. Quando voce escreve (A) to (B), uma linha e adicionada de A para B, exatamente comose voce tivesse escrito (A)--(B).
No entanto, se voce escrever (A) to[out=90,in=180] (B) uma curva e adicionada ao caminho,saindo do ponto A com um angulo de 90o e chegando no ponto B com um angulo de 180o (levandoem consideracao que o angulo 0 inicia-se do lado direito de um ponto fixo e percorre no sentido anti-horario). E claro que podemos digitar (0,0) to[out=90,in=180] (2,3). Os pontos A e B sao pontosnomeados que sao usados a partir do comando \coordinate.
Na terceira figura temos um exemplo saindo do ponto A a 45o e chegando em B a 135o.
A
B
A
B
A
B
90◦
180◦
45◦
135◦
Figura 3: Exemplos do operador to.
Veja o codigo:
\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}
Regis , 2011 http://latexbr.blogspot.com/ 3
Veja a seguir um desenho um pouco mais elaborado:
A
B C
D
E
FG
H
I
J
K
Figura 4: Mais um exemplo do operador to.
E o codigo:
\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}
Regis , 2011 http://latexbr.blogspot.com/ 4
Veja mais um exemplo com uma figura conhecida: arcos goticos.
Figura 5: Arcos goticos.
\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 tambem os exemplos Clusters of atoms e Beamer arrows.
Bend
Existem dois operadores: bend left e bend right. Ambos sao usados como opcao para o operadorto. O bend left funciona da seguinte forma: se voce digitar bend left=45, o resultado sera equivalentea out=45,in=135. Ou seja, out=<angulo>,in=180 - <angulo>. O bend right funciona de formacontraria.
A B C D E F
G
H
I
J
K
L
M
N
45◦ 90◦
bend left bend right bend left bend right
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);
Regis , 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.
Regis , 2011 http://latexbr.blogspot.com/ 6
Smooth
Esta opcao faz com que os pontos de uma curva sejam conectados por uma curva suave. Mas estaopcao so e usada com o operador plot e coordinates.
Um exemplo simples e:
\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 tambem a opcao 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 varias tensoesdiferentes.
A
B
C
D
E
F
G
tension=1.5
tension=1
tension=default
tension=0
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}
Regis , 2011 http://latexbr.blogspot.com/ 7
A seguir um outro exemplo com diferentes tensoes mas desta vez usando a opcao smooth cycle.Esta opcao fecha o ciclo de uma figura aberta transformando-a numa figura fechada.
A
B
C
D
E
F
G
H
I
J
K
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.25cm]
plot[tension =0.5] coordinates {(E) (F) (G) (H)};
\draw[smooth cycle ,yshift =-4.5cm]
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}
Regis , 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.
Regis , 2011 http://latexbr.blogspot.com/ 9
Comparacao entre out, in, bend e smooth
Veja um comparacao entre as curvas com o uso de out, in, bend e smooth.
bend right
out,in smooth
Figura 11: Comparacao entre out, in, bend e smooth
\begin{tikzpicture}
\tikzset{>=latex ,inner sep=0pt ,outer sep=2pt}
%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 (1pt);
\fill[blue] (1.75 ,.25) circle (1pt);
\fill[blue] (2,2) circle (1pt);
\end{tikzpicture}
Regis , 2011 http://latexbr.blogspot.com/ 10
Bezier - controls
O operador se chama controls. Bezier e um tipo de curva definida por pontos de controleque determinam sua curvatura. Podemos definir as curvas Bezier de duas maneiras: por coordenadaspolares 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 considereos pontos C1 e C2 como pontos de controle que definem a curvatura da curva. Suponha uma retasuporte passando por P1 e C1 e outra passando por P2 e C2. Essas retas tangenciam a curva emP1 e P2 definindo assim a curvatura da curva.
P1 P2
C1
C2
α
r1
β
r2
Curva Bezier
pontoinicial
pontofinal
ponto decontrole
ponto decontrole
reta tangente acurva em P1
reta tangente acurva em P2
raio
angulo
Figura 12: Curva Bezier definida por coordenadas polares.
A sintaxe para gerar uma curva Bezier usando coordenadas polares e a seguinte:
\draw (P1) .. controls +(α : r1) and +(β : r2) .. (P2);
onde P1 e o ponto inicial, P2 e o ponto final, α e β sao os angulos de inclinacao das retas tangentesa P1 e P2, respectivamente; e r1 e r2 e o comprimento de cada reta tangente, ou seja, a distancia deP1 a C1 e P2 a C2, respectivamente.
Regis , 2011 http://latexbr.blogspot.com/ 11
Exemplo com coordenadas polares
Veja o codigo mais simples para geracao da curva Bezier em coordenadas polares.
\begin{tikzpicture}
\draw (0,0) .. controls +(45:1) and +(60:2) .. (2,0);
\end{tikzpicture}
P1 P2
C1
C2
45◦ 60◦
resultado final
Figura 13: Exemplo de curva Bezier definida por coordenadas polares.
A seguir um codigo mais completo com o uso de coordenadas previamente definidas e estilos paravisualizacao dos pontos. Mas lembrando que, o codigo anterior e 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:P1] (p1) at (0,0);
\coordinate[ponto ,label=below:P2] (p2) at (2,0);
\coordinate[controle ,label=above:C1] (c1) at (45:1);
\coordinate (c2) at (60:2);
%coordenada necessaria para posicao correta do ponto cc2 para desenhar a reta
tangente.
%Nao eh obrigatorio.
\coordinate[controle ,,label=above:C2,xshift =4cm] (cc2) at (c2); %xshift com o
dobro da posicao do ponto.
%retas
\draw[blue] (p1) -- (c1) (p2) -- (cc2);
%bezier
\draw (p1) .. controls +(c1) and +(c2) .. (p2);
\end{tikzpicture}
Regis , 2011 http://latexbr.blogspot.com/ 12
Coordenadas Cartesianas
Atraves de coordenadas cartesianas os pontos P1, P2, C1 e C2 sao definidos pelo par ordenado (x, y).
x
y
0
P1 P2
C1 C2
Curva Bezier
pontoinicial ponto
final
pontos decontrole
Figura 14: Curva Bezier definida por coordenadas cartesianas.
A sintaxe para gerar uma curva Bezier usando coordenadas cartesianas e a seguinte:
\draw (P1) .. controls (C1) and (C2) .. (P2);
onde P1 e o ponto inicial, P2 e o ponto final, C1 e C2 sao os pontos de controle.
Exemplo com coordenadas cartesianas
Uma curva Bezier pode ser definida por um ou dois pontos de controle para cada trecho de curva.Veja o codigo mais simples para geracao da curva Bezier em coordenadas cartesianas, no caso, com
um ponto de controle.
\begin{tikzpicture}
\draw (0,0) .. controls (1,2) .. (4,0);
\end{tikzpicture}
P1 P2
C1
resultado final
Figura 15: Curva Bezier com um ponto de controle.
A seguir um codigo mais completo com o uso de coordenadas previamente definidas e estilos paravisualizacao dos pontos.
Regis , 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:P1] (p1) at (0,0);
\coordinate[ponto ,label=below:P2] (p2) at (4,0);
\coordinate[controle ,label=above:C1] (c1) at (1,2);
%retas
\draw[blue] (p1) -- (c1) -- (p2);
%bezier
\draw (p1) .. controls (c1) .. (p2);
\end{tikzpicture}
Se voce quiser as coordenadas sem os estilos basta dar uma simplificada no codigo anterior.
\begin{tikzpicture}
\coordinate (p1) at (0,0);
\coordinate (p2) at (4,0);
\coordinate (c1) at (1,2);
%bezier
\draw (p1) .. controls (c1) .. (p2);
\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}
P1 P2
C1 C2
resultado final
Figura 16: Curva Bezier 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);
Regis , 2011 http://latexbr.blogspot.com/ 14
%coordenadas
\coordinate[ponto ,label=below:P1] (p1) at (0,0);
\coordinate[ponto ,label=below:P2] (p2) at (4,0);
\coordinate[controle ,label=above:C1] (c1) at (1,2);
\coordinate[controle ,label=above:C2] (c2) at (2,2);
%retas
\draw[blue] (p1) -- (c1) (p2) -- (c2);
%bezier
\draw (p1) .. controls (c1) and (c2) .. (p2);
\end{tikzpicture}
E o codigo somente com as coordenadas:
\begin{tikzpicture}
\coordinate (p1) at (0,0);
\coordinate (p2) at (4,0);
\coordinate (c1) at (1,2);
\coordinate (c2) at (2,2);
%bezier
\draw (p1) .. controls (c1) and (c2) .. (p2);
\end{tikzpicture}
Exemplo de duas curvas
Daqui pra frente sempre usaremos coordenadas previamente definidas e estilos para visualizacaodos pontos.
Para fazer duas curvas basta inserir um novo controls. Assim, teremos:
\draw (P1) .. controls (C1) and (C2) .. (P2)
.. controls (C3) and (C4) .. (P3);
P1 P2
P3
C1 C2
C3 C4 resultado final
Figura 17: Duas curvas Bezier.
\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:P1] (p1) at (0,0);
\coordinate[ponto ,label=below left:P2] (p2) at (3,0);
\coordinate[ponto ,label=above:P3] (p3) at (6,0);
Regis , 2011 http://latexbr.blogspot.com/ 15
\coordinate[controle ,label=above:C1] (c1) at (1,1);
\coordinate[controle ,label=above:C2] (c2) at (2,1);
\coordinate[controle ,label=below:C3] (c3) at (4,-1);
\coordinate[controle ,label=below:C4] (c4) at (5,-1);
%retas
\draw[blue] (p1) -- (c1) (p2) -- (c2) (p2) -- (c3) (p3) -- (c4);
%duas curvas bezier
\draw (p1) .. controls (c1) and (c2) .. (p2)
.. controls (c3) and (c4) .. (p3);
\end{tikzpicture}
Exemplo de tres curvas
\draw (P1) .. controls (C1) and (C2) .. (P2)
.. controls (C3) and (C4) .. (P3)
.. controls (C5) and (C6) .. (P4);
P1 P2 P3 P4
C1 C2
C3 C4
C5 C6
resultado final
Figura 18: Tres curvas Bezier.
\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:P1] (p1) at (0,0);
\coordinate[ponto ,label=below left:P2] (p2) at (3,0);
\coordinate[ponto ,label=below right:P3] (p3) at (6,0);
\coordinate[ponto ,label=below:P4] (p4) at (9,0);
\coordinate[controle ,label=above:C1] (c1) at (1,1);
\coordinate[controle ,label=above:C2] (c2) at (2,1);
\coordinate[controle ,label=below:C3] (c3) at (4,-1);
\coordinate[controle ,label=below:C4] (c4) at (5,-1);
\coordinate[controle ,label=above:C5] (c5) at (7,1);
\coordinate[controle ,label=above:C6] (c6) at (8,1);
%retas
\draw[blue] (p1) -- (c1) (p2) -- (c2) (p2) -- (c3) (p3) -- (c4) (p3) -- (c5)
(p4) -- (c6);
%tres curvas bezier
\draw (p1) .. controls (c1) and (c2) .. (p2)
.. controls (c3) and (c4) .. (p3)
.. controls (c5) and (c6) .. (p4);
\end{tikzpicture}
Regis , 2011 http://latexbr.blogspot.com/ 16
Dica para desenhar curvas Bezier
Uma boa dica para desenhar curvas Bezier e tracando primeiro as retas com os quatro pontos dacurva junto com uma grade, a partir daı teremos uma nocao de como sera a curva.
P1
P2
C1
C2
P1
P2
C1
C2
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:P1] (p1) at (1,0);
\coordinate[ponto ,label=above:P2] (p2) at (1,4);
\coordinate[controle ,label=left:C1] (c1) at (0,1);
\coordinate[controle ,label=left:C2] (c2) at (0,3);
%retas
\draw[red ,dashed] (p1) -- (c1) -- (c2) -- (p2);
%bezier
\draw (p1) .. controls (c1) and (c2) .. (p2);
\end{tikzpicture}
Regis , 2011 http://latexbr.blogspot.com/ 17
Vejamos agora mais alguns exemplos de curvas.
P1
P2
P3
C1
C2
C3
C4
P1
P2
P3
C1
C2
C3
C4
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:P1] (p1) at (0,0);
\coordinate[ponto ,label=above right:P2] (p2) at (0,3);
\coordinate[ponto ,label=above:P3] (p3) at (0,6);
\coordinate[controle ,label=right:C1] (c1) at (1,1);
\coordinate[controle ,label=right:C2] (c2) at (1,2);
\coordinate[controle ,label=left:C3] (c3) at (-1,4);
\coordinate[controle ,label=left:C4] (c4) at (-1,5);
%retas
\draw[red ,dashed] (p1) -- (c1) -- (c2) -- (p2) -- (c3) -- (c4) -- (p3);
%bezier
\draw (p1) .. controls (c1) and (c2) .. (p2)
.. controls (c3) and (c4) .. (p3);
\end{tikzpicture}
Regis , 2011 http://latexbr.blogspot.com/ 18
P1
P2
C1
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:P1] (p1) at (0,0);
\coordinate[ponto ,label=above:P2] (p2) at (4,0);
\coordinate[controle ,label=above:C1] (c1) at (2,2);
\coordinate[controle ,label=below:C2] (c2) at (1,-.5);
%retas
\draw[blue] (p1) -- (c1) (p2) -- (c2);
%bezier
\draw (p1) .. controls (c1) and (c2) .. (p2);
\end{tikzpicture}
Regis , 2011 http://latexbr.blogspot.com/ 19
P1
P2
C1
C2
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:P1] (p1) at (0,0);
\coordinate[ponto ,label=above:P2] (p2) at (0,3);
\coordinate[controle ,label=above:C1] (c1) at (2,0);
\coordinate[controle ,label=below:C2] (c2) at (0,2);
%retas
\draw[blue] (p1) -- (c1) (p2) -- (c2);
%bezier
\draw (p1) .. controls (c1) and (c2) .. (p2);
\end{tikzpicture}
Regis , 2011 http://latexbr.blogspot.com/ 20
Veja tambem uma comparacao do carro desenhado anteriormente, so que agora desenhado comcurvas Bezier, no caso tivemos que inserir mais pontos de controle.
P1
P1
Figura 23: Carro desenhado com smooth (a esquerda) e com Bezier (a direita).
Baixe o codigo aqui.E por fim mais alguns exemplos de figuras conhecidas. As vezes torna-se necessario uma alteracao
na escala do desenho.
Figura 24: Letra B
Baixe o codigo aqui.
Figura 25: Gota d’agua
\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}
Regis , 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}
Regis , 2011 http://latexbr.blogspot.com/ 22
Figura 27: Taca
Nesta figura eu escolhi usar uma reflexao 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=-1cm]% -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}
Regis , 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 =6mm] (3.35 ,3.2) rectangle ++(1.4 ,4.2);
\fill[verde ,rounded corners =6mm] ( -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 (2mm);
\fill[white] ( -1.4 ,8.8) circle (2mm);
%orelhas
\begin{scope}[ xshift =1.4cm ,yshift =10.1cm]
\begin{scope}[ rotate =-35]
\fill[verde ,rounded corners =0.45mm] (0,0) rectangle ++(.1 ,1);
\end{scope}
\end{scope}
\begin{scope}[ xshift =-1.4cm ,yshift =10.1cm]
\begin{scope}[ rotate =35]
\fill[verde ,rounded corners =0.45mm] (0,0) rectangle ++(.1 ,1);
\end{scope}
\end{scope}
\end{tikzpicture}
Regis , 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 (1mm);
\end{tikzpicture}
Preserve a natureza
Figura 30: Folha
\begin{tikzpicture }[x=2pt ,y=2pt]
\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=2pt] (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 tres videos no youtube: bezier01, bezier02 e drawing android in LaTeX with KTikz.Veja tambem o topico Desenhando no TikZ com imagem de referencia, que e uma continuacao
deste topico.
Regis , 2011 http://latexbr.blogspot.com/ 25