7

enter image description here

Problem in short: The ellipse-arc should lie around Z and should start and end at the brown lines...


I want to draw circle-arcs and ellipse-arcs around a center-point.

So I use the syntax (TikZ-manual 2.10, page 36)

\draw[]([shift=(\wStart:\r)]Z) arc[start angle=\wStart, end angle=\wEnd, radius=\r];

with defined values \wStart, \wEnd, \r and a middlepoint-coordinate Z (which is not necessarily (0,0)) for circle-arcs and this works

For ellipse-arcs I use the syntax written in the TikZ-manual 2.10, page 37

\draw[red] ([shift=(\wStart:\rx)]Z) arc [start angle=\wStart, end angle=\wEnd, x radius=\rx, y radius=\ry];

in the following MWE.

But it seems my "center-shift" is wrong or it does not work (and maybe (?) start- and end-angle seems to be not correct).

What do I have to do?

BTW: I saw this thread (do not get the correct result with his methode), but I would like to fix the TikZ-syntax.

enter image description here

The ellipse-arc should start and end at the brown lines...

\documentclass[tikz, margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}[gridded]
% Center
\coordinate[label=below:Z] (Z) at (0,0);
\fill[] (Z) circle[radius=2pt];

% Values =============== \def\rx{1.75} \def\ry{1}

\def\r{\rx}

\def\wStart{20} \def\wEnd{315} % ====================

% Help lines \draw[brown] (Z) -- (\wStart:\r); \draw[brown] (Z) -- (\wEnd:\r);

% Full circle and ellipse \draw[] (Z) circle[radius=\r]; \draw[] (Z) circle[x radius=\rx, y radius=\ry];

% cirlce arc \draw[blue] ([shift=(\wStart:\r)]Z) arc [start angle=\wStart, end angle=\wEnd, radius=\r] node[near start]{good};

% ellipse arc \draw[red] ([shift=(\wStart:\rx)]Z) arc [start angle=\wStart, end angle=\wEnd, x radius=\rx, y radius=\ry] node[near start]{bad}; \end{tikzpicture} \end{document}

cis
  • 8,073
  • 1
  • 16
  • 45
  • 1
    A point (α:rx and ry) isn't on the line from the origin to (α:Rx). You're going to have to find the point and the angle mathematically or let intersections/spath3 find it for you. – Qrrbrbirlbel Dec 30 '23 at 11:45
  • @Qrrbrbirlbel I see. Would be nice to use the original TikZ-syntax with some needed math-inputs. But I tried many calculations, and I don't get the correct. So I was using a 'plot' with standard-formulas for the first (in my answer) – cis Dec 30 '23 at 11:49

7 Answers7

6

For another approach, you can apply a scale, draw an arc and compute the new angles:

\pgfmathsetmacro\myscale{\ry/\rx}
\pgfmathsetmacro\wStartE{atan(tan(\wStart)/\myscale)}
\pgfmathsetmacro\wEndE{360+atan(tan(\wEnd)/\myscale)}

A complete example could be:

\documentclass[tikz, margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}[gridded]
% Center
\coordinate[label=below:Z] (Z) at (0,0);
\fill[] (Z) circle[radius=2pt];

% Values =============== \def\rx{1.75} \def\ry{1} \def\r{\rx} \def\wStart{20} \def\wEnd{315}

% Scale and new angles \pgfmathsetmacro\myscale{\ry/\rx} \pgfmathsetmacro\wStartE{atan(tan(\wStart)/\myscale)} \pgfmathsetmacro\wEndE{360+atan(tan(\wEnd)/\myscale)} % ====================

% Help lines \draw[brown] (Z) -- (\wStart:\r); \draw[brown] (Z) -- (\wEnd:\r);

% Full circle and ellipse \draw[] (Z) circle[radius=\r]; \draw[] (Z) circle[x radius=\rx, y radius=\ry];

% cirlce arc \draw[blue] ([shift=(\wStart:\r)]Z) arc [start angle=\wStart, end angle=\wEnd, radius=\r] node[near start]{good};

% ellipse arc \draw[red,yscale=\myscale] ([shift=(\wStartE:\r)]Z) arc [start angle=\wStartE, end angle=\wEndE, radius=\r] node[near start]{good?}; \end{tikzpicture} \end{document}

enter image description here

Juan Castaño
  • 28,426
  • 2
    Yes, “good” :() I think this is the solution in terms of the task. – cis Dec 30 '23 at 12:15
  • 1
    Instead of yscale one should also be able to use x radius and y radius. But phew: my head is spinning right now. – cis Dec 30 '23 at 12:21
6

With tkz-elements requires compilation with lualatex

Edit: With Qrrbrbirlbel's comment, I use the clip that adapts to the situation

Edit2: With Alain Matthes'comment, we can read in the tkz-elements documentation:

set_lua_to_tex. You need to proceed with care, because unfortunately at the moment, the macros you create are global and you can overwrite existing macros. One solution is either to choose a macro name that won’t cause any problems, or to save the initial macro.

% !TeX TS-program = lualatex
\documentclass{standalone}

\usepackage{tkz-elements} \usepackage{tkz-euclide}

\begin{document} \begin{tkzelements} rx = value(1.75) ry = value(1) wStart = 20 wEnd = 315 z.Z = point: new (0 , 0) z.A = point: new (0 , rx)-- to draw the circle -- c = circle : new (z.Z,z.A) e = ellipse: radii (z.Z,rx,ry,0) -- z.Sp = point : polar_deg(rx,wStart) L.ZSp = line : new ( z.Z , z.Sp ) if wStart <180 then z.S,_ = intersection (e,L.ZSp)-- Start point else ,z.S = intersection (e,L.ZSp) end --
z.Ep = point : polar_deg(rx,wEnd) L.ZEp = line : new ( z.Z , z.Ep ) if wEnd <180 then z.E,
= intersection (e,L.ZEp)-- End point else _,z.E = intersection (e,L.ZEp) end -- -- set_lua_to_tex{"rx","ry","wStart","wEnd"}-- see Alain Matthes'comment \end{tkzelements} \begin{tikzpicture}[gridded] % Edit2 \newcommand{\rx}{\tkzUseLua{rx}} \newcommand{\ry}{\tkzUseLua{ry}} \newcommand{\wStart}{\tkzUseLua{wStart}} \newcommand{\wEnd}{\tkzUseLua{wEnd}} % \tkzGetNodes \tkzDrawPoints(Z,S,S',E,E') \tkzLabelPoints(Z) \tkzDrawCircleblue %\draw[green!70!black] (Z) -- +(\wStart:2\rx) arc[start angle=\wStart, end angle=\wEnd, radius=2\rx] -- cycle; \begin{scope} % With Qrrbrbirlbel's comment \clip overlay -- +(\wStart:2\rx) arc[start angle=\wStart, end angle=\wEnd, radius=2\rx] -- cycle; % \tkzDrawEllipsered \end{scope} \tkzDrawSegments[brown](S,Z Z,E) \tkzDrawSegments[brown,dashed](S,S' E,E') \end{tikzpicture} \end{document}

enter image description here

pascal974
  • 4,652
4

I fear, this could become a hard work, to "hack the TikZ-ellipse", so I used Polar form relative to center and then a plot:

enter image description here

\documentclass[tikz, margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}[gridded,
]
% Values ===============
\def\rx{1.75}
\def\ry{1}

\def\r{\rx}

\def\wStart{20} \def\wEnd{315} % ====================

% Center \coordinate[label=below:{(0,0)}] (O) at (0,0); \coordinate[label=below:Z] (Z) at (1.3,2); \foreach \P in {O,Z} \fill[] (\P) circle[radius=2pt];

% Help lines \draw[brown] (Z) -- +(\wStart:\r); \draw[brown] (Z) -- +(\wEnd:\r);

% Full circle and ellipse \draw[] (Z) circle[radius=\r]; \draw[] (Z) ellipse[x radius=\rx, y radius=\ry];

% circle arc \draw[blue] ([shift=(\wStart:\rx)]Z) arc [start angle=\wStart, end angle=\wEnd, radius=\r];

% ellipse arc \tikzset{% https://en.wikipedia.org/wiki/Ellipse#Polar_form_relative_to_center declare function={ E=sqrt(\rx^2-\ry^2)/\rx; PolarEllipse(\x)=\ry/sqrt(1-E^2*cos(\x)^2); }, }%

\draw[red, very thick, domain=\wStart:\wEnd, samples=111 ] plot ([shift={(Z)}]\x:{PolarEllipse(\x)}); \end{tikzpicture} \end{document}

cis
  • 8,073
  • 1
  • 16
  • 45
4

I like value-keys over macros but essentially, this uses the PGFMath function ellAngle to find the angle for the ellipse function while a few other PGFMath functions are used that simply map to a value-key. The functions maxRadius and minRadius evaluate the value-keys x radius and y radius.

This means the arcs can be drawn via

\begin{scope}[shift=(Z)]
\draw[green] (sAngle:maxRadius) arc [big   circle];
\draw[blue]  (sAngle:minRadius) arc [small circle];
\draw[red]   (ellAngle sAngle:xRadius and yRadius)
              arc [start angle ell, end angle ell];
\end{scope}

Applying shift=(Z) before the paths allows us to remove the shift operations from the paths making the input somewhat cleaner. (\draw[shift=(Z), …] …; would work, too.)

The keys small circle and big circle install minRadius and maxRadius while start angle ell and end angle ell apply the ellAngle function on their parameters (which default to the value-keys start angle and end angle).


With my answer to TikZ: using the ellipse command with a start and end angle instead of an arc this can be written as

\begin{scope}[shift=(Z), arc starts=after moveto]
\draw[green] arc [big   circle];
\draw[blue]  arc [small circle];
\draw[red]   arc [start angle ell, end angle ell];
\end{scope}

removing the need for sAngle.

I'm also using the bbox library and its bezier bounding box key to get accurate bounding boxes for the arcs.

Code

\documentclass[tikz, margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{backgrounds, bbox}
\tikzset{
  big   circle/.style={radius/.evaluated=maxRadius},
  small circle/.style={radius/.evaluated=minRadius},
  declare function={
    ellAngle(\x)=atan(xRadius/yRadius*tan(\x))+ellAngleCorr(mod(\x,360));
    ellAngleCorr(\x)=ifthenelse(\x>270,360,ifthenelse(\x>90,180,0));},
  start angle ell/.style={start angle/.expanded={ellAngle(#1)}}, start angle ell/.default=\pgfkeysvalueof{/tikz/start angle},
  end   angle ell/.style={end   angle/.expanded={ellAngle(#1)}}, end   angle ell/.default=\pgfkeysvalueof{/tikz/end   angle},
  @/.code args={#1>#2}{\pgfmathdeclarefunction{#1}{0}{\pgfmathparse{\pgfkeysvalueof{/tikz/#2}}}},
  @/.list={xRadius>x radius, yRadius>y radius, sAngle>start angle, eAngle>end angle}}
\pgfmathdeclarefunction{maxRadius}{0}{\pgfmathmax{\pgfkeysvalueof{/tikz/x radius}}{\pgfkeysvalueof{/tikz/y radius}}}
\pgfmathdeclarefunction{minRadius}{0}{\pgfmathmin{\pgfkeysvalueof{/tikz/x radius}}{\pgfkeysvalueof{/tikz/y radius}}}

\begin{document} \begin{tikzpicture}[ gridded, x radius=1.75, y radius=1, start angle=20, end angle=315] % Center \coordinate[label=below:Z] (Z) at (0,0); \fill[] (Z) circle[radius=2pt];

% Help lines \draw[brown] (Z) -- (sAngle:maxRadius); \draw[brown] (Z) -- (eAngle:maxRadius);

% Full circle and ellipse \draw[] (Z) circle[big circle]; \draw[] (Z) circle[]; \draw[] (Z) circle[small circle];

% Arcs \begin{scope}[shift=(Z), bezier bounding box] \draw[green] (sAngle:maxRadius) arc [big circle]; \draw[blue] (sAngle:minRadius) arc [small circle]; \draw[red] (ellAngle sAngle:xRadius and yRadius) arc [start angle ell, end angle ell]; \end{scope} \end{tikzpicture} \end{document}

Output

enter image description here

Qrrbrbirlbel
  • 119,821
  • 1
    ellAngle(90) and ellAngle(270) will fail with an error, of course, but for those angles, the function isn't needed (nor is it for 0° and 180°). – Qrrbrbirlbel Dec 30 '23 at 13:24
4

Just for fun: This uses cicles and ellipses and clips the part not wanted. Note the use of -| (\r,0) |- to extend the clipped area to the border.

\documentclass[tikz, margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}[gridded]
% Center
\coordinate[label=below:Z] (Z) at (0,0);
\fill[] (Z) circle[radius=2pt];

% Values =============== \def\rx{1.75} \def\ry{1}

\def\r{\rx}

\def\wStart{20} \def\wEnd{315} % ====================

% Help lines \draw[brown] (Z) -- (\wStart:\r); \draw[brown] (Z) -- (\wEnd:\r);

% Full circle and ellipse \draw[] (Z) circle[radius=\r]; \draw[] (Z) circle[x radius=\rx, y radius=\ry];

% cirlce arc \begin{scope}[even odd rule] \clip (-\r,-\r) rectangle (\r,\r)% clip exterior (\wStart:2) -- (Z) -- (\wEnd:2) -| (\r,0) |- cycle;% clip interior \draw[blue] (Z) circle [radius=\r];

% ellipse arc \draw[red] (Z) ellipse [x radius=\rx, y radius=\ry]; \end{scope} \end{tikzpicture} \end{document}

John Kormylo
  • 79,712
  • 3
  • 50
  • 120
  • 3
    Yes, let the PDF viewer do the math! Though, just clipping the arc seems easier: \clip[overlay] (Z) -- +(\wStart:2*\r) arc[start angle=\wStart, end angle=\wEnd, radius=2*\r] -- cycle; – Qrrbrbirlbel Dec 30 '23 at 17:07
1

Unfortunately the arc operation doesn't work always as one would expect, see Ch. "14.7 The Arc Operation". To further complicate things your end points weren't always right, which you can see when varying the Z-coordinate.

Here's a way to do it, using Jake's solution, who introduced a partial ellipse. The problem is that the starting point of your arc lies on an ellipse, not on a circle, which shifts it, upwards in this case.

The angles (brown lines) are fine for multiples of 90deg, and not right else, so there's a residual problem to solve.

result

\documentclass[tikz, margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\begin{document}
 \tikzset{
    partial ellipse/.style args={#1:#2:#3}{
        insert path={+ (#1:#3) arc (#1:#2:#3)}
    }
 }
 \begin{tikzpicture}[gridded]
    % Center
    \coordinate[label=below:Z] (Z) at (10,0);% <<< let's play with this
    \fill[] (Z) circle[radius=2pt];
% Values ===============
\def\rx{1.75}
\def\ry{1}

\def\r{\rx}

% ~~~ needed for partial ellipse ~~~
\def\ell{1.75cm and 1cm}

\def\wStart{20}
\def\wEnd{315}
% ====================

% Help lines
% !!! wrong end points ~~~~~~~~~~~~~~~~~~~~
\draw[brown] (Z) -- ([shift=(\wStart:\r)]Z);%(\wStart:\r);
\draw[brown] (Z) -- ([shift=(\wEnd:\r)]Z);%(\wEnd:\r);

% Full circle and ellipse
\draw[]       (Z) circle[radius=\r];
\draw[dashed] (Z) circle[x radius=\rx, y radius=\ry];

% cirlce arc
\draw[blue] ([shift=(\wStart:\r)]Z) arc [start angle=\wStart, end angle=\wEnd, radius=\r] node[near start]{good};

%   % ellipse arc --- this leads to nothing
%   \draw[red] ([shift=(0:\rx)]Z) 
%%      arc [start angle=\wStart, end angle=\wEnd, x radius=\rx, y radius=\ry]
%       arc [start angle=30, delta angle=180,x radius=\rx, y radius=\ry]
%       node[near start]{bad};

% partial ellipse
% found at https://tex.stackexchange.com/a/123187/245790
\draw[red] (Z) [partial ellipse=\wStart:\wEnd:\ell];

\end{tikzpicture} \end{document}

MS-SPO
  • 11,519
  • 1
    Do you say me: there is no way? Because: the ellipse-arc should start and end at the brown lines... and you haven't got that too. Mmmmhh... I think the angles have to be corrected (by a pgfmath-term); but I am not sure... – cis Dec 30 '23 at 10:10
  • No, there is certainly a way, but in a region, I've never investigated before. I suggest searching this site a little bit more than I did. – MS-SPO Dec 30 '23 at 10:32
1

tzplot translation:

enter image description here

\documentclass[tikz, margin=3mm]{standalone}

\usepackage{tzplot}

\begin{document} \begin{tikzpicture}[gridded] % Center \tzcoor(0,0)(Z){Z}[b] \tzdot*(Z)(4pt)

% Values =============== \def\rx{1.75} \def\ry{1} \def\r{\rx} \def\wStart{20} \def\wEnd{315} % ====================

% Help lines \tzlinebrown(\wStart:\r) \tzlinebrown(\wEnd:\r)

% Full circle and ellipse \tzcircle(Z)(\r) \tzcircle(Z)({\rx} and {\ry})

% cirlce arc \tzarcblue(\wStart:\wEnd:\r){good}[near start]

% ellipse arc \pgfmathsetmacro\XwStart{atan(tan(\wStart)(\rx/\ry))} % scaled angle \pgfmathsetmacro\XwEnd{atan(tan(\wEnd)(\rx/\ry))+360} % scaled angle \tzarcred(\XwStart:\XwEnd:{\rx} and {\ry}){bad?}[near start] \end{tikzpicture} \end{document}

I. Cho
  • 2,985