Re: Tikz – Convex hull

#87474
Up
0
Down
::

DirkPitt” post=86996

[quote=”DirkPitt” post=86949]Grazie per l’aiuto 🙂 Onestamente speravo fosse più semplice. Forse, a questo punto, mi conviene disegnare il bordo dell’insieme “attaccando” dei pezzi di funzioni note in modo che la curva risultante sia continua e chiusa, no? Se creo un paio di axis diciamo con dominio 0

Secondo me quel sistema è addirittura più complicato del mio. Appena ho tempo approfondisco.

Ciao
Claudio

Ah ok grazie 🙂 Spero, però, che tu abbia già inteso che la mia è la voce dell’ignoranza in materia, quindi non l ho proposto perchè certo che fosse più facile 😀

Ciao![/quote]
Perdona il ritardo per prima cosa 🙂

Dunque, la soluzione che avevo in mente non è proprio perfetta; credo che sarebbe meglio posizionare i nodi come dicevo, ma poi tracciare a mano le curve come in Highlighting some nodes of a TikZ binomial tree.

Con hobby, invece, mi ero scordato che l’algoritmo automatico traccia dei control points a metà di ogni coppia di nodi e nel tuo caso non va sempre bene. Ecco un esempio di cosa avevo in mente: `
\documentclass[a4paper,12pt]{article}

\usepackage{tikz}
\usetikzlibrary{calc,decorations.markings,hobby}

% versione TeXLive 2013 compatibile 2012:
% http://tex.stackexchange.com/questions/121286/error-with-hobbyconvexpath

\newcommand{\hobbyconvexpath}[2]{
[
create hobbyhullnodes/.code={
\global\edef\namelist{#1}
\foreach [count=\counter] \nodename in \namelist {
\global\edef\numberofnodes{\counter}
\node at (\nodename)
[draw=none,name=hobbyhullnode\counter] {};
}
\node at (hobbyhullnode\numberofnodes)
[name=hobbyhullnode0,draw=none] {};
\pgfmathtruncatemacro\lastnumber{\numberofnodes+1}
\node at (hobbyhullnode1)
[name=hobbyhullnode\lastnumber,draw=none] {};
},
create hobbyhullnodes
]
($(hobbyhullnode1)!#2!-90:(hobbyhullnode0)$)
\pgfextra{
\gdef\hullpath{}
\foreach [
evaluate=\currentnode as \previousnode using int(\currentnode-1),
evaluate=\currentnode as \nextnode using int(\currentnode+1)
] \currentnode in {1,…,\numberofnodes} {
\ifnum\currentnode=1\relax
\xdef\hullpath{([closed=true]$(hobbyhullnode\currentnode)!#2!180:(hobbyhullnode\previousnode)$)
..($(hobbyhullnode\nextnode)!0.5!(hobbyhullnode\currentnode)$)}
\else
\xdef\hullpath{\hullpath
..($(hobbyhullnode\currentnode)!#2!180:(hobbyhullnode\previousnode)$)
..($(hobbyhullnode\nextnode)!0.5!(hobbyhullnode\currentnode)$)}
\fi
\ifx\currentnode\numberofnodes
\else
\xdef\hullpath{\hullpath
..($(hobbyhullnode\nextnode)!#2!-90:(hobbyhullnode\currentnode)$)}
\fi
}
}
\hullpath
}

\tikzset{insert node/.style args={#1 at #2}{
postaction=decorate,
decoration={
markings,
mark= at position #2
with
{
#1
}
}
}
}

\begin{document}

\begin{tikzpicture}[use Hobby shortcut
]

\draw[-stealth] (-5,0)–(5,0);
\draw[-stealth] (0,-5)–(0,5);

% S2
\node (a) at (-0.75,-0.5) {};
\node (b) at (-4,-1) {};
\node (c) at (-4.75,1.5) {};
\node (d) at (-2.45,3) {};

\draw[fill=gray!20,insert node={
\node[coordinate](first-a){};} at 0.23,
insert node={
\node[coordinate](first-b){};} at 0.68
]
\hobbyconvexpath{a,b,c,d}{12.5pt};

% S1
\node (e) at (2,-3) {};
\node (f) at (1,1) {};
\node (g) at (2.5,1.5) {};
\node (h) at (4.25,0.5) {};

\draw[fill=gray!20,insert node={
\node[coordinate](second-a){};} at 0.01,
insert node={
\node[draw](second-b){};} at 0.475,
insert node={
\node[coordinate](second-c){};} at 0.7,
insert node={
\node[coordinate](second-d){b};} at 0.95,
]
\hobbyconvexpath{e,f,g,h}{12.5pt};

\draw(first-a)–(second-a);
\draw(first-b)–(second-b);
\draw(second-c)–(second-d);

\end{tikzpicture}
\end{document}
` Quello che invece dovrebbe tornerti utile anche nel caso di definizione a mano del segmento è il comodissimo (o per lo meno io lo reputo tale) [tt]insert node[/tt].

Ciao
Claudio

Go to top