Playing around with some methods to create a tangent to a circle of ellipse. Used to create cones in some jet figures.
Known radius r (or a, b) & distance q = |OQ|
% TANGENT to CIRCLE - known: r, q\usetikzlibrary{calc}\begin{tikzpicture}\def\r{1.5} % radius\def\q{4} % distance center-external point q = |OQ|\def\x{{\r^2/\q}} % Q x coordinate\def\y{{\r*sqrt(1-(\r/\q)^2}} % Q y coordinate\coordinate (O) at (0,0); % circle center O\coordinate (Q) at (\q,0); % external point Q\coordinate (P) at (\x,\y); % point of tangency, P\draw[->] (0,-1.3*\r) -- (0,1.5*\r);\draw[->] (-1.3*\r,0) -- (\q+0.4*\r,0);\draw[dashed] (\x,0) |- (0,\y);\draw[blue,thick] (O) circle(\r);\draw[green,thick] ($(Q)!-0.2!(P)$) -- ($(Q)!1.3!(P)$);\draw[green,thick] ($(O)!-0.3!(P)$) -- ($(O)!1.4!(P)$);\fill[red] (O) circle(0.05) node[below right] {O};\fill[red] (Q) circle(0.05) node[below left] {Q};\fill[red] (P) circle(0.05) node[above=3,right=4] {P};\end{tikzpicture}% TANGENT to ELLIPSE - known: a, b, q\begin{tikzpicture}\def\a{1.5} % horizontal radius\def\b{1.0} % vertical radius\def\q{4} % distance center-external point q = |OQ|\def\x{{\a^2/\q}} % x coordinate P\def\y{{\b*sqrt(1-(\a/\q)^2}} % y coordinate P\coordinate (O) at (0,0); % circle center O\coordinate (Q) at (\q,0); % external point Q\coordinate (P) at (\x,\y); % point of tangency, P\draw[->] (0,-\b-0.3*\a) -- (0,\b+0.4*\a);\draw[->] (-1.3*\a,0) -- (\q+0.4*\a,0);\draw[dashed] (\x,0) |- (0,\y);\draw[blue,thick] (O) ellipse({\a} and {\b});\draw[green,thick] ($(Q)!-0.2!(P)$) -- ($(Q)!1.3!(P)$);\draw[green,thick] ($(O)!-0.3!(P)$) -- ($(O)!1.4!(P)$);\fill[red] (O) circle(0.05) node[below right] {O};\fill[red] (Q) circle(0.05) node[below left] {Q};\fill[red] (P) circle(0.05) node[above=3,right=4] {P};\end{tikzpicture}
Known radius r (or a, b) & angle α
% TANGENT to CIRCLE - known: r, alpha\usetikzlibrary{calc}\usetikzlibrary{math} % for \tikzmath\usetikzlibrary{angles,quotes} % for pic (angle labels)\begin{tikzpicture}\def\r{1.5} % radius\def\ang{25} % alpha angle\def\q{\r/sin(\ang)} % distance center-external point q = |OQ|\coordinate (O) at (0,0); % circle center O\coordinate (Q) at ({\q},0); % external point Q\coordinate (P) at (90-\ang:\r); % point of tangency, P\draw[->] (0,-1.3*\r) -- (0,1.5*\r);\draw[->] (-1.3*\r,0) -- ({\q+0.4*\r},0);\draw[dashed] ({\r*sin(\ang)},0) |- (0,{\r*cos(\ang)});\draw[blue,thick] (O) circle(\r);\draw[green,thick] ($(Q)!-0.2!(P)$) -- ($(Q)!1.3!(P)$);\draw[green,thick] ($(O)!-0.3!(P)$) -- ($(O)!1.4!(P)$);\fill[red] (O) circle(0.05) node[below right] {O};\fill[red] (Q) circle(0.05) node[below left] {Q};\fill[red] (P) circle(0.05) node[above=3,right=4] {P};\draw pic[<-,"$\alpha$"{above=1,left=0},draw=black,angle radius=28,angle eccentricity=1.0]{angle = P--Q--O};\end{tikzpicture}% TANGENT to ELLIPSE - known: a, b, alpha\begin{tikzpicture}\def\a{1.5} % horizontal radius\def\b{1.0} % vertical radius\def\ang{25} % alpha angle\def\q{\a/sin(\ang)} % distance center-external point q = |OQ|\coordinate (O) at (0,0); % circle center O\coordinate (Q) at ({\q},0); % external point Q\coordinate (P) at (90-\ang:{\a} and {\b}); % point of tangency, P\draw[->] (0,-\b-0.3*\a) -- (0,\b+0.5*\a);\draw[->] (-1.3*\a,0) -- ({\q+0.4*\a},0);\draw[dashed] ({\a*sin(\ang)},0) |- (0,{\b*cos(\ang)});\draw[blue,thick] (O) ellipse({\a} and {\b});\draw[green,thick] ($(Q)!-0.2!(P)$) -- ($(Q)!1.3!(P)$);\draw[green,thick] ($(O)!-0.3!(P)$) -- ($(O)!1.4!(P)$);\fill[red] (O) circle(0.05) node[below right] {O};\fill[red] (Q) circle(0.05) node[below left] {Q};
Known vector & angle α
Cones given by vector and opening angle α
Edit and compile if you like:
% Author: Izaak Neutelings (May 2021)% Description:% Experimenting with finding the tangent to an ellipse% with the purpose of finding a nice way to draw a 3D cone.\documentclass[border=3pt,tikz]{standalone}\usepackage{amsmath}\usepackage{mathtools} % for \eqcolon\usepackage{physics}\usepackage{siunitx}\usepackage{xcolor}\usepackage{etoolbox} %ifthen\usepackage[outline]{contour} % glow around text\usetikzlibrary{calc}\usetikzlibrary{math} % for \tikzmath\usetikzlibrary{angles,quotes} % for pic (angle labels)\tikzset{>=latex} % for LaTeX arrow head\contourlength{1.6pt}\colorlet{myblue}{blue!70!black}\colorlet{mygreen}{green!40!black}\colorlet{myred}{red!65!black}\tikzstyle{vector}=[->,very thick,myblue,line cap=round]\tikzstyle{cone}=[thin,blue!50!black,fill=blue!50!black!30,fill opacity=0.8]\newcommand\rightAngle[4]{\pgfmathanglebetweenpoints{\pgfpointanchor{#2}{center}}{\pgfpointanchor{#3}{center}}\coordinate (tmpRA) at ($(#2)+(\pgfmathresult+45:#4)$);%\draw[white,line width=0.6] ($(#2)!(tmpRA)!(#1)$) -- (tmpRA) -- ($(#2)!(tmpRA)!(#3)$);\draw[blue!40!black] ($(#2)!(tmpRA)!(#1)$) -- (tmpRA) -- ($(#2)!(tmpRA)!(#3)$);}\begin{document}% TANGENT to CIRCLE - known: r, q\begin{tikzpicture}\def\r{1.5} % radius\def\q{4} % distance center-external point q = |OQ|\def\x{{\r^2/\q}} % Q x coordinate\def\y{{\r*sqrt(1-(\r/\q)^2}} % Q y coordinate
Click to download: circle_tangent.tex • circle_tangent.pdf
Open in Overleaf: circle_tangent.tex
FYI, I tried compiling this code in overleaf as well as my local installation (This is pdfTeX, Version 3.141592653-2.6-1.40.26 (TeX Live 2024) (preloaded format=pdflatex))
I get this error message
The compiler is having trouble understanding a command you have used. Check that the command is spelled correctly. If the command is part of a package, make sure you have included the package in your preamble using \usepackage{…}.
Learn more
\C ->\ERROR
l.190 }
The control sequence at the end of the top line
of your error message was never \def’ed. If you have
misspelled it (e.g., `\hobx’), type `I’ and the correct
spelling (e.g., `I\hbox’). Otherwise just continue,
and I’ll forget about whatever was undefined.
Hi Troy,
Thanks for reporting this!
I cannot reproduce it on my own local installation (pdfTeX, Version 3.141592653-2.6-1.40.24 via TeX Live 2022), but I can reproduce it on this webpage. I could solve it by simply renaming
\C
in each\tikzmath
(and consequently all derived\Cx
,\Cy
) to whatever else (\c
,\foo
, …). Not sure why the installation of some compilers choke on\C
, but can you try, please? I’ll update the code on this page later.Cheers,
Izaak
Hi Troy,
After playing around with it, I think the issue is caused by the using the
siunitx
package, which includes a\C
definition for Coulomb units. You can try for yourself:
I fixed it in the post by replacing
\C
with\v
everywhere.Cheers,
Izaak