TikZ
- How to draw/visualize/simulate to show the diffence between the two almost identical curves?by Black Mild on September 1, 2026 at 9:45 am
This question is related to an interesting question on mathSE. The blue curve $E$ is the ellipse $\left(\frac{4x}{\pi}\right)^2+\left(\frac{y}{\ln\left(\sqrt2+1\right)}\right)^2=1$ and the red curve $L$ is $y^2=\ln^2\left(\sqrt2\cos x-\sqrt{\cos(2x)}\right)$ are almost identical in shapes. So far several answers show that they are different (some 1/10000) but almost identical (it's still open for that exact value/measure of how different they are). Naturally we want to see the difference. The question is to draw/visualize/simulate how different they are. It's interesting in mathematics but challenging in drawing due to very small diffrences. I can draw them (the code below is a MWE); the below left is E over thicker L, the below right is L over a thicker E; however we can not see the difference. Any tools (tikz, pgfplot, asymptote, luadraw, julia, ...) are allowed (standalone can be integrated into LaTeX/beamer). I just think of f(x)-g(x), f(x)/g(x), ... then scale by 10000 in graph, but not yet clear and complete. Please explain some maths behind your way, if any. // https://asymptote.ualberta.ca/ // https://math.stackexchange.com/questions/5147646/why-is-this-curve-almost-an-ellipse-y2-ln2-left-sqrt2-cos-x-sqrt-cos2x/5148177 // The blue curve $E$ is the ellipse $\left(\frac{4x}{\pi}\right)^2+\left(\frac{y}{\ln\left(\sqrt2+1\right)}\right)^2=1$. import graph; usepackage("amsmath"); size(12cm); real a = pi/4; // \approx 0.7854 real b = log(sqrt(2)+1); // = arcsinh(1) \approx 0.8814 write(a); write(b); // The ellipse E real xE(real t) { return a*cos(t); } real yE(real t) { return b*sin(t); } // The curve L real yL_upper(real x) { // Tránh sai số dấu phẩy động lân cận nghiệm bằng hàm max real u = sqrt(max(cos(2*x), 0)); return log(u + sqrt(u^2 + 1)); } real yL_lower(real x) { return -yL_upper(x); } // draw on a picture with pen void draw_curve_E(picture pic=currentpicture, pen p) { draw(pic, graph(xE, yE, 0, 2*pi), p); } void draw_curve_L(picture pic=currentpicture, pen p) { path upper = graph(yL_upper, -a, a, operator ..); path lower = reverse(graph(yL_lower, -a, a, operator ..)); draw(pic, upper -- lower -- cycle, p); } pen penE = blue+1pt; pen penL = red+1pt; pen draw_first = opacity(.3) + 4pt; picture picaxes, picE, picL, picEL, picLE; real extra = .1; xaxis(picaxes, -a-extra, a+extra, gray); yaxis(picaxes, -b-extra, b+extra, gray); add(picE,picaxes); add(picL,picaxes); add(picEL,picaxes); add(picLE,picaxes); draw_curve_E(picE, penE); string sE=" \begin{minipage}[C]{6cm} \[ \left(\frac{4x}{\pi}\right)^2+ \left(\frac{y}{\ln(\sqrt2+1)}\right)^2=1 \] \begin{align*} a&=\pi/4 \approx 0.7854\\ b&=\ln(\sqrt2+1)\\ &=\operatorname{arsinh}(1)\approx0.8814 \end{align*} \[ \frac{x^2}{a^2}+\frac{y^2}{b^2}=1 \] \end{minipage}"; label(picE,Label(scale(.6)*sE,penE),(-a-extra,0),W); draw_curve_L(picL, penL); string sL=" \begin{minipage}[C]{6cm} $$y^2=\ln^2\left(\sqrt2\cos x-\sqrt{\cos(2x)}\right)$$ $$2\sin^2x +\sinh^2 y=1$$ \end{minipage}"; label(picL,Label(scale(.6)*sL,penL),(a+extra,0),E); draw_curve_E(picEL, penE + draw_first); draw_curve_L(picEL, penL); draw_curve_L(picLE, penL + draw_first); draw_curve_E(picLE, penE); real dx=1, dy=1.8; add(shift(-dx,0)*picE); add(shift(dx,0)*picL); add(shift(-dx,-2dy)*picEL); add(shift(dx,-2dy)*picLE); label("They are different but almost identical!",(0,-dy-.2)); label("How do we see their difference ?",(0,-2dy-b-.8)); //shipout(bbox(2mm,invisible)); shipout(bbox(2mm,Fill(.2yellow+.8white)));
- How to draw realistic, semi-3D chemistry glassware (volumetric flask) in pure TikZ?by user446526 on September 1, 2026 at 8:34 am
I am trying to recreate an educational chemistry diagram illustrating the dilution of a solution using pure TikZ. Here is the target image I want to emulate (specifically the realistic, glossy 3D look of the glassware and liquid): I have made an initial attempt at drawing the volumetric flask and adding some basic gradients to simulate a 3D effect and control the water level. Here is my current Minimal Working Example (MWE), which is stripped of all custom fonts and language packages, along with a screenshot of my current output: \documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture}[x=1cm, y=1cm] % Water level control \def\waterlevel{-0.5} % Main flask path \def\flaskpath{ (0,-2.115) .. controls (1.85,-2.0) and (0.2,-0.45) .. (0.225,-0.01) .. controls (0.15,1.95) and (0.25,1.55) .. (0.25,1.725) .. controls (0.175,2.15) and (0.3,2.15) .. (0.3,2.225) .. controls (0.2,2.35) and (-0.2,2.35) .. (-0.3,2.225) .. controls (-0.3,2.15) and (-0.175,2.15) .. (-0.25,1.725) .. controls (-0.25,1.55) and (-0.15,1.95) .. (-0.225,-0.01) .. controls (-0.2,-0.45) and (-1.85,-2.0) .. cycle } % 1. Flask glass (3D transparent background) \fill[left color=gray!10, right color=gray!30, middle color=white, opacity=0.4] \flaskpath; % 2. Liquid with 3D gradient \begin{scope} \clip \flaskpath; \fill[left color=blue!60!black, right color=blue!40, middle color=blue!15, opacity=0.85] (-2,-2.2) rectangle (2, \waterlevel); % Liquid surface line \draw[blue!80!black, thick, opacity=0.6] (-1, \waterlevel) -- (1, \waterlevel); \end{scope} % 3. Flask outline \draw[line width=1.3pt, color=black!75] \flaskpath; % 4. Top stopper/neck details \draw[line width=1.3pt, color=black!75] (-0.3,2.225) .. controls (-0.15,2.125) and (0.15,2.125) .. (0.3,2.225); \draw[line width=1.3pt, color=black!75] (-0.25,2.275) .. controls (-0.15,2.2) and (0.15,2.2) .. (0.25,2.275); \draw[line width=1.3pt, color=black!75, left color=gray!5, right color=gray!40, middle color=white] (0.25,2.275) .. controls (0.15,2.325) and (0.15,2.375) .. (0.175,2.425) .. controls (0.45,2.5) and (0.3,2.7) .. (0,2.675) .. controls (-0.3,2.7) and (-0.45,2.5) .. (-0.175,2.425) .. controls (-0.15,2.375) and (-0.15,2.325) .. (-0.25,2.275) .. controls (-0.1,2.325) and (0.1,2.325) .. (0.25,2.275); \draw[line width=1.3pt, color=black!75] (-0.25,2.625) .. controls (-0.15,2.575) and (0.15,2.575) .. (0.25,2.625); % 5. Calibration mark (red ring on the neck) \draw[line width=1pt, red!70!black] (-0.23, 1.2) .. controls (-0.1, 1.15) and (0.1, 1.15) .. (0.23, 1.2); \end{tikzpicture} \end{document} My question: How can I further improve the shading, highlights, and transparency of this TikZ code to closely match the professional, glossy 3D rendering seen in the target image? (Note: I am looking for a pure TikZ solution and prefer not to use pst-labo or external 3D software if possible).
- Circle with tkz-euclide and transform shape goes wrongby Sander on August 31, 2026 at 6:41 pm
I'm using tkz-euclide to draw a circle with center M through point A: \documentclass{article} \usepackage{tikz} \usepackage{tkz-base} \usepackage{tkz-euclide} \begin{document} \tikzset{ xaxe style/.style ={-}, yaxe style/.style ={-}, } \begin{tikzpicture}[scale=0.6, transform shape] \tkzInit[xmin=-3,xmax=7,ymin=-4,ymax=6] \tkzGrid[color=black!20](-3.5, -4.5)(7.5, 6.5) \tkzDrawX[left space=0.5, right space=0.5] \tkzDrawY[up space=0.5, down space=0.5] \tkzLabelX[orig=false] \tkzLabelY[orig=false] \tkzDefPoint(0,0){O} \tkzLabelPoint[below left=2pt](O){\(O\)} \tkzDefPoints{2/1/M, -2/-2/A} \tkzDrawCircle[draw=blue!80!black, line width=.75pt](M,A) \tkzDrawPoints[fill=black, size=4](M,A) \tkzLabelPoint[below left](A){\(A\)} \tkzLabelPoint[below right](M){\(M\)} \end{tikzpicture} \end{document} The result of this code is a circle with center M, but not through A: Apparently this is caused by using transform shape in combination with scale=0.6. When I remove transform shape everything works fine. Does anybody know how to make tkz-euclide draw the correct circle in combination with transform shape?
- Designing consistent, good-looking inline TikZ nodes for keyboard keys and menu itemsby Marco Moldenhauer on August 29, 2026 at 6:38 pm
I am creating my own inline TikZ commands for a Blender tutorial. So far, I have defined three commands: \KeyboardLetter{...} for keyboard letters, such as \KeyboardLetter{A} \KeyboardSymbol{...} for keyboard symbols, such as \KeyboardSymbol{\shift} \BlenderMenu{...} for Blender menu items, such as \BlenderMenu{Object Mode} My main requirement is that all three types of inline nodes should have the same height, regardless of their contents. I am not particularly happy with my current design (see the output below). How could I improve the design so that keyboard letters, keyboard symbols, and Blender menu items look like they belong to the same visual system? Maybe someone has a creative idea or a nice design suggestion? 🙂 my Code \documentclass{article} \usepackage{menukeys} \tikzset{ keystroke/.style={ draw=black!50, fill=yellow!20, %drop shadow={shadow xshift=0.15ex,shadow yshift=-0.15ex,fill=black,opacity=0.7}, rectangle, %rounded corners=0.8pt, inner xsep=1.5pt, inner ysep=1.5pt, line width=0.3pt, %minimum width=0.21cm, %minimum height=0.21cm, font=\sffamily\small, %text=blue!75!black, %anchor=south } } \newcommand*\KeyboardLetter[1]{% \tikz[baseline=(key.base)] % \node[keystroke](key) {#1} ;% } \newcommand*\KeyboardSymbol[1]{% \tikz[baseline=(key.base)]{% \node[keystroke,inner sep=1.5pt] (key) {\phantom{A}}; \node[ inner sep=0.8pt, transform shape, scale=0.75 ] at (key.center) {#1}; }% } \newcommand*\BlenderMenu[1]{% \tikz[baseline=(key.base)] % \node[% keystroke, %signal, fill=red!5 ](key) {#1} ;% } \begin{document} \KeyboardSymbol{\tab}\KeyboardLetter{A}\KeyboardLetter{P}\KeyboardLetter{=}\KeyboardSymbol{\shift}\KeyboardLetter{,}\BlenderMenu{Object Mode}\BlenderMenu{Edit Mode} \end{document} my Output
- How to put tikz node at top left in a picture fitting all the A4 document?by Manuel Selva on August 29, 2026 at 8:55 am
I have the following document : \documentclass[a4paper]{article} \usepackage[a4paper,margin=0cm,landscape]{geometry} \usepackage{tikz} \usetikzlibrary{fit} \begin{document} \begin{tikzpicture}[remember picture, overlay] \coordinate (nw) at (current page.north west); \coordinate (se) at (current page.south east); \node [fill=red!10, fit=(nw) (se), inner sep=0pt] {}; \node [rectangle,fill=green,draw=black, minimum width=3cm, minimum height=3cm,anchor=north west] at (0, 0) {Manu}; \end{tikzpicture} \end{document} The Manu green rectangle is not in the top left corner of the resulting document while the red background done using fit correctly fits all the page. Why is the green rectangle shifted ?
- How make a tikzpicture filling an A4 page?by Manuel Selva on August 29, 2026 at 6:49 am
I want to use tikz to draw a diagram and I want this diagram occupy all the A4 space of my document (so that I can print it then). How can I achieve this ? Here is what I have for now : \documentclass[a4paper]{article} \usepackage{tikz} \usetikzlibrary{fit} \begin{document} \begin{tikzpicture}[remember picture, overlay] \node [fill=blue, fit=(current page.north west) (current page.south east), inner sep=0pt] {}; \end{tikzpicture} \end{document} But my problem is that I want to have a landscape A4 paper. Adding : \usepackage[a4paper,margin=0in,landscape]{geometry} results in a blue rectangle occupying only part of the document. It seems that current page.north west and current page.south east are no more valid with landscape ?
- Relative paths in pgfkeys vs. usage in TikZby karlh on August 28, 2026 at 3:12 pm
This is more a curiosity (or bug report?) than it is an actual problem. That is, I know how to fix it/work around it, and I'm really asking about the design principle(s). Using \pgfkeys to set a key /pgf/bar is fine, but setting one /pgf/foo/bar will cause an error if the \pgf part is left off inside a TikZ path/node/etc. command: \documentclass{article} \usepackage{tikz} \pgfkeys{% /pgf/bar/.initial=1cm, /pgf/foo/bar/.initial=1cm, } \begin{document} \begin{tikzpicture} \path [bar=2cm] (0,0); \end{tikzpicture} \end{document} compare to \documentclass{article} \usepackage{tikz} \pgfkeys{% /pgf/bar/.initial=1cm, /pgf/foo/bar/.initial=1cm, } \begin{document} \begin{tikzpicture} \path [foo/bar=2cm] (0,0); \end{tikzpicture} \end{document} The latter gives the following error: ! Package pgfkeys Error: I do not know the key '/tikz/foo/bar', to which you passed '2cm', and I am going to ignore it. Perhaps you misspelled it. See the pgfkeys package documentation for explanation. Type H <return> for immediate help. ... l.13 \path [foo/bar=2cm] ( 0,0); ? Making the root path /tikz solves the problem, as does providing the full path /pgf/foo/bar, but given the statement in the TikZ documentation, section 12.4.1, I expected it to work: Is this supposed to work, or is there a reason this list is not followed when a slash is present in the key name?
- tikz pgfplot fill area between multiple graphs or pathsby paul_schaefer on August 27, 2026 at 12:22 pm
MWE: \documentclass[12pt,a4paper]{article} \usepackage[utf8]{inputenc} \usepackage{lmodern} \usepackage[ngerman]{babel} \usepackage{amsmath} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{tikz} \usetikzlibrary{arrows.meta} \usetikzlibrary{datavisualization.formats.functions} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \usepgfplotslibrary{fillbetween} \begin{document} \begin{tikzpicture}[scale=1] \begin{axis}[ axis equal, % axis line style=thick, axis x line=center, ylabel={$y$}, xlabel={$x$}, major tick style = {black}, axis y line=middle, every axis y label/.style={ at={(current axis.above origin)}, inner sep=3, anchor=north east, }, every axis x label/.style={ at={(current axis.right of origin)}, inner sep=3, anchor=north east, }, xtick={-1,1}, xticklabels={$-\frac{w}{2}$,$\frac{w}{2}$}, ytick={1}, yticklabels={$h$}, yticklabel style={anchor=south west}, xmin=-1.75, xmax=3.25, ymin=-0.1, ymax=1.5, height=4cm, samples=100] \addplot[domain=-1:1,thick, name path=A] {1 - x * x}; \addplot[domain=0.5:2.5,thick, name path=B] {1 - (x-1.5) * (x-1.5)}; \draw[name path=C, thin] (1/3,8/9) -- (1.5,1); \path [name path=D] (\pgfkeysvalueof{/pgfplots/xmin},0) -- (\pgfkeysvalueof{/pgfplots/xmax},0); \addplot[black!15] fill between[of=C and A, soft clip={domain=0:0.75}]; \addplot[black!15] fill between[of=C and B, soft clip={domain=0.75:1.5}]; \addplot[black!40] fill between[of=B and D, soft clip={domain=0.5:0.75}]; \addplot[black!40] fill between[of=A and D, soft clip={domain=0.75:1}]; \end{axis} \end{tikzpicture} \end{document} results in a graph, where the areas between the both graphs are filled in gray. In this example I splitted the areas into four sections and colored them. Is there a possibility to fill the areas without splitting them into sections? A second problem is, that the separation of each area into two parts will sometimes result in in slight white vertical line between the colored areas. In my case it depends on the scaling of the pdf viewer I use. If there area could be described without separation this should not happen.
- How to draw 3D animation of reflection of a triangle about the bisector?by Learner on August 26, 2026 at 6:50 pm
I want to plot a 3D animation of an equilateral triangle about one bisector. I have plotted the steps by using tikz: \documentclass[a4paper,11pt]{article} \usepackage{tikz} \usepackage[margin=1.2cm]{geometry} \usepackage{amsmath} \begin{document} \begin{tikzpicture}[x=1cm,y=1cm] % First triangle: \begin{scope}[shift={(0,0)}] \coordinate (A) at (0,2); \coordinate (B) at (-1.732,0); \coordinate (C) at (1.732,0); % Median = axis of reflection \draw[dashed,very thick] (0,0) -- (0,2); % Triangle \draw[thick] (A) -- (B) -- (C) -- cycle; % Vertex labels \node[above] at (A) {$A$}; \node[below left] at (B) {$B$}; \node[below right] at (C) {$C$}; % Element \node at (0,-0.7) {I}; \end{scope} %Arrow from first triangle to second triangle \draw[->,thick] (2.2,1) -- (5.8,1); \node at (4,1.2) {s}; \node at (4,0.5) {$(\text{reflection})$}; %second triangle \begin{scope}[shift={(8,0)}] \coordinate (A) at (0,2); \coordinate (B) at (-1.732,0); \coordinate (C) at (1.732,0); % Reflect in the vertical median \begin{scope}[xscale=-1] % Triangle \draw[thick] (A) -- (B) -- (C) -- cycle; % Vertex labels \node[above left] at (A) {$A$}; \node[below left] at (B) {$B$}; \node[below] at (C) {$C$}; \end{scope} % Reflection axis \draw[dashed,very thick] (0,0) -- (0,2); \node at (0,-1) {II}; \end{scope} \end{tikzpicture} \end{document} which gives the following two triangles: I want to plot a 3D animation to display the reflection about the bisector.I would appreciate to do that. The vertices B and C will be changing every time but A will remain fixed. Note that the first triangle and the last triangle are same.
- Interaction between drawing something in the background and a page of floatsby Werner on June 26, 2026 at 3:59 am
In the following setup, I have a couple of images that forms part of a very large figure. The float ends up on a page of floats (on its own), because of the size. I plan on drawing some elements in the background, simulated by the background fill being the example images via \AddToHookNext{shipout/background}{<background drawing>}: \documentclass{article} \usepackage{lipsum,tikz} \begin{document} \lipsum[1-2] \begin{figure} \centering \tikz [remember picture] \node [inner sep = 10pt] (image-a) {\includegraphics[width = 0.5\linewidth]{example-image-a}}; \bigskip \tikz [remember picture] \node [inner sep = 10pt] (image-b) {\includegraphics[width = 0.5\linewidth]{example-image-b}}; \bigskip \tikz [remember picture] \node [inner sep = 10pt] (image-c) {\includegraphics[width = 0.5\linewidth]{example-image-c}}; \caption{A large figure} \AddToHookNext{shipout/background}{% \begin{tikzpicture}[remember picture, overlay] \filldraw [draw = red, fill = red!10!white, thick] (image-a.south west) rectangle (image-a.north east); \filldraw [draw = blue, fill = blue!10!white, thick] (image-b.south west) rectangle (image-b.north east); \filldraw [draw = green, fill = green!10!white, thick] (image-c.south west) rectangle (image-c.north east); \end{tikzpicture}} \end{figure} \lipsum[3-10] \end{document} Using this approach, however, puts the background drawing on the page where the original figure is processed, rather than where the actual figure is placed. How can I adjust the code so that the background content is placed correctly on the page where the float ends up? Ideally I'd like to keep the code as part of the figure as it semantically belongs with the figure, rather than placing it at some other bizarre place in the document just to make sure it fits there.
- Draw a Möbius trip with normal vectors?by Gigi on October 21, 2024 at 3:41 pm
So, I have been trying to illustrate the fact that the Möbius band doesn't have a non-vanishing normal vector space. I was trying to replicate this kind of thing: Here is my code: \documentclass[12pt]{article} \usepackage{tikz} \usepackage{pgfplots} \pgfplotsset{compat=newest} \usepgfplotslibrary{colormaps} \usepgfplotslibrary{external} \tikzexternalize \usepackage{pgfplots} \pgfplotsset{compat=1.18} % Assure-toi que tu utilises la version appropriée \usepackage[margin=1in]{geometry} \geometry{ a4paper, left=25mm, right=25mm, top=10mm, bottom=15mm, } \usepackage{amsmath,amsthm,amssymb} \usepackage{graphicx} \newenvironment{statement}[2][Statement]{\begin{trivlist} \item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}} \begin{document} \begin{tikzpicture} \begin{axis}[ hide axis, view = {40}{40} ] \addplot3 [ surf, colormap={blackwhite}{gray(0cm)=(1); gray(1cm)=(0.5)}, shader = faceted interp,opacity = 0.7, samples = 40, samples y = 4, z buffer = sort, domain = 0:360, y domain =-0.5:0.5 ] ( {(1+0.5*y*cos(x/2)))*cos(x)}, {(1+0.5*y*cos(x/2)))*sin(x)}, {0.5*y*sin(x/2) +1 } ); % Draw the orange circle \addplot3 [ samples=50, domain=-145:180, samples y=0, thick, color=orange ] ( {cos(x)}, {sin(x)}, {1} ); % Add tangent vectors that rotate as they follow the twist of the Möbius strip \addplot3 [ quiver={ u={cos(x/2)*cos(x)}, % Tangent vector with twisting effect v={cos(x/2)*sin(x)}, % Tangent vector with twisting effect w={sin(x/2)}, % Vertical component from the Möbius strip's twist scale arrows=0.2, % Adjust size of arrows }, samples=15, % Number of arrows domain=-145:180, -stealth, % Arrow style color=blue, % Color of the tangent vectors ] ( {cos(x)}, {sin(x)}, {1} ); \end{axis} \end{tikzpicture} \end{document} As you can see, it is quite far from my goal. I would like to have all the normal vectors on the orange circle juste like the Geogebra example. I don't need multiple colours and 2 directions of vectors. One colour and one direction will suffice. I hope that you I am being clear and apologise in advance if it is not the case. Thank you all in advance for your help.
- How can I draw this in Latexby kuu huu on May 25, 2024 at 9:35 pm
How can I draw like this 1 The problem is how can I colorize shape 2 like figure below 1. \documentclass{standalone} \usepackage{amsmath} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{pgfplots} \usepackage{tikz,tikz-3dplot} \usetikzlibrary{shapes.geometric,arrows.meta,decorations.markings,angles,quotes} \pgfplotsset{compat = 1.17} \tikzset{declare function={x1=45;x2=60;x3=170;a=4.05;b=4;d=1; c=sqrt(a^2-b^2); h1(\u,\v)=(d*(c - a*cos(\u)*cos(\v)) + b^2*cos(\u))/(a - c*cos(\u)*cos(\v)); h2(\u,\v)=(b*sin(\u)*(a - d*cos(\v)))/(a - c*cos(\u)*cos(\v)); h3(\u,\v)=(b*sin(\v)*(c*cos(\u) - d))/(a - c*cos(\u)*cos(\v)); }} \tdplotsetmaincoords{70}{110} \begin{document} \begin{tikzpicture}[tdplot_main_coords,dotted/.style={dash pattern=on .03pt off 3pt,line cap=round}] \coordinate (O) at (0,0,0); \coordinate (F1) at (c,0,0); \coordinate (F2) at (-c,0,0); \draw[-latex,thick] (0,0,0)--(8,0,0) node[below left] {$x$}; \draw[-latex,thick] (0,0,0)--(0,8,0) node[right] {$y$}; \draw[-latex,thick] (0,0,0)--(0,0,8) node[above] {$z$}; \foreach \i in {0,90,...,360}{ \draw[thick] plot[variable=\x,domain=0:360,smooth,samples=71]({h1(\x,\i)},{h2(\x,\i)},{h3(\x,\i)}); } \foreach \j in {0,60,...,360}{ \draw[thick] plot[variable=\x,domain=0:360,smooth,samples=71]({h1(\j,\x)},{h2(\j,\x)},{h3(\j,\x)}); } \fill[blue] (F1) circle (2pt); \fill[red] (F2) circle (2pt); \end{tikzpicture} \end{document} The result is Edit by @Jasper The parametric surface is defined by x1=45;x2=60;x3=170;a=4.05;b=4;d=1; c=sqrt(a^2-b^2); h1(\u,\v)=(d*(c - a*cos(\u)*cos(\v)) + b^2*cos(\u))/(a - c*cos(\u)*cos(\v)); h2(\u,\v)=(b*sin(\u)*(a - d*cos(\v)))/(a - c*cos(\u)*cos(\v)); h3(\u,\v)=(b*sin(\v)*(c*cos(\u) - d))/(a - c*cos(\u)*cos(\v)); on a domain of 0:360 degrees for both variables. In this code, h1, h2, and h3 are the parametric functions for the surface. I have drawn black (I'm on a mac and don't know how to change the color) lines along the trajectories I was referring to in the bounty. - @Jasper
- Draw vector field on top of surface of spherical octant, but not in specific regionsby Johannes Nauta on February 9, 2024 at 1:40 pm
I am interested in drawing a vector-like field towards, or away from, a single point on the surface of a unit octant. If possible, I would like to constrain this to not occur within an area spanned by some paths. I have the following code in place that produces the image shown below. I furthermore highlighted what I would like. \documentclass[border=10pt]{standalone} \usepackage{tikz} \usepackage{tikz-3dplot} \usetikzlibrary{arrows.meta} \begin{document} \tdplotsetmaincoords{65}{120} \begin{tikzpicture}[ scale=2.5, tdplot_main_coords, Arrow/.style={-{Latex[scale=.7]}}, ] % Draw axes \draw[->] (0,0,0) -- (1.2,0,0) node[inner sep=0pt, below left] (r2) {$r_2$}; \draw[->] (0,0,0) -- (0,1.2,0) node[inner sep=0pt, below right] (r1) {$r_1$}; \draw[->] (0,0,0) -- (0,0,1.2) node[inner sep=0pt, above] (r3) {$r_3$}; % quarter circle on xy plane \draw[dashed] (1,0,0) arc (0:90:1); % -- (0,0,0) -- cycle; % quarter circle on xz plane \tdplotsetthetaplanecoords{0} \draw[dashed, tdplot_rotated_coords] (1,0,0) arc (0:90:1); % -- (0,0,0) -- cycle; % quarter circle on yz plane \tdplotsetthetaplanecoords{90} \draw[dashed, tdplot_rotated_coords] (1,0,0) arc (0:90:1); % -- (0,0,0) -- cycle; \node (A1) at (0.7,0.7,0.1) {}; \node (A2) at (0.7,0.1,0.7) {}; \node (A3) at (0.1,0.7,0.7) {}; % Draw triangle on surface with corners A1...A3 \draw[blue] (A1.center) edge[bend left] (A2.center); \draw[blue] (A2.center) edge[bend left] (A3.center); \draw[blue] (A3.center) edge[bend left] (A1.center); \end{tikzpicture} \end{document} This is what I currently have. This is what I'd like. If possible, I would like to keep it as simple as possible, but I understand that 3D coordinates bring with them some more complicated calculations. If there is also an external library that makes this far easier, I'd be more than happy to learn about it as well.
- Setting the directionality of \tdplotdrawarc in cartesian coordinatesby Heath on March 30, 2022 at 2:54 pm
I have an issue with regards to \tdplotdrawarc in TikZ. Consider the following snippet: \documentclass{article} \usepackage{tikz,tikz-3dplot} \usetikzlibrary{intersections,fadings,decorations.pathreplacing} % interesection is not needed %\usetikzlibrary{shadows.blur} \begin{document} \tdplotsetmaincoords{70}{110} \begin{tikzpicture}[tdplot_main_coords] \draw[thick,->] (0,0,0) -- (3,0,0) node[anchor=north east]{$x$}; \draw[thick,->] (0,0,0) -- (0,3,0) node[anchor=north west]{$y$}; \draw[thick,->] (0,0,0) -- (0,0,3) node[anchor=south]{$z$}; \pgfmathsetmacro{\ax}{1} \pgfmathsetmacro{\ay}{0} \pgfmathsetmacro{\az}{1} \pgfmathsetmacro{\axx}{0} \pgfmathsetmacro{\ayy}{1} \pgfmathsetmacro{\azz}{1} \draw[->,red, thick] (0,0,0) -- (1,1,1) node[anchor=west]{$\vec{n}$}; \draw[dashed,red] (0,0,0) -- (1,0,1); \draw[dashed,red] (0,0,0) -- (1,0,0) -- (1,0,1) -- (0,0,0); \draw[dashed, black] (0,0,0) -- (1,1,0) -- (1,1,1); \draw[dashed, black] (1,1,0) -- (1,0,0); \draw[fill=red,opacity=0.1] (-3,-3,0) -- (-3,3,0) -- (3,3,0) -- (3,-3,0) -- cycle; \tdplotdrawarc[tdplot_main_coords,->]{(0,0,0)}{1}{0} {45}{anchor=east}{$\alpha$} \end{tikzpicture} \end{document} which produces: What I would like to do is something like: but I do not want to use: \tdplotgetpolarcoords{\ax}{\ay}{\az} \tdplotsetthetaplanecoords{\tdplotresphi} \tdplotdrawarc[tdplot_rotated_coords]{(0,0,0)}{1}{0} {\tdplotrestheta}{anchor=east}{$\alpha$} to draw the arc, but stick to cartesian coordinates. Is this possible? And If so, how?
- Problem with TikZ 3D graphby Magform on May 16, 2021 at 2:08 pm
I want to draw a 3D graph in tikz; something like z=x/y, this is the code that I've written: \documentclass[tikz,border=5pt]{standalone} \usepackage{pgfplots} \begin{document} \begin{tikzpicture} \begin{axis} [ title = {Campo in funzione della forza e della carica}, xtick = {-12,-9,...,12}, ytick = {-9,-6,...,12}, xlabel = $\vec{F}$, ylabel = $q$, ticklabel style = {font = \scriptsize}, grid ] \addplot3 [surf, domain=-12:12, samples=50] { x/y }; \end{axis} \end{tikzpicture} \end{document} The problem is that where the graph shouldn't exist anyway it exists, I tried to solve the problem, maybe using asymptote instead of tikz but I still can't draw it.
- Polar triangle in TiKzby Averroes2 on April 1, 2021 at 8:54 am
I am trying to draw a spherical triangle $ABC$ and its polar counterpart $A'B'C'$ like in the picture Is this possible using TiKz. There was a similar question in TikZ - Spherical triangles but without answer.
- TikZ - Spherical trianglesby Averroes2 on April 1, 2021 at 7:13 am
I would like to draw this picture: The triangle ABC is a spherical one. How can I do this using TikZ?
- Plotting function ℝ² →ℝ with pole at (0,0) smoothlyby Wizard of Math on May 30, 2020 at 1:56 pm
I would like to plot the function f: ℝ² →ℝ, definited by f(x,y)=(xy)/(x^2+y^2). But the following problem comes up: At (0,0) the function is not continous and therefore it looks kind of jagged. To solve this problem i could force the function to input specific points but i can't find it anywhere an don't know if that is even possible. Code: \begin{tikzpicture}[] \begin{axis}[axis lines=center, axis on top, xtick=\empty, ytick=\empty, ztick=\empty, xrange=-2:2, yrange=-2:2 ] % function \addplot3[domain=-2:2,y domain=-2:2,colormap/viridis,surf,opacity=0.5,samples = 55] {(x*y)/(x^2+y^2)}; \end{axis} \end{tikzpicture} How do i make this function look smooth? Any help would be greatly appreciated 🙂 (Just increasing the Samples doesnt do that much, and I run into the following error: TeX capacity exceeded, sorry [main memory size=3000000])
- Tikz plotting 3dby Titanlord on May 15, 2020 at 3:05 pm
I'm trying to make a 3d plot with tikz, but I was not able to do it. I always get a rubbish messy chaos of lines heading into all directions. I wanted to plot f(x,y) = x^3 / y^2. I was able to do it with gnuplot: \begin{gnuplot} set terminal epslatex color set size 1,1 set isosamples 100 unset key set grid set xrange [-5:5] set yrange [-5:5] set zrange [-5:5] set hidden3d set view 62, 308, 1, 1 splot x**3 / y**2 lt rgb "red" \end{gnuplot} The result looks like this: This solution still has some problems. E.g. for the area around (0,0,0) there are very litte samples, so there is a lot of white space and the edges are spicky. My question: Is it even possibile to make this plot with tikz? Can the plot be smother and better looking for the area around (0,0,0)? If true, can you help me?
- Projective Plot of a elliptic curveby Titanlord on May 11, 2020 at 4:24 pm
I'm trying to plot a elliptic curve in a projective Space. I got inspired by this thread. Here one can find the code. Now the point is, that the author of the thread only plotted a 2d Version of an elliptic curve. I wanted to plot this 3d equation: z*y^2=x^3-3*x*z^2+3*z^3 ( This is the projective form of the affin equation y^2 = x^3 -3x + 3 ) It already was a big problem to find plotters only, that can handle this. I finally got this result: Can someone help me plotting this with using tikz?
- pgfplot renders jagged polynomialby JohnD on November 24, 2019 at 3:21 am
I keep getting a very jagged plot of this 9th degree polynomial, regardless of using smooth or increasing the sample points. Ideas? \documentclass{standalone} \usepackage{tikz} \usepackage{pgfplots} \pgfplotsset{compat=newest} \usetikzlibrary{fpu} \begin{document} \begin{tikzpicture}[scale=.55] \begin{axis}[ xlabel={$x$}, ylabel={$y$} ,restrict y to domain=-10^9:10^9 ,axis lines=middle ,samples=2000, %,grid ,thick ,domain=0:4 ,xtick={0,1,2,3,4} ,ytick={0,9} ,xmin=0 ,xmax=4.5 ,ymin=-1 ,ymax=1.8 ,xlabel shift={1in} ,y tick label style={yshift={5pt}} %,legend pos=outer north east ] \addplot+[black,no marks,smooth]{1.5*x + 3.83333*x^2 - 15.0104*x^3 + 22.7454*x^4 - 19.2028*x^5 + 9.37731*x^6 - 2.5978*x^7 + 0.377315*x^8 - 0.0222801*x^9}; \end{axis} \end{tikzpicture} \end{document}
- TikZ, 3D multiple layers with orthogonal lineby BowPark on April 10, 2018 at 3:28 pm
Using the TikZ 3D library, I would like to reproduce the following image: Some details: the planes have an arbitrary angle; they are parallel and opaque; the arrow segment is orthogonal to the plane surfaces. I only found examples with single figures, like this one or this one, but they didn't help here. What could be the correct approach to realize the above image?
- Tikz isn't plotting the right functionby John 545 on November 17, 2017 at 11:29 pm
Im trying to plot a probability function in tikz, but the line plotted isn't even close to how the function should look. Im new to using latex and I have no idea why this isnt working, unless tikz just cant handle this function. Here is my code: \documentclass{article} \usepackage{pgfplots} \usepackage{tikz} \begin{document} \begin{tikzpicture}[ declare function={Probability(\n,\k) = 1-((\n!)/((\n^(\k))*((\n- \k)!)));} ] \begin{axis}[ no markers, domain=0:15, samples=2500, axis lines=left, xlabel=$k$, ylabel=$y$, every axis y label/.style={at=(current axis.above origin),anchor=east}, every axis x label/.style={at=(current axis.right of origin),anchor=north}, height=10cm, width=15cm, xtick={0,2,4,6,8,10,12,14}, ytick={0.1,0.2,0.3,0.4,0.5,.6,.7,.8,.9,1}, enlargelimits=false, clip=false, axis on top, grid = major, xmax=15 ] \addplot [very thin,cyan!20!black] {Probability(10,x)}; \end{axis} \end{tikzpicture} \end{document} This is what the function should look like, And this is what tikz is plotting I would appreciate it if someone could point me in the right direction. Thanks
- tikz-3dplot: Find projection of a vector on a unitary sphereby UJIN on January 15, 2016 at 2:07 pm
I am using TikZ (with the 3dplot package) to draw figures that mostly represent vectors lying on 2-Spheres surfaces. I have to say I am a bit of a newbie with TikZ, but I think i got the basic concepts. In this MWE I am drawing a figure with 3 unitary length vectors m, n and l (with m orthogonal to both l and n). I also have a point x that lies on the "meridian" connecting m and l, and its orthogonal projection xp on the n,m plane. \documentclass{article} \usepackage{tikz} \usepackage{tikz-3dplot} \begin{document} \begin{figure}[ht] \centering \tdplotsetmaincoords{70}{135} \pgfmathsetmacro{\rvec}{1} \pgfmathsetmacro{\thetavec}{320} \pgfmathsetmacro{\phivec}{240} \begin{tikzpicture}[tdplot_main_coords, scale=8] \coordinate (O) at (0,0,0); \draw[thick,->] (O) -- (0,\rvec,0) node[anchor=north west]{$\mathbf{n}$}; \draw[thick,->] (O) -- (0,0,\rvec) node[anchor=south]{$\mathbf{m}$}; \tdplotsetcoord{X}{\rvec}{\thetavec}{\phivec}; \tdplotsetcoord{L}{\rvec}{270}{\phivec} \draw[thick,->] (O) -- (X) node[anchor=east]{$\mathbf{x}$}; \draw[thick,->] (O) -- (L) node[anchor=east]{$\mathbf{l}$}; \draw[thick,->] (O) -- (Xyz) node[anchor=south east]{$\mathbf{x_p}$}; \draw[dashed] (X) -- (Xyz); \tdplotsetthetaplanecoords{90}; \tdplotdrawarc[tdplot_rotated_coords, style=dashed]{(O)}{\rvec}{0}{90}{}{}; \tdplotsetthetaplanecoords{\phivec}; \tdplotdrawarc[tdplot_rotated_coords, style=dashed]{(O)}{\rvec}{-90}{0}{}{}; \end{tikzpicture} \end{figure} \end{document} My question is: Is it possible to draw a line that connects xp to its projection on the sphere? Or, alternatively, a line that starts from the origin and stops at the projection of xp on the sphere? In another context I would have simply L2-normalized xp to unitary lenght, but in TikZ this doesn't seem to be a viable option (correct me if I'm wrong). For a better understanding, the picture shows what I am looking for: that really ugly red segment. Thank you for your time and sorry for the occasionally bad English!
- TiKz. Angle between two vectors and a projectionby JUAN G R on September 12, 2015 at 9:16 am
I'm having trouble to draw something with TiKz. What I want to draw I think is simple: SIM is a vector in the YZ-plane with a Beta = 38º, source is just a random vector with positive x and y components and negative z. Theta is the angle between SIM and source vectors and Phi is the angle formed by the source projection in the XZ-plane with the X-axis. Thanks a lot in advance
- Special decoration for TikZ pin featureby Chris on June 15, 2014 at 9:37 am
I try to achieve the curvy pin style I sketched below. It would help to distinguish pin lines from grid and other lines in the diagram. How can I realize a decoration that automatically draws such a curve? How can I integrate this with the pin feature? The code for the picture: \documentclass[tikz,convert]{standalone} \usepackage{pgfplots} \begin{document} \begin{tikzpicture}[ pin distance=5mm, every pin edge/.style={ decorate, decoration={ snake, pre length=4pt } } ] \begin{axis}[ width=12cm, height=5cm, xmin=0,xmax=4, ] \addplot coordinates {(1,1) (3,3)} coordinate [pos=.5] (a) coordinate [pos=.7] (b); \node [pin=135:From the manual] at (a) {}; \path (a) ++(-45:1cm) node (c) {What I want}; \draw [gray] (c) to[out=110,in=-70] (a); \path (b) ++(-45:.8cm) node [right] (d) {What I want II}; \draw [gray] (d.west) to[out=160,in=-20] (b); \end{axis} \end{tikzpicture} \end{document} (I tagged with pgfplots as well since this would be a common application.)
- 2D and 3D vectors in Tikzby alexT on March 7, 2014 at 5:08 am
I would like to draw some 2D and 3D vectors in Tikz with certain properties. The following primitive graph sums what I desire: I just need the first quadrant of the Cartesian coordinate system for my representation. I need the vector to be connected to the respective values on the distinct dimensions(not a projection, just orthogonal dashed lines). The code segment below does what I want to achieve in 3D with two exceptions: The projections on the xy plane and z dimension are given instead of connecting the head of the vector to the corresponding value in each dimension. Numerical values are missing in dimensions. Code: \documentclass[tikz]{standalone} \usepackage{tikz-3dplot} \begin{document} \tdplotsetmaincoords{60}{120} \begin{tikzpicture} [scale=3, tdplot_main_coords, axis/.style={->,blue,thick}, vector/.style={-stealth,red,very thick}, vector guide/.style={dashed,red,thick}] %standard tikz coordinate definition using x, y, z coords \coordinate (O) at (0,0,0); %tikz-3dplot coordinate definition using r, theta, phi coords \tdplotsetcoord{P}{.8}{55}{60} %draw axes \draw[axis] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$}; \draw[axis] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$}; \draw[axis] (0,0,0) -- (0,0,1) node[anchor=south]{$z$}; %draw a vector from O to P \draw[vector] (O) -- (P); %draw guide lines to components \draw[vector guide] (O) -- (Pxy); \draw[vector guide] (Pxy) -- (P); \end{tikzpicture} \end{document}
- How to draw spherical triangles?by Rani on August 25, 2013 at 5:37 am
Does anyone know how to draw spherical arcs and spherical triangles using LaTeX?
- Moebius Strip using TikZby Dox on June 10, 2013 at 11:19 pm
I'm wondering whether is possible to draw a Moebius Strip using TikZ. The closest thing I've seen is in Texamples' page, but no luck so far! Do you have any ideas? I don't even have a MWE (sorry)
- How to speed up LaTeX compilation with several TikZ pictures?by Łukasz Lew on July 26, 2010 at 7:43 pm
The slowest part is a dozen of diagrams in TikZ.