Füllen einer umrandeten Fläche in Tikz

Antwort erstellen


Diese Frage dient dazu, das automatisierte Versenden von Formularen durch Spam-Bots zu verhindern.
Smilies
:D :) :( :o :shock: :? 8) :lol: :-x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen:

BBCode ist eingeschaltet
[img] ist eingeschaltet
[flash] ist ausgeschaltet
[url] ist eingeschaltet
Smilies sind eingeschaltet

Die letzten Beiträge des Themas

Ich habe die Datenschutzerklärung gelesen und bin damit einverstanden.

   

Wenn du eine Datei oder mehrere Dateien anhängen möchtest, gib die Details unten ein.

Ansicht erweitern Die letzten Beiträge des Themas: Füllen einer umrandeten Fläche in Tikz

Re: Füllen einer umrandeten Fläche in Tikz

von Stefan Kottwitz » Do 23. Nov 2023, 11:11

Besser neuen Thread, richtig. Ist günstiger weil es auch andere TikZ-Freunde gibt, die frische Threads lesen, und spätere Fragen in älteren/längeren nicht bemerken bzw. nicht durcharbeiten um die Vorgeschichte zu verstehen.

So ein lauffähiges Minimalbeispiel wie hier in Deinem ersten Beitrag ist schonmal super!

Stefan

Re: Füllen einer umrandeten Fläche in Tikz

von Patrick1990 » Do 23. Nov 2023, 10:55

Vielen Dank! So ist es perfekt.
Hast du auch eine Idee zum Spiegeln und Vervielfältigen? Oder besser dann einen neuen Thread eröffnen?

Re: Füllen einer umrandeten Fläche in Tikz

von Stefan Kottwitz » Do 23. Nov 2023, 10:32

Hallo Patrick,

ich hatte die 4 übersprungen, hab das nun ins zweite Füllen mit -- (c4) eingefügt, das kannst Du nun oben sehen.

Clippen ist vielleicht nicht ganz einfach zu lernen, ich hab zu einem Kapitel in meinem Buch, wo das erklärt wird, ein paar Beispiele online gestellt: tikz.org/chapter-07

Stefan

Re: Füllen einer umrandeten Fläche in Tikz

von Patrick1990 » Do 23. Nov 2023, 10:10

Hallo Stefan,
danke für deinen Vorschlag.

Was ist mit der Koordinate 4? Da wird irgendwie nicht richtig gefüllt.
Ich habe gestern schon probiert, jedoch bin ich bisher noch nicht mit dem Clip klar gekommen.

Re: Füllen einer umrandeten Fläche in Tikz

von Stefan Kottwitz » Mi 22. Nov 2023, 15:11

Hi Patrick,

das kannst Du mit \clip beschnitten füllen. Bei "Doppelring" mit der "even odd rule" zum Bestimmen des Inneren von Pfaden. Ich mach mal in 2 Teilen.
\begin{scope}[even odd rule]
  \clip circle(\do/2)  circle(\drue/2)
        circle(\dzk/2) circle(\di/2);
  \fill[orange, opacity=0.5] (c2) -- (c3) -- (c4) -- (c5)
    -- (c6) -- ($(c6)!1.2!(c7)$) -- ($(c8)!-0.2!(c1)$) -- (c1);
\end{scope}
\clip circle(\drue/2)  circle(\dzk/2);
\fill[orange, opacity=0.5] (c1) -- (c2) -- (c3)
  -- (c5) -- (c5) -- (c8);
Hier habe ich mit der calc-Syntax die Linien etwas verlängert, um über den Kreis hinaus zu kommen.

Komplettbeispiel:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{fpu, calc, angles, intersections} 
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\newcommand{\radiusOHL}[3]{
\path 
(#1)coordinate(M)% Mittelpunkt 
(#2)coordinate(A)% Anfangskoordinate 
(#3)coordinate(B)% Endkoordinate 
; 
\path 
let 
\p1=(M), \p2=(A), 
\n1={veclen({\x2-\x1},{\y2-\y1})} 
in 
pic[draw=black,angle radius=\n1]{angle=A--M--B} ; 
}


\begin{document}
\begin{tikzpicture}[even odd rule]
\def\N{12}
\def\rot{90-360/\N}
\def\rotb{90}
\def\bzhs{0.3}
\def\nutoeffnung{0.8}
\def\do{10}
\def\di{7}
\def\hzhs{0.4}
\def\hrues{0.3}

\def\hzks{0.1}

%Durchmesser Zahnkopf innen
\pgfmathsetmacro\dzk{\di+\hzks*(\do-\di)};
\pgfmathsetmacro\drue{\do-\hrues*(\do-\di)};
\pgfmathsetmacro\dzhu{\do-(\hrues+\hzhs)*(\do-\di)};

% Hilfslinien
\draw[color=gray,dashed, name path=DAS] (0,0)++(\rot:\do/2) arc(\rot:\rot+2*360/\N:\do/2) node {\tiny DAS};
\draw[color=gray,dashed, name path=DIS] (0,0)++(\rot:\di/2) arc(\rot:\rot+2*360/\N:\di/2) node {\tiny DIS};
\draw[color=gray,dashed, name path=DRUE] (0,0)++(\rot:\drue/2) arc(\rot:\rot+2*360/\N:\drue/2) node {\tiny DRUE};
\draw[color=gray,dashed, name path=DZK] (0,0)++(\rot:\dzk/2) arc(\rot:\rot+2*360/\N:\dzk/2) node {\tiny DZK};
\draw[color=gray,dashed,name path=GL] (0,0) -- (0, \do/2) node[above] {\tiny GL};
\draw[color=gray,dashed,name path=GZ] (0,0) -- ({\do/2*sin(\nutoeffnung*360/(2*\N))}, {\do/2*cos(\nutoeffnung*360/(2*\N))}) node[above] {\tiny GZ};
\draw[color=gray,dashed,name path=GR] (0,0) -- ({\do/2*sin(360/(2*\N))}, {\do/2*cos(360/(2*\N))}) node[above] {\tiny GR};

% Schnittpunkte & Koordinaten
\path[name intersections={of=GL and DIS}](intersection-1) coordinate (c1) node {\tiny 1};  
\path[name intersections={of=GZ and DIS}](intersection-1) coordinate (c2) node {\tiny 2};  
\path[name intersections={of=GZ and DZK}](intersection-1) coordinate (c3) node {\tiny 3};  
\pgfgetlastxy{\xa}{\ya};
\pgfmathsetmacro\bzh{2*\bzhs*\xa};
\path ({\bzh/2 pt},\dzhu/2) coordinate (c4) node{\tiny 4} -- ({\bzh/2 pt},\drue/2) coordinate (c5) node{\tiny 5};
\path[name intersections={of=GR and DRUE}](intersection-1) coordinate (c6) node {\tiny 6};  
\path[name intersections={of=GR and DAS}] (intersection-1) coordinate (c7) node {\tiny 7};
\path[name intersections={of=GL and DAS}](intersection-1) coordinate (c8) node {\tiny 8};  

\begin{scope}[even odd rule]
  \clip circle(\do/2)  circle(\drue/2)
        circle(\dzk/2) circle(\di/2);
  \fill[orange, opacity=0.5] (c2) -- (c3) -- (c4) -- (c5)
    -- (c6) -- ($(c6)!1.2!(c7)$) -- ($(c8)!-0.2!(c1)$) -- (c1);
\end{scope}
\clip circle(\drue/2)  circle(\dzk/2);
\fill[orange, opacity=0.5] (c1) -- (c2) -- (c3)
  -- (c4) -- (c5) -- (c5) -- (c8);

\end{tikzpicture}
\end{document}
fuellen.png
fuellen.png (65.79 KiB) 1118 mal betrachtet
Stefan

Füllen einer umrandeten Fläche in Tikz

von Patrick1990 » Mi 22. Nov 2023, 14:19

Hallo,
ich suche nach einer Möglichkeit die umrandete Fläche grau einzufärben. Ich hatte zunächst mit fillbetween experimentiert, jedoch übersteigt das meine Fähigkeiten.
Hab ihr eine Idee, wie ich diese Fläche einfärben kann?
Zudem müsse ich sie dann im Anschluss noch Spiegeln an der vertikalen Achse und n mal um den Ursprung drehen.

Hier ein Minimalbeispiel:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{fpu, calc, angles, intersections} 
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\newcommand{\radiusOHL}[3]{
\path 
(#1)coordinate(M)% Mittelpunkt 
(#2)coordinate(A)% Anfangskoordinate 
(#3)coordinate(B)% Endkoordinate 
; 
\path 
let 
\p1=(M), \p2=(A), 
\n1={veclen({\x2-\x1},{\y2-\y1})} 
in 
pic[draw=black,angle radius=\n1]{angle=A--M--B} ; 
}


\begin{document}
\begin{tikzpicture}
\def\N{12}
\def\rot{90-360/\N}
\def\rotb{90}
\def\bzhs{0.3}
\def\nutoeffnung{0.8}
\def\do{10}
\def\di{7}
\def\hzhs{0.4}
\def\hrues{0.3}

\def\hzks{0.1}

%Durchmesser Zahnkopf innen
\pgfmathsetmacro\dzk{\di+\hzks*(\do-\di)};
\pgfmathsetmacro\drue{\do-\hrues*(\do-\di)};
\pgfmathsetmacro\dzhu{\do-(\hrues+\hzhs)*(\do-\di)};

% Hilfslinien
\draw[color=gray,dashed, name path=DAS] (0,0)++(\rot:\do/2) arc(\rot:\rot+2*360/\N:\do/2) node {\tiny DAS};
\draw[color=gray,dashed, name path=DIS] (0,0)++(\rot:\di/2) arc(\rot:\rot+2*360/\N:\di/2) node {\tiny DIS};
\draw[color=gray,dashed, name path=DRUE] (0,0)++(\rot:\drue/2) arc(\rot:\rot+2*360/\N:\drue/2) node {\tiny DRUE};
\draw[color=gray,dashed, name path=DZK] (0,0)++(\rot:\dzk/2) arc(\rot:\rot+2*360/\N:\dzk/2) node {\tiny DZK};
\draw[color=gray,dashed,name path=GL] (0,0) -- (0, \do/2) node[above] {\tiny GL};
\draw[color=gray,dashed,name path=GZ] (0,0) -- ({\do/2*sin(\nutoeffnung*360/(2*\N))}, {\do/2*cos(\nutoeffnung*360/(2*\N))}) node[above] {\tiny GZ};
\draw[color=gray,dashed,name path=GR] (0,0) -- ({\do/2*sin(360/(2*\N))}, {\do/2*cos(360/(2*\N))}) node[above] {\tiny GR};

% Schnittpunkte & Koordinaten
\path[name intersections={of=GL and DIS}](intersection-1) coordinate (c1) node {\tiny 1};  
\path[name intersections={of=GZ and DIS}](intersection-1) coordinate (c2) node {\tiny 2};  
\path[name intersections={of=GZ and DZK}](intersection-1) coordinate (c3) node {\tiny 3};  
\pgfgetlastxy{\xa}{\ya};
\pgfmathsetmacro\bzh{2*\bzhs*\xa};
\path ({\bzh/2 pt},\dzhu/2) coordinate (c4) node{\tiny 4} -- ({\bzh/2 pt},\drue/2) coordinate (c5) node{\tiny 5};
\path[name intersections={of=GR and DRUE}](intersection-1) coordinate (c6) node {\tiny 6};  
\path[name intersections={of=GR and DAS}] (intersection-1) coordinate (c7) node {\tiny 7};
\path[name intersections={of=GL and DAS}](intersection-1) coordinate (c8) node {\tiny 8};  

% Kontur
\radiusOHL{{0,0}}{c2}{c1};
\draw (c2) -- (c3);
\draw (c3) -- (c4);
\draw (c4) -- (c5);
\radiusOHL{{0,0}}{c6}{c5};
\draw (c6) -- (c7);
\radiusOHL{{0,0}}{c7}{c8};
\draw (c8) -- (c1);

\end{tikzpicture}
    

\end{document}

Nach oben