Skip to main content
used 1=1cm scale factor.
Source Link
John Kormylo
  • 89.1k
  • 3
  • 57
  • 131

Part of the problem is doing math with distances. pgfmath uses 1=1pt to do calculations, while tikz typically uses 1=1cm when graphing. It has the ability to add units to \pgfmathresult, but all it does is take the first unit found while parsing.

This is a macro solution. You might be able to do this using a code key, if you are more comfortable with keys than macros.

\documentclass{article} \usepackage{tikz} %\usepackage{calc}% not needed inside tikz \newcommand{\afro}[2]% #1 = a, #2 = b {\pgfextra{% needed inside a path \pgfmathparse{#1/1cm}% \let\a=\pgfmathresult \pgfmathparse{#2/1cm}% \let\b=\pgfmathresult \pgfmathparse{0.5*(#1*#1\a*\a/#2\b + #2\b)}% \let\r=\pgfmathresult \pgfmathparse{acos(#1\a/\r)}% \let\angle=\pgfmathresult}% arc(\angle:180-\angle:\r cm)% } \begin{document} \begin{tikzpicture} \draw[green] (0,0) arc (37:143:2.5cm); \draw (0,0) node {$O$}; \end{tikzpicture} \begin{tikzpicture} \draw[red] (0,0) \afro{22cm}{11cm}; \draw (0,0) node {$O$}; \end{tikzpicture} \end{document} 

Part of the problem is doing math with distances. pgfmath uses 1=1pt to do calculations, while tikz typically uses 1=1cm when graphing.

This is a macro solution. You might be able to do this using a code key, if you are more comfortable with keys than macros.

\documentclass{article} \usepackage{tikz} %\usepackage{calc}% not needed inside tikz \newcommand{\afro}[2]% #1 = a, #2 = b {\pgfextra{% needed inside a path \pgfmathparse{0.5*(#1*#1/#2 + #2)}% \let\r=\pgfmathresult \pgfmathparse{acos(#1/\r)}% \let\angle=\pgfmathresult}% arc(\angle:180-\angle:\r)% } \begin{document} \begin{tikzpicture} \draw[green] (0,0) arc (37:143:2.5cm); \draw (0,0) node {$O$}; \end{tikzpicture} \begin{tikzpicture} \draw[red] (0,0) \afro{2}{1}; \draw (0,0) node {$O$}; \end{tikzpicture} \end{document} 

Part of the problem is doing math with distances. pgfmath uses 1=1pt to do calculations, while tikz typically uses 1=1cm when graphing. It has the ability to add units to \pgfmathresult, but all it does is take the first unit found while parsing.

This is a macro solution. You might be able to do this using a code key, if you are more comfortable with keys than macros.

\documentclass{article} \usepackage{tikz} %\usepackage{calc}% not needed inside tikz \newcommand{\afro}[2]% #1 = a, #2 = b {\pgfextra{% needed inside a path \pgfmathparse{#1/1cm}% \let\a=\pgfmathresult \pgfmathparse{#2/1cm}% \let\b=\pgfmathresult \pgfmathparse{0.5*(\a*\a/\b + \b)}% \let\r=\pgfmathresult \pgfmathparse{acos(\a/\r)}% \let\angle=\pgfmathresult}% arc(\angle:180-\angle:\r cm)% } \begin{document} \begin{tikzpicture} \draw[green] (0,0) arc (37:143:2.5cm); \draw (0,0) node {$O$}; \end{tikzpicture} \begin{tikzpicture} \draw[red] (0,0) \afro{2cm}{1cm}; \draw (0,0) node {$O$}; \end{tikzpicture} \end{document} 
simplified code slightly
Source Link
John Kormylo
  • 89.1k
  • 3
  • 57
  • 131

Part of the problem is doing math with distances. pgfmath uses 1=1pt to do calculations, while tikz typically uses 1=1cm when graphing.

This is a macro solution. You might be able to do this using a code key, if you are more comfortable with keys than macros.

\documentclass{article} \usepackage{tikz} %\usepackage{calc}% not needed inside tikz \newcommand{\afro}[2]% #1 = a, #2 = b {\pgfextra{% needed inside a path \pgfmathparse{0.5*(#1*#1 - #2*#2)/#2}%  \let\c=\pgfmathresult + \pgfmathparse{sqrt(#1*#1+\c*\c#2)}% \let\r=\pgfmathresult \pgfmathparse{acos(#1/\r)}% \let\angle=\pgfmathresult}% arc(\angle:180-\angle:\r)% } \begin{document} \begin{tikzpicture} \draw[green] (0,0) arc (37:143:2.5cm); \draw (0,0) node {$O$}; \end{tikzpicture} \begin{tikzpicture} \draw[red] (0,0) \afro{2}{1}; \draw (0,0) node {$O$}; \end{tikzpicture} \end{document} 

Part of the problem is doing math with distances. pgfmath uses 1=1pt to do calculations, while tikz typically uses 1=1cm when graphing.

This is a macro solution. You might be able to do this using a code key, if you are more comfortable with keys than macros.

\documentclass{article} \usepackage{tikz} %\usepackage{calc}% not needed inside tikz \newcommand{\afro}[2]% #1 = a, #2 = b {\pgfextra{% needed inside a path \pgfmathparse{0.5*(#1*#1 - #2*#2)/#2}%  \let\c=\pgfmathresult  \pgfmathparse{sqrt(#1*#1+\c*\c)}% \let\r=\pgfmathresult \pgfmathparse{acos(#1/\r)}% \let\angle=\pgfmathresult}% arc(\angle:180-\angle:\r)% } \begin{document} \begin{tikzpicture} \draw[green] (0,0) arc (37:143:2.5cm); \draw (0,0) node {$O$}; \end{tikzpicture} \begin{tikzpicture} \draw[red] (0,0) \afro{2}{1}; \draw (0,0) node {$O$}; \end{tikzpicture} \end{document} 

Part of the problem is doing math with distances. pgfmath uses 1=1pt to do calculations, while tikz typically uses 1=1cm when graphing.

This is a macro solution. You might be able to do this using a code key, if you are more comfortable with keys than macros.

\documentclass{article} \usepackage{tikz} %\usepackage{calc}% not needed inside tikz \newcommand{\afro}[2]% #1 = a, #2 = b {\pgfextra{% needed inside a path \pgfmathparse{0.5*(#1*#1/#2 + #2)}% \let\r=\pgfmathresult \pgfmathparse{acos(#1/\r)}% \let\angle=\pgfmathresult}% arc(\angle:180-\angle:\r)% } \begin{document} \begin{tikzpicture} \draw[green] (0,0) arc (37:143:2.5cm); \draw (0,0) node {$O$}; \end{tikzpicture} \begin{tikzpicture} \draw[red] (0,0) \afro{2}{1}; \draw (0,0) node {$O$}; \end{tikzpicture} \end{document} 
Source Link
John Kormylo
  • 89.1k
  • 3
  • 57
  • 131

Part of the problem is doing math with distances. pgfmath uses 1=1pt to do calculations, while tikz typically uses 1=1cm when graphing.

This is a macro solution. You might be able to do this using a code key, if you are more comfortable with keys than macros.

\documentclass{article} \usepackage{tikz} %\usepackage{calc}% not needed inside tikz \newcommand{\afro}[2]% #1 = a, #2 = b {\pgfextra{% needed inside a path \pgfmathparse{0.5*(#1*#1 - #2*#2)/#2}% \let\c=\pgfmathresult \pgfmathparse{sqrt(#1*#1+\c*\c)}% \let\r=\pgfmathresult \pgfmathparse{acos(#1/\r)}% \let\angle=\pgfmathresult}% arc(\angle:180-\angle:\r)% } \begin{document} \begin{tikzpicture} \draw[green] (0,0) arc (37:143:2.5cm); \draw (0,0) node {$O$}; \end{tikzpicture} \begin{tikzpicture} \draw[red] (0,0) \afro{2}{1}; \draw (0,0) node {$O$}; \end{tikzpicture} \end{document}