2

I have different measurement of length with trigonometric equation using radius and theta and from coordinates. I want to solve this issue because for further computation I need to have both measurement matching.

In overleaf, a MWE:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}

\usetikzlibrary{math, calc, angles}
\title{MWE}

\begin{document}
\begin{tikzpicture}
\def\angleTheta{30}
\pgfmathsetmacro\angleThetaComplementaire{90-\angleTheta/2}
\def\r{4cm}

\pgfmathsetmacro\lengthabtrigo{2*\r*sin(\angleTheta/2)}

\path
 (0,0) coordinate [label=above left:a,inner sep=0pt] (a)
 arc [radius=\r, start angle= 90+\angleTheta/2, end angle=90-\angleTheta/2] 
 coordinate [label=above right:b,inner sep=0pt] (b); 

\pgfgetlastxy{\xb}{\yb}
\tikzmath{\lengthabcoord= sqrt(\xb*\xb +\yb*\yb);}     
\node [label=right:O,inner sep=0pt] 
        (O)      at ++(-\angleThetaComplementaire:\r) {};

\draw (a) -- (b) -- (O) -- (a);
\pic [thick, draw, above left, <->, angle eccentricity=1, angle radius=2cm] {angle=b--O--a};
\node at (1, -1.5) {$\theta$};

\node at (5,-2) {ab (from trigo)=\lengthabtrigo};
\node at (5,-3) {ab (from coord)=\lengthabcoord};

\end{tikzpicture}
\end{document}

measurement of ab

2

The last coordinate in your code is not what you think it is. To see this, I added \path (b); just before \pgfgetlastxy{\xb}{\yb}. The reason for the discrepancy is coordinate [label=above right:b,inner sep=0pt] in your code, which adds the label after the coordinate. So you compare the coordinate of the label to your analytic computation. If you use the coordinate b instead the discrepancy goes away. (Of course, there is a tiny residual discrepancy because the accuracy of the TeX computations is not infinite.)

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}

\usetikzlibrary{math, calc, angles}
\title{MWE}

\begin{document}
\begin{tikzpicture}
\def\angleTheta{30}
\pgfmathsetmacro\angleThetaComplementaire{90-\angleTheta/2}
\def\r{4cm}

\pgfmathsetmacro\lengthabtrigo{2*\r*sin(\angleTheta/2)}

\path
 (0,0) coordinate [label=above left:a,inner sep=0pt] (a)
 arc [radius=\r, start angle= 90+\angleTheta/2, end angle=90-\angleTheta/2] 
 coordinate [label=above right:b,inner sep=0pt] (b); 
\path(b);
\pgfgetlastxy{\xb}{\yb}
\tikzmath{\lengthabcoord= sqrt(\xb*\xb +\yb*\yb);}     
\node [label=right:O,inner sep=0pt] 
        (O)      at ++(-\angleThetaComplementaire:\r) {};

\draw (a) -- (b) -- (O) -- (a);
\pic [thick, draw, above left, <->, angle eccentricity=1, angle radius=2cm] {angle=b--O--a};
\node at (1, -1.5) {$\theta$};

\node at (5,-2) {ab (from trigo)=\lengthabtrigo};
\node at (5,-3) {ab (from coord)=\lengthabcoord};
\path  let \p1=($(b)-(a)$),\n1={veclen(\x1,\y1)} in (5,-4) node
 {ab (from calc)=\n1};

\end{tikzpicture}
\end{document}

enter image description here

I also added a third, IMHO somewhat more direct, way to measure the distance. The results agree (with reasonable accuracy).

  • 1
    as often in tikz what I took for a major issue was indeed a minor glitch :( – the world is not flat May 23 at 15:06
  • @theworldisnotflat Yes, the world is not flat. ;-) – user121799 May 23 at 15:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.