TikZ
- How to create a dynamic fan in TikZ in LaTeX?by mathrm alpha on August 18, 2026 at 5:49 am
Although I've created a basic fan shape in TikZ, how do I make the center blade of the TikZ fan dynamic rotate? the value you enter determines exactly how fast the TikZ fan I created will spin. \documentclass{article} \usepackage{tikz} \usepackage[paperwidth=9cm, paperheight=9cm, margin=1.5cm]{geometry} \begin{document} \pagestyle{empty} \begin{figure}[htbp] \begin{tikzpicture} \filldraw[color=yellow!60, fill=orange!40, very thick](0,0) circle (3); \filldraw[color=yellow!60, fill=red!0, very thick](0,0) circle (2.5); \begin{scope}[rotate=0] \draw [line width=0.3cm] (0,0) -- (2,2); \draw [line width=0.3cm] (0,0) -- (0,3); \draw [line width=0.3cm] (0,0) -- (-2,2); \draw [line width=0.3cm] (0,0) -- (2,-2); \draw [line width=0.3cm] (0,0) -- (3,0); \draw [line width=0.3cm] (0,0) -- (-3,0); \draw [line width=0.3cm] (0,0) -- (0,-3); \draw [line width=0.3cm] (0,0) -- (-2,-2); \filldraw[orange] (0,0) circle (30pt) node[anchor=west]{}; \end{scope} \end{tikzpicture} \end{figure} \end{document}
- My goal is to approximate an arc length reparameterizationby Jasper on August 16, 2026 at 9:51 pm
My goal is to approximate an arc length reparameterization. The thick curve and the red curve should nearly coincide is the expected result. \documentclass{article} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \usepackage{mathtools} \usepackage{unicode-math} \tikzset{ declare function={ alpha(\t)=1/\t; dalpha(\t)=(alpha(\t+0.02)-alpha(\t-0.02))/0.04; length(\x,\y)=sqrt((\x)^2+(\y)^2); ldalpha(\t)=length(1,dalpha(\t)); } } \pgfmathdeclarefunction{riemannsumldalpha}{3}{% \pgfmathsetmacro{\count}{0}% \pgfmathsetmacro{\dx}{(#2-#1)/#3}% \pgfplotsinvokeforeach{1,...,#3} {% \pgfmathsetmacro{\count}{\count+ldalpha(#1+##1*\dx)*\dx}% }% \let\pgfmathresult\count% } \pgfmathdeclarefunction{inverseriemannsumldalpha}{4}{% \pgfmathsetmacro{\lo}{#2}% \pgfmathsetmacro{\hi}{#3}% \pgfplotsinvokeforeach{1,...,#4}{% \pgfmathsetmacro{\mid}{(\lo+\hi)/2}% \pgfmathsetmacro{\value}{riemannsumldalpha(0.25,\mid,#4)}% \pgfmathsetmacro{\test}{\value < #1}% \ifnum\test=1 \pgfmathsetmacro{\lo}{\mid}% \else \pgfmathsetmacro{\hi}{\mid}% \fi }% \pgfmathsetmacro{\pgfmathresult}{(\lo+\hi)/2}% } \tikzset{ declare function={ alphainverseriemannsumldalpha(\t,\s,\e,\sam)=alpha( inverseriemannsumldalpha(\t,\s,\e,\sam) ); } } \begin{document} Let \(\alpha(t)=1/t\). My goal is to approximate an arc length reparameterization. I believe that plotting the following composition will achieve this; \[\alpha\Biggl(\biggl(\int_{t_0}^t\lvert\alpha'(t)\rvert\,dt\biggr)^{-1}\Biggr).\] \begin{center} \begin{tikzpicture}[samples=5] % producing the expected result \draw[red] plot[domain=0.25:4] (\x,{alpha(\x)}); \draw[green] plot[domain=0.25:4] (\x,{dalpha(\x)}); \draw[blue] plot[domain=0.25:4] (\x,{ldalpha(\x)}); \draw[purple] plot[domain=0.25:4] (\x,{riemannsumldalpha(0.25,\x,7)}); \draw[yellow] plot[domain=0.25:4] (\x,{inverseriemannsumldalpha(\x,0.25,4,7)}); % not producing the expected result \draw[thick] plot[domain=0.25:4] (\x,{alphainverseriemannsumldalpha(\x,0.25,4,7)}); \end{tikzpicture} \end{center} \end{document}
- Triangle Nesting ( Similar to Sierpinski Triangles ) [duplicate]by Discrete on August 15, 2026 at 7:09 pm
Im curious to know if there is a more efficient way to have triangles repeat themselves in one another without needing to run the \draw command for each line of the triangle; similar to Sierpinski's triangles is essentially what it is but in a different way for nesting. So far i've been doing the \draw command as such \documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} [scale = 3] \draw[thick] (0,0) -- (2,0) -- (1,1.73205) -- cycle; \draw[thick] (0,0) -- (1,0.8) (2,0) -- (1,0.8) -- (1,1.73205) -- (1,0.8); \draw[thick] (1,0.8) -- (1.566667,0.769); \end{tikzpicture} \end{document} Ive provided an example above of what it should look like however I need to define what the colors mean and some rules it has. Meaning of Colors: Black = 1st Generation triangles, Blue = 2nd Generation triangles, and Red = 3rd Generation triangles as well each generation has a specific intersection where all the points meet ( for example black has a intersection in the middle where all points meet ) I should also say that each generation has its own "sub section" where the rule above applies to each sub section and these sub sections are divided by the lines of the previous generation. ( for example a 3rd generation sub section can have a different intersection than another 3rd generation sub section this is so each has one intersection which will for the sake of simplicity be set in the center for all generations) if you have any questions on this to better help me feel free to ask and I apologize if some of it seems confusing it is a rather "niche" section of discrete geometry relating to triangles and other two dimensional shapes ( side note i'd like this concept to be done with other two dimensional shapes as well so if theres a way to set the starting shape to say a circle or another shape that would be amazing; and it would follow the same rules I have revealed here).
- How to draw highly accurate, continuous pH titration curves with the tangent method in TikZ/pgfplots?by Natsu on August 15, 2026 at 5:28 pm
When attempting to plot pH-metric titration curves for weak/polyprotic acids and bases using piecewise Henderson-Hasselbalch approximations, sharp breaks and discontinuous artifacts often appear near equivalence points. Is there a robust, automated way in TikZ and pgfplots to plot continuous curves using exact charge and mass balance equations, while also supporting geometric constructions such as the tangent method (méthode des tangentes)?
- Plot a domain in 3D with TikZ for a triple integralby Sebastiano on April 20, 2026 at 9:59 pm
I have to solve this triple integral ∭ x y|z|³/(1+ (x²+y²)⁴) dx dy dz, with a domain T={(x, y, z) ∈ ℝ³: x ≤ 0, y ≥ 0, z² ≤ x²+y² ≤ 1}. Plotting with DESMOS 3D I see this: Actually I am not able to visualise this domain in my mind. It should be a cylinder enclosed by a double-sloped cone, but I can’t quite get the x ≤ 0, y ≥ 0 parameters right. I’ve created something but I would like my drawing (or a new one) to be intuitive with TikZ3D so that I can correctly draw this integral. My MWE: \documentclass[12pt]{article} \usepackage{tikz} \usepackage{tikz-3dplot} \tdplotsetmaincoords{60}{130} \begin{document} \begin{tikzpicture}[tdplot_main_coords, scale=3] % assi \draw[->] (0,0,0) -- (1.3,0,0) node[right]{$x$}; \draw[->] (0,0,0) -- (0,1.3,0) node[left]{$y$}; \draw[->] (0,0,0) -- (0,0,1.3) node[above]{$z$}; \foreach \t in {0,1,...,359}{ \pgfmathsetmacro{\ct}{cos(\t)} \pgfmathsetmacro{\st}{sin(\t)} \draw[blue!60, opacity=0.75] (0,0,0) -- plot[domain=0:1, samples=40] ({\x*\ct},{\x*\st},{\x}); \draw[red!60, opacity=0.75] (0,0,0) -- plot[domain=0:1, samples=40] ({\x*\ct},{\x*\st},{-\x}); } \draw[thick] plot[domain=0:360, samples=200] ({cos(\x)},{sin(\x)},1); \draw[thick] plot[domain=0:360, samples=200] ({cos(\x)},{sin(\x)},-1); \end{tikzpicture} \end{document}
- Partially dashed orthogonal projection of a straight line onto a planeby Mr.Price on February 11, 2025 at 7:23 pm
I have the following 3D plot in Tikz which represents plane, segment that intersects the plane and the orthogonal projection of that segment onto that plane: \documentclass[tikz, margin=2mm]{standalone} \usetikzlibrary{angles, quotes} \usepackage{amssymb} \usetikzlibrary {arrows.meta, shapes.geometric, trees, shapes, backgrounds,intersections, patterns,decorations.markings} \usepackage{pgfplots} \usepgfplotslibrary{units} \usetikzlibrary{positioning} \usepackage{amsmath, amssymb} \usepackage{siunitx} \usepackage{tikz-3dplot} \usepackage[dvipsnames]{xcolor} \usepackage{polski} \usepackage{tkz-euclide} \begin{document} \tikzset{background grid/.append style={step=.5cm, ultra thin, dashed, gray!50}} \begin{tikzpicture}[show background grid, >=Stealth] \begin{scope}[canvas is xz plane at y=0] \path[] (0,0) coordinate (A) (4,0) coordinate (B) (4,4) coordinate (C) (0,4) coordinate (D) (2,2) coordinate (Q) (5,0) coordinate (P') ; \end{scope} \begin{scope}[canvas is xz plane at y=3] \path[] (5,2) coordinate (P); \end{scope} \tkzDrawPolygon[thick, fill=Dandelion!50, fill opacity=0.8](A,B,C,D) \tkzDefMidPoint(P,Q)\tkzGetPoint{MPQ} \tkzDrawSegment[Green, thick](P,Q) \tkzLabelSegment[Green, left, pos=0.85](P,Q){$k$} \tkzDrawPoints[black, size=3pt](P,Q) \tkzLabelPoint[above left=0 and -1mm](P){$P$} \tkzDrawSegment[Red, thick, add=1.3 and 0.5](Q,P') \end{tikzpicture} \end{document} The output is the following: What I want to do is to extend that segment to make it look like a line that cuts the plane in such a way that the part below plane is solid but the part between cutting point and bottom part of the plane is dashed. How can I do that? And also, is there a way to calculate the coordinates of orthogonal projection of point P on that plane? I just set its y coordinate to 0 but it does not seems to be correct, expecially when I want to draw an straight angle.
- Can I simulate colour-blindness (in Beamer / TikZ)by Chris H on July 22, 2024 at 3:31 pm
I'm putting together a talk on figures for publications, and one point I want to make is about them being accessible to colour-blind readers/viewers. So far I've been using ColorOracle to simulate what a colour-blind person might see (it's also handy for simulating greyscale). However this has a few downsides: It isn't an option using someone else's machine, like one of our seminar room setups, it doesn't play nicely with multiple monitors, and as soon as you click on another window, the display reverts to normal. This is probably wishful thinking, but is there a simple way to switch the contents of my slides to a simulated view? Just the LaTeX/TikZ content would be good, though of course imported logos and graphics would be better. Otherwise I would look for an external tool that can generate PDFs that I can then include, but that's not as flexible on the day. Some very useful background is in the preprint Easy colorblind-safe typesetting: General guidelines and a helpful LATEX package, Simon Pfahler TUG2024. My goals are similar.
- Sphere with a randomly marked region and an equatorial circleby hteica on June 17, 2024 at 2:42 pm
I'm working with spheres in 3D and would like to draw a sphere with an open region $U$ with color green and enclosed closed region $E$ filled with color red such that $E \subset U$. And a vector $x$ on the sphere with the dotted equatorial circle, however this circle should disappear in the region $U$. There is a similar post about this: Random closed line on a 3d sphere. I'd be gladly for any codes/tips/resources where I can learn to do this. Thank you
- what would be the best way to wire these without it looking like a mess? (circuitikz)by Nate3384 on May 29, 2024 at 3:46 pm
simply doing it this way results in an unreadable mess, as you can see in the picture following it, I want to know if there's a better way of doing it without changing the pin order of the XNN components. \documentclass{article} \usepackage{circuitikz} \begin{document} \begin{circuitikz} % Define positions for the w, x, y, z labels \node (label_w) at (-4, 1.5) {$w$}; \node (label_x) at (-4, 0.5) {$x$}; \node (label_y) at (-4, -0.5) {$y$}; \node (label_z) at (-4, -1.5) {$z$}; \node [muxdemux, muxdemux def={NL=4, NR=1, NB=0, w=3, square pins=0, Lh=6, Rh=6}, rotate=0](A) at (0,2) {\rotatebox{0}{\small \ttfamily XNN}}; \node[above] at (A.lpin 1) {$x$}; \node[above] at (A.lpin 2) {$y$}; \node[above] at (A.lpin 3) {$z$}; \node[above] at (A.lpin 4) {$w$}; \node [muxdemux, muxdemux def={NL=4, NR=1, NB=0, w=3, square pins=0, Lh=6, Rh=6}, rotate=0](B) at (0,-2) {\rotatebox{0}{\small \ttfamily XNN}}; \node[above] at (B.lpin 1) {$z$}; \node[above] at (B.lpin 2) {$w$}; \node[above] at (B.lpin 3) {$x$}; \node[above] at (B.lpin 4) {$y$}; \node [muxdemux, muxdemux def={NL=4, NR=1, NB=0, w=3, square pins=0, Lh=6, Rh=6}, rotate=0](C) at (5,0) {\rotatebox{0}{\small \ttfamily XNN}}; \node[left] at (C.lpin 1) {\scriptsize XNN$\left(x,y,z,w\right)$}; \node[left] at (C.lpin 2) {\scriptsize XNN$\left(z,w,x,y\right)$}; \node[above] at (C.lpin 3) {$0$}; \node[above] at (C.lpin 4) {$0$}; \node[above] at (C.rpin 1) {$F$}; \begin{scope} \draw[draw opacity=0.4] (A.rpin 1) -| ([xshift=-1cm]C.lpin 1) |- (C.lpin 1); \draw[draw opacity=0.4] (B.rpin 1) -| ([xshift=-1cm]C.lpin 2) |- (C.lpin 2); \end{scope} % Wire from labels w,x,y,z to A and B pin's \draw (label_w) -- ++(0.5,0) |- (A.lpin 4); \draw (label_w) -- ++(0.5,0) |- (B.lpin 2); \draw (label_x) -- ++(0.75,0) |- (A.lpin 1); \draw (label_x) -- ++(0.75,0) |- (B.lpin 3); \draw (label_y) -- ++(1,0) |- (A.lpin 2); \draw (label_y) -- ++(1,0) |- (B.lpin 4); \draw (label_z) -- ++(1.5,0) |- (A.lpin 3); \draw (label_z) -- ++(1.5,0) |- (B.lpin 1); \end{circuitikz} \end{document}
- How to build cylinders similar to this, but in reverse?by TCR on April 8, 2024 at 8:06 pm
How to build cylinder in tikz like shown in this example The example above builds a set of ever-larger cylinders on top of each other with texts on the side, starting at the bottom. The example output and code is replicated here. The source is the link above. \documentclass[border=3.14pt]{standalone} \usepackage{pgfplots} \definecolor{myellow}{RGB}{228,212,0} \definecolor{mgreen}{RGB}{5,104,57} \newcommand\funnel[3]{% \pgfmathsetmacro\mwid{(2+\xi*.7)} \pgfmathsetmacro\marc{\mwid-.4} \begin{scope}[% shift={(0,#1)}, line width=.05pt, %x=5mm, %scale=1.\xi, yshift=\xi*12 ] \draw[black,bottom color=#2, top color=#2] (-\mwid,0) -- (-\mwid+.4,-1) arc (190:350:\marc cm and 5mm) -- (\mwid,0); \draw[black,fill=#3] (0,0) ellipse (\mwid cm and 5mm); \path (-\mwid,0) -- (-\mwid+.4,-1) coordinate[midway] (a\xi); \end{scope} } \begin{document} \begin{tikzpicture}[ latent/.style={% ,circle ,draw ,thick ,minimum size=10mm } ] \foreach \text [% count=\xi starting from 0, evaluate=\xi as \shadecolor using int(25*\xi), evaluate=\xi as \coord using int(\xi-12) ] in {% Discuss and conclude\\overall findings, Combine the data\\\tiny\itshape (synthesis or meta-analysis), Assess the quality\\of the studies, Extract data from the studies }{% \funnel{\coord}{mgreen!\shadecolor !myellow}{mgreen!\shadecolor !myellow} \node[align=right, anchor=east, inner sep=10pt, font=\scriptsize, text width=2cm] at (a\xi) {\text}; } \end{tikzpicture} \end{document} I am looking for two things: A set of an arbitrary number of ever-larger cylinders on top of each other with texts on the side, starting from the top. Following the ever-larger cylinders, a set of an arbitrary number of ever-smaller cylinders on top of each other with texts on the side, starting from the top. (Effectively the same as the example, but rather than starting from the bottom and go up, it would start from the top and go down.) Ideally the size of the last (and the widest) cylinder from 1 would transition smoothly to the top-most cylinder from 2. In other words, I would like to have to have a set of cylinders first expanding as we move down and then narrowing. Thus far I have been tinkering with the funnel function by trying various combinations of positive and negative signs for \xi, \mwid, etc. None of the combinations have worked. Embarrassingly while the example code produces a wonder set of cylinders almost what I wanted, the PGF/TikZ code in it is much too advanced for my understanding. **Edits: 1. adding the final sentence as it was cut off; 2. steps I have attempted at creating what I wanted.
- TikZ text node and edge position in TikZitby Qohelet on November 27, 2023 at 5:46 pm
I am using the TikZit application to construct a diagram containing nodes that "contain" or "consist of" only text (formatted with color, etc.) and that are connected by various edges. When inputing the text as the label argument, the connecting edge encroaches into the middle of the text, like this: Here is the source code generated by TikZit: \begin{tikzpicture} \begin{pgfonlayer}{nodelayer} \node [style=none] (0) at (-2.5, 7) {Hello world!}; \node [style=green dot] (1) at (1.75, 5) {}; \node [style=red dot] (2) at (2.25, -0.75) {}; \node [style=none] (3) at (-3, -2) {}; \end{pgfonlayer} \begin{pgfonlayer}{edgelayer} \draw (0.center) to (1); \draw [in=30, out=45, looseness=2.25] (1) to (2); \draw (3.center) to (2); \end{pgfonlayer} \end{tikzpicture} I was able to use the label={POSITION:TEXT} option to modify the default behavior \node [style=none, label={above=Hello \textcolor{blue}{World!}}] (0) at (-2.5, 7) {}; which renders which is what I am wanting. The problem is that I do not want to manually input the position parameter for each node and I do not know how to set up a node style that will automatically position the edge connection relative to the text node without having to specify the position in each case. To put it in question form: Is there a way to set up a node style that will automatically position the connecting edge on the "outside" of the node relative to the text like the second image above? Any help is appreciated.
- 3D view of a 2D rectangleby Diaa on November 12, 2023 at 11:34 pm
I would be grateful to know how to: fix the code to make it work be able to control the viewing angle so that I can see the rectangle like the top surface of this image \documentclass{article} \usepackage{tikz-3dplot} \usetikzlibrary{perspective,calc,3d,arrows} \begin{document} \tdplotsetmaincoords{70}{110} % Set the view angles \begin{tikzpicture}[scale=2, transform shape, tdplot_main_coords] % Define the coordinates of the rectangle corners with labels \coordinate (A) at (0,0,0); \coordinate (B) at (4,0,0); \coordinate (C) at (4,1,0); \coordinate (D) at (0,1,0); % Draw the rectangle \draw (A) -- (B) -- (C) -- (D) -- cycle; % Draw x-axis \draw[->] (0,0,0) -- (2,0,0) node[anchor=north east]{$x$}; % Draw y-axis \draw[->] (0,0,0) -- (0,2,0) node[anchor=north west]{$y$}; % Draw z-axis \draw[->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$}; % Add labels to coordinates \node[above right] at (A) {$A$}; \node[above right] at (B) {$B$}; \node[above right] at (C) {$C$}; \node[above right] at (D) {$D$}; \end{tikzpicture} \end{document}
- TikZ fill behavior depends on perspective (tikz-3dplot)by Leyna Shackleton on August 11, 2023 at 10:25 pm
Here is my MWE: \documentclass{minimal} \usepackage{pgfplots} \pgfplotsset{compat=newest} \usepackage{tikz-3dplot} \tdplotsetmaincoords{80}{-5} \begin{document} \begin{tikzpicture} \draw[fill=gray] (1.66, -2, 0) -- (1.33, -2, 0) .. controls (1.33, -0.5, -1) .. (1.33, 1, 0) -- (1.66, 1, 0) .. controls (1.66, -0.5, -1) .. (1.66, -2, 0); \end{tikzpicture} \begin{tikzpicture}[tdplot_main_coords] \draw[fill=gray] (1.66, -2, 0) -- (1.33, -2, 0) .. controls (1.33, -0.5, -1) .. (1.33, 1, 0) -- (1.66, 1, 0) .. controls (1.66, -0.5, -1) .. (1.66, -2, 0); \end{tikzpicture} \end{document} which outputs the following: I'm drawing a curved sheet for which the interior should be filled in, but precisely how this is filled in depends on the coordinate system - the first one is how it should be shaded, but it seems like if I change the perspective, TikZ gets confused and doesn't shade it in properly. Is there any way to fix this?
- Filling in capped off torus in tikz 3dby heervande on July 7, 2023 at 1:28 pm
I am trying to draw a capped off torus in tikz 3d, see MWE below. I'd like the surface to be colored in gray for the first picture, and everything below the blue line to be colored in gray for the second one. Is it possible to do this and changing as little as possible about the picture (so it will still be in the same style with some other pictures I made)? Thanks in advance \documentclass[tikz,border=1.618mm]{standalone} \usepackage{tikz} \usepackage{tikz-3dplot} \usepackage{tikz-cd} \usepackage[]{calc} \begin{document} \tdplotsetmaincoords{80}{0} \begin{tikzpicture}[scale=5,tdplot_main_coords] \coordinate (O) at (0,0,0); \tdplotsetrotatedcoords{90}{90}{0} \tdplotdrawarc[bottom color= gray, top color= gray!40, tdplot_main_coords]{(0,-0.08,0.76604444311)}{0.64278760968}{0}{360}{}{} \tdplotdrawarc[tdplot_rotated_coords]{(O)}{1}{-140.5}{140.5}{}{} \tdplotdrawarc[tdplot_rotated_coords]{(O)}{.25}{0}{360}{}{} \end{tikzpicture} \tdplotsetmaincoords{80}{0} \begin{tikzpicture}[scale=5,tdplot_main_coords] \coordinate (O) at (0,0,0); \tdplotsetrotatedcoords{90}{90}{0} \tdplotdrawarc[tdplot_main_coords,color=blue, dashed]{(0,-0.08,0.76604444311)}{0.64278760968}{0}{180}{}{} \tdplotdrawarc[tdplot_main_coords,color=blue]{(0,-0.08,0.76604444311)}{0.64278760968}{180}{360}{}{} \tdplotdrawarc[tdplot_rotated_coords]{(O)}{1}{-140.5}{140.5}{}{} \tdplotdrawarc[tdplot_rotated_coords]{(O)}{.25}{0}{360}{}{} \tdplotsetrotatedcoords{90}{-90}{0} \tdplotdrawarc[tdplot_rotated_coords, color=blue]{(O)}{1}{-39.5}{39.5}{}{} \end{tikzpicture} \end{document}
- tabularray and babel frenchby jrivet on April 7, 2022 at 1:34 pm
I need to use \usetikzlibrary{babel} but it causes an error in the folowing example. \documentclass[french]{article} \usepackage{babel} \usepackage{tabularray} \usepackage{pgfplots} \usepackage{circuitikz} %to draw an electrical circuit %\usetikzlibrary{babel} %I need this library because I use french babel and circuitikz \begin{document} \begin{center} \begin{tblr}{colspec={Q[c,m]Q[c,m]},vlines,hlines} $y=2x$ & \begin{tikzpicture}[baseline=(current bounding box.center)] \begin{axis}[ xlabel = {$x$}, ylabel = {$y$}, ] \addplot[domain=0:10]{2*x}; \end{axis} \end{tikzpicture} \end{tblr} \end{center} \end{document}
- Tikz 3D plot of poles zerosby Raja Ali Riaz on September 18, 2021 at 4:43 pm
I need to make a 3D plot in tikz of the form as in the picture. It's the magnitude plot of transfer function H(s)= (s+1)(s+2)/(s+3)(s+1+j)(s+1-j) I am sorry, I have not shared any attempt because I am ignorant in tikz 3d plotting. If somebody provide the solution, it will be kick start for me and then I build up on it. Thanks in advance. My Attempt and still few things to rectify. I have plotted the graph with online help of different resources (code and picture attached). Now the problems are It is not correcting plotting the curve in y-z plane the red line and give this error message Package pgfplots Error: Sorry, you can't use 'y' in this context. PGFPlots expected to sample a line, not a mesh. Please use the [mesh] option combined with [samples y>0] and [domain y!=0:0] to indicate a twodimensional input domain. Labels are too small and not placed properly. If somebody can set view angles so it looks like the picture of the book. If somebody can help in that regard. \documentclass[border=1cm]{standalone} \usepackage{pgfplots} \usetikzlibrary{calc,math} \pgfplotsset{compat=newest} \pgfkeys{/pgf/declare function={H(\x,\y) = 3*((((((\x)^2-(\y)^2+3*(\x)+2)^2+((2*\x*\y)+3*\y)^2)+2.2204e-16)^(1/2))/(((((\x)^3+5*(\x)^2-3*\x*(\y)^2+8*x-5*(\y)^2+6)^2+(3*(\x)^2*y+10*\x*\y-(\y)^3+8*y)^2)+2.2204e-16)^(1/2)));}} \begin{document} \begin{tikzpicture} \begin{axis}[ axis lines=middle, axis on top, axis equal image, width=50cm, view={30}{10}, xmin=-4, xmax=0, ymin=-2, ymax=2, zmin=0, zmax=5, miter limit=1, xlabel=$\sigma$, xlabel style={anchor=east,xshift=-5pt,at={(xticklabel* cs:.95)}}, ylabel=$j\Omega$, zlabel=$\mathopen| H(s)\mathclose|$, zlabel style={anchor=north east}, xtick = {-3,-2,-1,0}, hide obscured x ticks=false, ytick = {-1,0,1}, ztick = {2,4}, ] \addplot3[ smooth, surf, faceted color=gray, line width=0.1pt, fill=white, domain=-4:0, y domain = -2:2, samples = 50, samples y = 50, restrict z to domain*=0:5] {H(\x,\y)}; \addplot3[domain=-2:2,samples=70, samples y = 0,red, thick] ({0},{x},{H(0,x)}); \end{axis} \end{tikzpicture} \end{document}
- Tikz : Customize dotted line on a portion of the segmentby RedWest on May 7, 2021 at 2:21 am
I am looking to change the pattern of a segment in the middle of it or after a predefined distance in cm or pt for example. I have tried to look at the draw pattern but without finding any good solutions. Does anyone have any ideas? Here is the basic code : \documentclass[border=1cm]{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture} \node at (0,0) [circle,draw]{$t_1$}; \node at (1.5,0) [circle,draw]{$t_2$}; \node at (3,0) [circle,draw]{$t_3$}; \node at (4.5,0) [circle,draw]{$t_4$}; \node at (6,0) [circle,draw]{$t_4$}; \draw [color=red!100,line width=1pt](0,-0.4) to [bend right=45] (1.5,-0.4); \draw [color=red!100,line width=1pt](1.5,-0.4) to [bend right=45] (3,-0.4); \draw [color=red!100,line width=1pt](3,-0.4) to [bend right=45] (4.5,-0.4); \draw [color=red!100,line width=1pt](4.5,-0.4) to [bend right=45] (6,-0.4); \draw [color=blue!100,line width=1pt](0,-0.4) to [bend right=45] (3,-0.4); \draw [color=green!100,line width=1pt](0,-0.4) to [bend right=45] (3,-0.4); \draw [color=blue!100,line width=1pt](0,0.4) to [bend left=45] (6,0.4); \end{tikzpicture} \end{document}
- plotting a 3D coneby Nilcouv on April 21, 2020 at 2:50 pm
I'm trying to plot a cone in 3D, but I'm a little stuck. I plotted a densely dashed, then I'm trying to plot the border of the cone, divided in 3 part: The green part is static The blue part change depending on the height of the cone The red part is just a connection between a dot "h" and the blue part. I'm unable to plot the red left part of the cone, and the there is a black line when "height=0" %%%%%%%%%%%%%%%%%% INTRODUCTION %%%%%%%%%%%%%%%%%% \documentclass[border=10pt]{standalone} %%%%%%%%%%%%%%%%%% PACKAGE %%%%%%%%%%%%%%%%%% \usepackage{tikz, tkz-euclide}% permet de dessiner des figures, des graphiques \usepackage{adjustbox}% permet de déterminer une taille de fenêtre %% FONT \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage{tgadventor}% paquet de police de caractère TGadventor \usepackage{sansmath}% Copie-colle la police active dans % \sfdefault (/!\ N'EST PAS UNE POLICE DE CARACTÈRES) \usepackage{xcolor} %%%%%%%%%%%%%%%%%% INPUT %%%%%%%%%%%%%%%%%% %\input{preamble} %\input{parameters} %\input{types/f3d_fig} %%%%%%%%%%%%%%%%%% SETUP %%%%%%%%%%%%%%%%%% \tikzset{volum3D/.style={font={\sansmath\sffamily\large}, line width=0.4mm, line cap=round, line join=round, >=latex,}} %%%%%%%%%%%%%%%%%%%%%%%% CONE %%%%%%%%%%%%%%%%%%%%%%%% \makeatletter \tikzset{pics/cone/.style={code={% \tikzset{cone/.cd,#1}% \def\pv##1{\pgfkeysvalueof{/tikz/cone/##1}}% \pgfmathsetmacro{\myan}{atan2(\pgf@zx,\pgf@xx)}% \begin{scope}[local bounding box=sph]% %%% Compute the angle \pgfmathsetmacro\angle{acos(1/\pv{height})} \path[cone/corps] %%% Patrie supérieur (0, \pv{height}*\pv{scale}, 0) coordinate (h) node[above] {\angle} node[below] {\myan} %%% Patrie droite (h) -- plot[smooth,variable=\t,samples=19,domain={(sign(\myan)*90+\myan)-\angle}:\myan] ({\pv{ray}*\pv{scale}*cos(\t)}, 0, {\pv{ray}*\pv{scale}*sin(\t)}) %%% Patrie Inférieur -- plot[smooth,variable=\t,samples=19,domain=\myan:{-1*sign(\myan)*180+\myan}] ({\pv{ray}*\pv{scale}*cos(\t)}, 0, {\pv{ray}*\pv{scale}*sin(\t)}) %%% Patrie gauche %-- plot[smooth,variable=\t,samples=19,domain={180*\myan-\myan}:\myan] %({\pv{ray}*\pv{scale}*cos(\t)}, %0, %{\pv{ray}*\pv{scale}*sin(\t)}) -- cycle ; %%% CERCLE EN POINTILLÉ \draw[thick, densely dashed] %%% Arc Avant plot[smooth,variable=\t,samples=19,domain={-1*sign(\myan)*180+\myan}:\myan] ({\pv{ray}*\pv{scale}*cos(\t)}, 0, {\pv{ray}*\pv{scale}*sin(\t)}) %%% Arc Arrière plot[smooth,variable=\t,samples=19,domain={sign(\myan)*180+\myan}:\myan] ({\pv{ray}*\pv{scale}*cos(\t)}, 0, {\pv{ray}*\pv{scale}*sin(\t)}) ; \end{scope} %% Dot (0,0) \draw (0,0,0) node[circle, fill=black, inner sep=1pt] {} coordinate (o) ; }}, cone/.cd, ray/.initial=5, height/.initial=3, scale/.initial=1, corps/.style={draw,fill=black!15}, } \makeatother %%%%%%%%%%%%%%%%%% DOCUMENT %%%%%%%%%%%%%%%%%% \begin{document} \begin{tikzpicture}[volum3D, x={(0:1cm)}, y={(90:1cm)}, z={(89:0.4cm), scale=0.5}] % calibration cross %\pic at (5,0,0) {calcross}; % Figures \foreach \h in {0.5,1,...,8}{ \begin{scope}[shift={(6.2*\h,0)}] \pic{cone={ray=3, height=\h, scale=0.5}}; \end{scope} } \end{tikzpicture} \end{document}
- A hyperbolic triangle embedded in a saddle-shaped surfaceby Tony on August 16, 2018 at 5:49 pm
This is the diagram I would like to recreate. (from https://en.wikipedia.org/wiki/Hyperbolic_triangle) From Is there any easy way to draw a ruled surface like a hyperbolic paraboloid in TikZ?, I found a way to draw the saddle-shaped surface. Is there a way to draw the triangle on it? And get the colours/transparency like the picture? \documentclass{article} \usepackage{pgfplots} \begin{document} \begin{tikzpicture} \begin{axis} \addplot3 [surf,shader=flat,draw=black] {x^2-y^2}; \end{axis} \end{tikzpicture} \end{document}
- Adding coloured dashed lines inside matrix with external bracesby Milo on July 24, 2018 at 3:09 pm
This is the kind of the matrix I'm trying to create: Because I wanted labelled braces around the matrix, I've used the TikZ solution from this question. To get the dashed lines I've used the cheating dash style from this question, and drawn them taking inspiration from How to create vertical and horizontal dotted lines in a matrix?. My problem is this method requires a lot of manual adjustment. Another method to draw lines within matrices comes from How to add dash lines in Matrix, where there is a solution which uses array and arydshln. This draws them automatically, but I can't at the moment (a) change the colour, (b) add external braces to the matrix and (c) the ends of the dashed lines get cut off (this is precisely why I use cheating dash in the previous example). All these reasons suggest the TikZ method is the way to go. If only there was a better way to draw the lines automatically without having to the manually specify the start and end points? MWE \documentclass[12pt,a4paper]{article} \usepackage{mathtools} \usepackage{arydshln} % CODE BELOW FROM https://tex.stackexchange.com/a/1070/128068 % Load TikZ \usepackage{tikz} \usetikzlibrary{matrix,decorations.pathreplacing,calc} % Set various styles for the matrices and braces. It might pay off to fiddle around with the values a little bit \pgfkeys{tikz/mymatrixenv/.style={decoration=brace,every left delimiter/.style={xshift=3pt},every right delimiter/.style={xshift=-3pt}}} \pgfkeys{tikz/mymatrix/.style={matrix of math nodes,left delimiter=[,right delimiter={]},inner sep=2pt,column sep=1em,row sep=0.5em,nodes={inner sep=0pt}}} \pgfkeys{tikz/mymatrixbrace/.style={decorate,thick}} \newcommand\mymatrixbraceoffseth{0.5em} \newcommand\mymatrixbraceoffsetv{0.2em} \newcommand*\mymatrixbraceright[4][m]{ \draw[mymatrixbrace] ($(#1.north west)!(#1-#3-1.south west)!(#1.south west)-(\mymatrixbraceoffseth,0)$) -- node[left=2pt] {#4} ($(#1.north west)!(#1-#2-1.north west)!(#1.south west)-(\mymatrixbraceoffseth,0)$); } \newcommand*\mymatrixbraceleft[4][m]{ \draw[mymatrixbrace] ($(#1.north east)!(#1-#2-1.north east)!(#1.south east)+(\mymatrixbraceoffseth,0)$) -- node[right=2pt] {#4} ($(#1.north east)!(#1-#3-1.south east)!(#1.south east)+(\mymatrixbraceoffseth,0)$); } \newcommand*\mymatrixbracetop[4][m]{ \draw[mymatrixbrace] ($(#1.north west)!(#1-1-#2.north west)!(#1.north east)+(0,\mymatrixbraceoffsetv)$) -- node[above=2pt] {#4} ($(#1.north west)!(#1-1-#3.north east)!(#1.north east)+(0,\mymatrixbraceoffsetv)$); } \newcommand*\mymatrixbracebottom[4][m]{ \draw[mymatrixbrace] ($(#1.south west)!(#1-1-#3.south east)!(#1.south east)-(0,\mymatrixbraceoffsetv)$) -- node[below=2pt] {#4} ($(#1.south west)!(#1-1-#2.south west)!(#1.south east)-(0,\mymatrixbraceoffsetv)$); } % CHEATING DASH FROM https://tex.stackexchange.com/a/133357/128068 \tikzset{ cheating dash/.code args={on #1 off #2}{ % Use csname so catcode of @ doesn't have do be changed. \csname tikz@addoption\endcsname{% \pgfgetpath\currentpath% \pgfprocessround{\currentpath}{\currentpath}% \csname pgf@decorate@parsesoftpath\endcsname{\currentpath}{\currentpath}% \pgfmathparse{\csname pgf@decorate@totalpathlength\endcsname-#1}\let\rest=\pgfmathresult% \pgfmathparse{#1+#2}\let\onoff=\pgfmathresult% \pgfmathparse{max(floor(\rest/\onoff), 1)}\let\nfullonoff=\pgfmathresult% \pgfmathparse{max((\rest-\onoff*\nfullonoff)/\nfullonoff+#2, #2)}\let\offexpand=\pgfmathresult% \pgfsetdash{{#1}{\offexpand}}{0pt}}% } } \begin{document} \begin{equation} \mathbf{X} = \begin{tikzpicture}[baseline=0cm,mymatrixenv] \matrix [mymatrix,inner sep=4pt,row sep=1em] (m) { \frac{x}{y} + C & m\omega^2 + U \\ 0 & 1 \\ 1 & \frac{x}{y} + Dx^2 \\ }; % Dashed lines \draw [cheating dash=on 2pt off 2pt,red] ([xshift=1ex,yshift=1ex]m-1-1.north east) --++(-90:2.4cm); \draw [cheating dash=on 2pt off 2pt,red] ([xshift=-0.3ex,yshift=-0.9ex]m-1-1.south west) --++(0:3.3cm); % Braces \mymatrixbraceright{1}{3}{$A$} \mymatrixbracetop{2}{2}{$B$} \end{tikzpicture} \end{equation} \begingroup \renewcommand*{\arraystretch}{1.75} \begin{equation} \mathbf{X} = \left[ \begin{array}{c;{2pt/2pt}c} \frac{x}{y} + C & m\omega^2 + U \\ \hdashline[2pt/2pt] 0 & 1 \\ 1 & \frac{x}{y} + Dx^2 \\ \end{array} \right] \end{equation} \endgroup \end{document} ADDED - I should mention that for different matrices I play around the tikz/mymatrix/.style settings, like changing inner sep and row sep. If the placement of the dashed lines could be somehow tied into those settings that would be ideal. This highlights why my current method (specifying the lengths in centimeters) is not ideal.
- Clipping more complicated shapes in TikZby user121799 on December 31, 2017 at 2:33 am
I have tried to understand TikZ clipping better but I am stuck. I'd like to clip the area bounded by the blue contour in this picture: Unfortunately, the MWE is rather lengthy, and based on Alain Matthes cool macros and some additional macros from the answer here. \documentclass{article} \usepackage{tikz} \usetikzlibrary{calc,fadings,decorations.pathreplacing,shadings} \usepackage{verbatim} \newcommand\pgfmathsinandcos[3]{% \pgfmathsetmacro#1{sin(#3)}% \pgfmathsetmacro#2{cos(#3)}% } \newcommand\LongitudePlane[3][current plane]{% \pgfmathsinandcos\sinEl\cosEl{#2} % elevation \pgfmathsinandcos\sint\cost{#3} % azimuth \tikzset{#1/.style={cm={\cost,\sint*\sinEl,0,\cosEl,(0,0)}}} } \newcommand\LatitudePlane[3][current plane]{% \pgfmathsinandcos\sinEl\cosEl{#2} % elevation \pgfmathsinandcos\sint\cost{#3} % latitude \pgfmathsetmacro\yshift{\RadiusSphere*\cosEl*\sint} \tikzset{#1/.style={cm={\cost,0,0,\cost*\sinEl,(0,\yshift)}}} % } \newcommand\NewLatitudePlane[4][current plane]{% \pgfmathsinandcos\sinEl\cosEl{#3} % elevation \pgfmathsinandcos\sint\cost{#4} % latitude \pgfmathsetmacro\yshift{#2*\cosEl*\sint} \tikzset{#1/.style={cm={\cost,0,0,\cost*\sinEl,(0,\yshift)}}} % } \newcommand\DrawLongitudeCircle[2][1]{ \LongitudePlane{\angEl}{#2} \tikzset{current plane/.prefix style={scale=#1}} % angle of "visibility" \pgfmathsetmacro\angVis{atan(sin(#2)*cos(\angEl)/sin(\angEl))} % \draw[current plane] (\angVis:1) arc (\angVis:\angVis+180:1); \draw[current plane,opacity=0.4] (\angVis-180:1) arc (\angVis-180:\angVis:1); } \newcommand\DrawLongitudeArc[4][black]{ \LongitudePlane{\angEl}{#2} \tikzset{current plane/.prefix style={scale=1}} \pgfmathsetmacro\angVis{atan(sin(#2)*cos(\angEl)/sin(\angEl))} % \pgfmathsetmacro\angA{mod(max(\angVis,#3),360)} % \pgfmathsetmacro\angB{mod(min(\angVis+180,#4),360} % \draw[current plane,#1,opacity=0.4] (#3:\RadiusSphere) arc (#3:#4:\RadiusSphere); \draw[current plane,#1] (\angA:\RadiusSphere) arc (\angA:\angB:\RadiusSphere); }% \newcommand\DrawLatitudeCircle[2][1]{ \LatitudePlane{\angEl}{#2} \tikzset{current plane/.prefix style={scale=#1}} \pgfmathsetmacro\sinVis{sin(#2)/cos(#2)*sin(\angEl)/cos(\angEl)} % angle of "visibility" \pgfmathsetmacro\angVis{asin(min(1,max(\sinVis,-1)))} \draw[current plane] (\angVis:1) arc (\angVis:-\angVis-180:1); \draw[current plane,opacity=0.4] (180-\angVis:1) arc (180-\angVis:\angVis:1); } \newcommand\DrawLatitudeArc[4][black]{ \LatitudePlane{\angEl}{#2} \tikzset{current plane/.prefix style={scale=1}} \pgfmathsetmacro\sinVis{sin(#2)/cos(#2)*sin(\angEl)/cos(\angEl)} % angle of "visibility" \pgfmathsetmacro\angVis{asin(min(1,max(\sinVis,-1)))} \pgfmathsetmacro\angA{max(min(\angVis,#3),-\angVis-180)} % \pgfmathsetmacro\angB{min(\angVis,#4)} % \draw[current plane,#1,opacity=0.4] (#3:\RadiusSphere) arc (#3:#4:\RadiusSphere); \draw[current plane,#1] (\angA:\RadiusSphere) arc (\angA:\angB:\RadiusSphere); } %% document-wide tikz options and styles \tikzset{% >=latex, % option for nice arrows inner sep=0pt,% outer sep=2pt,% mark coordinate/.style={inner sep=0pt,outer sep=0pt,minimum size=3pt, fill=black,circle}% } \begin{document} \begin{tikzpicture} % "THE GLOBE" showcase \def\RadiusSphere{4} % sphere radius \def\angEl{20} % elevation angle \def\angAz{-20} % azimuth angle \shade[ball color = gray!40, opacity = 0.5] (0,0) circle (\RadiusSphere); \tikzset{ every path/.style={ color=black } } \DrawLatitudeArc[blue]{40}{-140}{-30} \DrawLongitudeArc[blue]{-140}{-30}{40} \DrawLatitudeArc[blue]{-30}{-140}{-30} \DrawLongitudeArc[blue]{-30}{-30}{40} \end{tikzpicture} \end{document} The problem is that, according to what I read, clip needs to be the only option of \draw, but this clashes with the way the arcs are drawn here. So I am wondering if there is a way to have both. EDIT Motivated by the great progress by John Kormylo, I tried (and to some extent succeeded) to find alternative ways of shading the area. They are based on this post, and require the spath package (run pdflatex spath.dtx). \documentclass{article} \usepackage{tikz} \usetikzlibrary{shadings} \usepackage{spath} % from https://tex.stackexchange.com/a/26664/121799 \usetikzlibrary{calc,fadings,decorations.pathreplacing,shadings} \usepackage{verbatim} \newcommand\pgfmathsinandcos[3]{% \pgfmathsetmacro#1{sin(#3)}% \pgfmathsetmacro#2{cos(#3)}% } \newcommand\LongitudePlane[3][current plane]{% \pgfmathsinandcos\sinEl\cosEl{#2} % elevation \pgfmathsinandcos\sint\cost{#3} % azimuth \tikzset{#1/.style={cm={\cost,\sint*\sinEl,0,\cosEl,(0,0)}}} } \newcommand\LatitudePlane[3][current plane]{% \pgfmathsinandcos\sinEl\cosEl{#2} % elevation \pgfmathsinandcos\sint\cost{#3} % latitude \pgfmathsetmacro\yshift{\RadiusSphere*\cosEl*\sint} \tikzset{#1/.style={cm={\cost,0,0,\cost*\sinEl,(0,\yshift)}}} % } \newcommand\NewLatitudePlane[4][current plane]{% \pgfmathsinandcos\sinEl\cosEl{#3} % elevation \pgfmathsinandcos\sint\cost{#4} % latitude \pgfmathsetmacro\yshift{#2*\cosEl*\sint} \tikzset{#1/.style={cm={\cost,0,0,\cost*\sinEl,(0,\yshift)}}} % } \newcommand\DrawLongitudeCircle[2][1]{ \LongitudePlane{\angEl}{#2} \tikzset{current plane/.prefix style={scale=#1}} % angle of "visibility" \pgfmathsetmacro\angVis{atan(sin(#2)*cos(\angEl)/sin(\angEl))} % \draw[current plane] (\angVis:1) arc (\angVis:\angVis+180:1); \draw[current plane,opacity=0.4] (\angVis-180:1) arc (\angVis-180:\angVis:1); } \newcommand\DrawLongitudeArc[4][black]{ \LongitudePlane{\angEl}{#2} \tikzset{current plane/.prefix style={scale=1}} \pgfmathsetmacro\angVis{atan(sin(#2)*cos(\angEl)/sin(\angEl))} % \pgfmathsetmacro\angA{mod(max(\angVis,#3),360)} % \pgfmathsetmacro\angB{mod(min(\angVis+180,#4),360} % \draw[current plane,#1,opacity=0.4] (#3:\RadiusSphere) arc (#3:#4:\RadiusSphere); \draw[current plane,#1] (\angA:\RadiusSphere) arc (\angA:\angB:\RadiusSphere); }% \newcommand\ClipLongitudeArc[4][black]{ \LongitudePlane{\angEl}{#2} \tikzset{current plane/.prefix style={scale=1}} \pgfmathsetmacro\angVis{atan(sin(#2)*cos(\angEl)/sin(\angEl))} % \pgfmathsetmacro\angA{mod(max(\angVis,#3),360)} % \pgfmathsetmacro\angB{mod(min(\angVis+180,#4),360} % \path[save path=\tmppathI,current plane,#1,opacity=0.4] (#3:\RadiusSphere) arc (#3:#4:\RadiusSphere); \path[save path=\tmppathII,current plane,#1] (\angA:\RadiusSphere) arc (\angA:\angB:\RadiusSphere); }% \newcommand\ClipLongitudeArcReverse[4][black]{ \LongitudePlane{\angEl}{#2} \tikzset{current plane/.prefix style={scale=1}} \pgfmathsetmacro\angVis{atan(sin(#2)*cos(\angEl)/sin(\angEl))} % \pgfmathsetmacro\angA{mod(max(\angVis,#3),360)} % \pgfmathsetmacro\angB{mod(min(\angVis+180,#4),360} % \path[save path=\tmppathI,current plane,#1,opacity=0.4] (#4:\RadiusSphere) arc (#4:#3:\RadiusSphere); \path[save path=\tmppathII,current plane,#1] (\angB:\RadiusSphere) arc (\angB:\angA:\RadiusSphere); }% \newcommand\DrawLatitudeCircle[2][1]{ \LatitudePlane{\angEl}{#2} \tikzset{current plane/.prefix style={scale=#1}} \pgfmathsetmacro\sinVis{sin(#2)/cos(#2)*sin(\angEl)/cos(\angEl)} % angle of "visibility" \pgfmathsetmacro\angVis{asin(min(1,max(\sinVis,-1)))} \draw[current plane] (\angVis:1) arc (\angVis:-\angVis-180:1); \draw[current plane,opacity=0.4] (180-\angVis:1) arc (180-\angVis:\angVis:1); } \newcommand\DrawLatitudeArc[4][black]{ \LatitudePlane{\angEl}{#2} \tikzset{current plane/.prefix style={scale=1}} \pgfmathsetmacro\sinVis{sin(#2)/cos(#2)*sin(\angEl)/cos(\angEl)} % angle of "visibility" \pgfmathsetmacro\angVis{asin(min(1,max(\sinVis,-1)))} \pgfmathsetmacro\angA{max(min(\angVis,#3),-\angVis-180)} % \pgfmathsetmacro\angB{min(\angVis,#4)} % \draw[current plane,#1,opacity=0.4] (#3:\RadiusSphere) arc (#3:#4:\RadiusSphere); \draw[current plane,#1] (\angA:\RadiusSphere) arc (\angA:\angB:\RadiusSphere); } \newcommand\ClipLatitudeArc[4][black]{ \LatitudePlane{\angEl}{#2} \tikzset{current plane/.prefix style={scale=1}} \pgfmathsetmacro\sinVis{sin(#2)/cos(#2)*sin(\angEl)/cos(\angEl)} % angle of "visibility" \pgfmathsetmacro\angVis{asin(min(1,max(\sinVis,-1)))} \pgfmathsetmacro\angA{max(min(\angVis,#3),-\angVis-180)} % \pgfmathsetmacro\angB{min(\angVis,#4)} % \path[save path=\tmppathI,current plane,#1,opacity=0.4] (#3:\RadiusSphere) arc (#3:#4:\RadiusSphere); \path[save path=\tmppathII,current plane,#1] (\angA:\RadiusSphere) arc (\angA:\angB:\RadiusSphere); } \newcommand\ClipLatitudeArcReverse[4][black]{ \LatitudePlane{\angEl}{#2} \tikzset{current plane/.prefix style={scale=1}} \pgfmathsetmacro\sinVis{sin(#2)/cos(#2)*sin(\angEl)/cos(\angEl)} % angle of "visibility" \pgfmathsetmacro\angVis{asin(min(1,max(\sinVis,-1)))} \pgfmathsetmacro\angA{max(min(\angVis,#3),-\angVis-180)} % \pgfmathsetmacro\angB{min(\angVis,#4)} % \path[save path=\tmppathI,current plane,#1,opacity=0.4] (#4:\RadiusSphere) arc (#4:#3:\RadiusSphere); \path[save path=\tmppathII,current plane,#1] (\angB:\RadiusSphere) arc (\angB:\angA:\RadiusSphere); } %% document-wide tikz options and styles \tikzset{% >=latex, % option for nice arrows inner sep=0pt,% outer sep=2pt,% mark coordinate/.style={inner sep=0pt,outer sep=0pt,minimum size=3pt, fill=black,circle}% } \begin{document} \begin{tikzpicture} % "THE GLOBE" showcase \def\RadiusSphere{4} % sphere radius \def\angEl{20} % elevation angle \def\angAz{-20} % azimuth angle \shade[ball color = gray!40, opacity = 0.5] (0,0) circle (\RadiusSphere); \tikzset{ every path/.style={ color=black } } \ClipLatitudeArc[blue]{40}{-140}{-30} \pgfoonew \patha=new spath(\tmppathI) \pgfoonew \pathb=new spath(\tmppathII) \ClipLongitudeArc[blue]{-30}{40}{-40} \pgfoonew \pathc=new spath(\tmppathI) \pgfoonew \pathd=new spath(\tmppathII) \ClipLatitudeArc[blue]{-40}{-30}{-140} \pgfoonew \pathe=new spath(\tmppathI) \pgfoonew \pathf=new spath(\tmppathII) \ClipLongitudeArc[blue]{-140}{-30}{40} \pgfoonew \pathg=new spath(\tmppathI) \pgfoonew \pathh=new spath(\tmppathII) \patha.concatenate with lineto(,\pathc) \patha.concatenate with lineto(,\pathe) \patha.concatenate with lineto(,\pathg) \patha.close() \patha.use path with tikz(line width=1pt,draw=black,fill=blue,path fading=south) \end{tikzpicture} \end{document} Although this comes somewhat closer to what I wish to achieve, I am still puzzled that these paths can not be used for clippings. (This also means that John Kormylo's approach is much cleaner and better.) And I am wondering if there is a cleaner or at least alternative way that does not rely on the inofficial spath package.
- Tikz pictures inside Tikz pictures: typesetting failing in lattice subgraph with edgesby hhh on April 16, 2016 at 11:29 am
I define Tikz pictures within each other. The typesetting fails in a way that the edges are not drawn properly: the edges are not drawn from the centers of vertices in the lattice subgraph structure, instead on the side of the vertices like below and the lattice subgraph structure is in 2. MWE while simplified example without the issue in 1. MWE: the issue somehow occurs only when having many tikz environments. 1. MWE draws the edges nicely between the centers of vertices \begin{tikzpicture} \tikzstyle{every node}=[draw, circle, fill=black, inner sep=4pt,minimum size=3pt] \draw (0,0)node{}; \draw (1,0)node{}; \draw (0.5,1)node{}; \draw (0,0)--(1,0); \end{tikzpicture} 2. MWE not drawing the edges nicely between the centers of vertices, why? \begin{tikzpicture}[scale=1.2] \tikzstyle{every node}=[draw, circle] \node(0) { \begin{tikzpicture} \tikzstyle{every node}=[draw, circle, fill=black, inner sep=0pt,minimum size=3pt] \draw (0,0)node{}; \draw (1,0)node{}; \draw (0.5,1)node{}; \end{tikzpicture} }; \node[above =of 0](1){ \begin{tikzpicture} \tikzstyle{every node}=[draw, circle, fill=black, inner sep=1pt,minimum size=3pt] \draw (0,0)node{} -- (1,0)node{}; \draw (0.5,1)node{}; \end{tikzpicture} }; \node[above right =of 1](21){ \begin{tikzpicture} \tikzstyle{every node}=[draw, circle, fill=black, inner sep=1pt,minimum size=3pt] \draw (0,0)node{} -- (1,0)node{} -- (0.5,1)node{}; \end{tikzpicture} }; \node[above left =of 1](22){ \begin{tikzpicture} \tikzstyle{every node}=[draw, circle, fill=black, inner sep=1pt,minimum size=3pt] \draw (0,0)node{} -- (0.5,1)node{} -- (1,0)node{}; \end{tikzpicture} }; \node[above left =of 21](30){ \begin{tikzpicture} \tikzstyle{every node}=[draw, circle, fill=black, inner sep=1pt,minimum size=3pt] \draw (0,0)node{} -- (1,0)node{} -- (0.5,1)node{}; \draw (0,0)node{} -- (0.5,1)node{}; \end{tikzpicture} }; \draw (0) -- (1); \draw (1) -- (21); \draw (1) -- (22); \draw (21) -- (30); \draw (22) -- (30); %\draw (21) -- (31); %\draw (21) -- (32); %\draw (21) -- (33); %\draw (31) -- (41); %\draw (31) -- (42); %\draw (32) -- (42); %\draw (33) -- (41); %\draw (22) -- (32); \end{tikzpicture} where the lattice subgraph picture has the failed typesetting, the edges not drawn between the centers. So How to draw edges properly from the centers of vertices in the lattice subgraph with many tikz environments? Perhaps relevant Nesting tikz pictures Joining different TikZ pictures What are most important variables set at the beginning of a tikzpicture? of a scope?
- rotate node in 3Dby Fadwa on November 19, 2015 at 6:54 am
I am trying to draw this 3D shape I draw the 4 arrows and the cylinder, but can't rotate the arrows in 3D to put them on the top. \documentclass{standalone} \usepackage[usenames,dvipsnames]{xcolor} \usepackage{tikz} \usetikzlibrary{shapes.geometric} \usetikzlibrary{shapes.arrows} \begin{document} %,rotate around={30:(0,1,1)} \begin{tikzpicture} \node[cylinder, draw=white,fill=blue, shape aspect=0.7,rotate=90,minimum height=0.7cm, minimum width=2cm] {hh}; \node [fill=red,single arrow, draw=none, rotate=90,minimum height=1cm,minimum width=0.7cm]at(0,0) {}; \node [fill=blue,single arrow, draw=none, rotate=-90,minimum height=1cm,minimum width=0.7cm] at (0,1.5) {}; \node [fill=red,single arrow, draw=none, rotate=-180,minimum height=1cm,minimum width=0.7cm]at(-0.75,0.7) {}; \node [fill=blue,single arrow, draw=none, rotate=-360,minimum height=1cm,minimum width=0.7cm] at (0.75,0.7) {}; \end{tikzpicture} \end{document}
- Spiral on a truncated coneby Dinis Nunes on September 1, 2015 at 2:33 pm
I need to plot a spiral around an inverted truncated cone, starting and ending at the centre of both bases. Something like this: I've searched and found a similar solution, but for cylinders only: Helix on a cylinder I couldn't adapt it to my geometric shape in question, so any help would be appreciated. The code for the cone only: \documentclass[border=0.125cm]{standalone} \usepackage{tikz} \usetikzlibrary{3d,calc} \begin{document} \begin{tikzpicture} \draw (-1,0) arc (180:370:2cm and 1cm); \draw (-1,0) arc (180:10:2cm and 1cm); \draw (0,-3) arc (180:360:1cm and 0.5cm); \draw[dashed] (0,-3) arc (180:0:1cm and 0.5cm); \draw(0,-3) -- (-0.97,-0.18); \draw(2,-3) -- (2.97,-0.18); \shade[left color=blue!5!white,right color=blue!60!white,opacity=0.3] (-0.97,-0.18) arc (190:350:2 and 1) -- (2,-3) arc (360:180:1cm and 0.5cm) -- cycle; \shade[left color=blue!5!white,right color=blue!60!white,opacity=0.3] (1,0) ellipse (2cm and 1cm); \draw[dashed] (0.7,-3) arc (180:0:0.3cm and 0.15cm); \draw[dashed] (0.7,-3) arc (180:360:0.3cm and 0.15cm); \end{tikzpicture} \end{document} Thanks in advance, Dinis Nunes EDIT: Following Ignasi suggestion, I've added a spiral function, but my goal was making the line follow closely the wall of the cone. Code: \node[xshift=1cm,yshift=-3cm] (dummy) {}; \draw[densely dotted,scale=0.09,variable=\x,shift=(dummy)] plot[domain = 0:10*pi, samples = 400] ({\x*0.6*sin(0.3*pi*deg(\x))},{\x},{\x*0.6*cos(0.3*pi*deg(\x)});
- Improving the visual appearance of a truncated cone in TikZby Ingo on August 27, 2014 at 4:19 pm
I have drawn a truncated cone in TikZ and am generally happy with the result. Here is the output and an MWE: \documentclass{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture}[>=latex] \fill[fill=gray!50] (1,0) ellipse (0.166 and 0.5); \fill[fill=gray!50] (4,0) ellipse (0.498 and 1.5); \fill[fill=gray!50] (1, 0.5) -- (4, 1.5) -- (4, -1.5) -- (1, -0.5) -- (1, 0.5); \draw[thick,->] (0,0,0) -- (5,0,0) node[anchor=west]{$z$}; \draw[thick,->] (0,0,0) -- (0,2,0) node[anchor=south]{$x$}; \draw[thick,->] (0,0,0) -- (0,0,2) node[anchor=north east]{$y$}; \draw[semithick] (1,0) ellipse (0.166 and 0.5); \draw[semithick] (4,0) ellipse (0.498 and 1.5); \draw (1, 0.5) -- (4, 1.5); \draw (1, -0.5) -- (4, -1.5); \end{tikzpicture} \end{document} However, I think that there is room for improvement. Here are some things that I could not figure out: How can we (automatically) dash the z-axis where it should be hidden, as well as part of the ellipse of one of the sides, which should not be visible? Would there be a sane way of adding some shading to the drawing, that would add depth? Can you help me out with these points?
- Rectangles around cells in tableby James on October 23, 2013 at 6:48 am
I asked a question here but, rather stupidly, added extra information after it had been answered. My additional question is this: I have a table with varying lengths of words. I want to encircle different groups of cells, including diagonals. If possible, it would be great if the rectangles don't overlap each other where possible. I looked at the answer here, which, whilst tedious, worked except for the overlap. This is where I've got to so far: \documentclass[fleqn,12pt,a4paper,landscape]{article} \usepackage{tikz} \usepackage{tabularx} \begin{document} % Introduce a new counter for counting the nodes needed for circling \newcounter{nodecount} % Command for making a new node and naming it according to the nodecount counter \newcommand\tabnode[1]{\addtocounter{nodecount}{1} \tikz \node (\arabic{nodecount}) {#1};} % Some options common to all the nodes and paths \tikzstyle{every picture}+=[remember picture,baseline] \tikzstyle{every node}+=[inner sep=0pt,anchor=base, minimum width=1.8cm,align=center,text depth=.25ex,outer sep=1.5pt] \tikzstyle{every path}+=[thick, rounded corners] \begin{table}[ht] \begin{minipage}[b]{1 \linewidth}\centering \begin{tabular}{cccccc} % Turn the cells needed for defining the circling paths into nodes with our custom command \tabnode{Long ago}& \tabnode{A few days ago}& \tabnode{Day before yesterday}& \tabnode{Yesterday} & & \\ & & & & \tabnode{Today} & \tabnode{Now}\\ \tabnode{Long time in the future}& \tabnode{A few days on}& \tabnode{Day after tomorrow}& \tabnode{Tomorrow} & & \\ \end{tabular} \end{minipage} \begin{tikzpicture}[overlay] % Define the circle paths \draw [blue](1.north west) -- (1.north east) -| (7.north east) |- (7.south west) |- (1.north west); \draw [red](8.south west) -| (2.north east) -| (2.south west) |- (8.south west); \draw [yellow](9.south west) -| (3.north east) -| (3.south west) |- (9.south west); \draw [green](8.south west) -| (3.north east) -| (2.south west) |- (8.south west); \end{tikzpicture} \end{table} \end{document} %%% Local Variables: %%% mode: latex %%% TeX-master: t %%% End:
- Helix on a cylinderby Grimolatto on August 24, 2013 at 8:49 am
I want to plot geodesics on a cylinder. These are straight lines, circles or helices. I can plot the first two, but I don't know how to draw the helices. To be precise, I would like to know how to draw an helix on this cylinder (passing thru two points A and B, but the location of the points is not relevant), using TikZ exclusively (maybe with pgfplots, but without using pstricks): \documentclass{standalone} \usepackage{tikz} \usetikzlibrary{shapes.geometric} \begin{document} \begin{tikzpicture} \node [cylinder,rotate=90,draw,aspect=2,minimum width=2cm,minimum height=3.5cm](C){}; \draw[fill] (-0.5,-0.5) circle [radius=0.045]node[below]{$A$}; \draw[fill] (0.5,0.75) circle [radius=0.045]node[below]{$B$}; \end{tikzpicture} \end{document}
- How to plot functions like x=f(y) using TikZ?by Sisabe on March 27, 2013 at 3:48 pm
To plot functions in the form of y=f(x), we simply write \draw [smooth,samples=100,domain=0:2] plot(\x,{(\x)...}); But how about functions like x=f(y)? How to plot them? How to specify their domains in terms of "y"? \documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} \draw [smooth,samples=100,domain=0:2] plot(???); \end{tikzpicture} \end{document}
- 3D bodies in TikZby azetina on January 30, 2012 at 4:35 pm
Is there like a library that has default geometric figures like the ones shown below. Am not acquainted yet with 3D diagrams in TikZ.
- beamer & TikZ: gradually unveil treesby Fred on June 13, 2011 at 11:02 am
Imagine a simple tree: \begin{tikzpicture} \node {Selbstregulation} [edge from parent fork down] child {node {Kognition}} child {node {Metakognition} child {node {Planung}} child {node {Monotoring}} child {node {Regulation}} } \end{tikzpicture} Is it possible to unveil the child nodes step by step using overlays in beamer? I tried with the \onslide command at several positions around child, but it doesn't work... Any hints? - Thanks.