0

i want to draw an arc of circle, and figure out the raduis on the graph, using:

raduis\times cos and sin 45\deg

when i specify the radius r=1.5cm, i can't get it on the border, anyone can help me, thanks in advance

\documentclass[border=30pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, calc, decorations.markings, quotes}
\begin{document}
\begin{tikzpicture}
\draw[thick, violet] (0,0) -- (4,0);
      \node[left] at (0,0){$O$};
     \node[right] at (4,0){$O'$};
    \fill[red] (2,0) circle (1.1pt);
    \draw[thick, red] (2,0) -- ({1.5*cos(40)},{1.5*sin(40)});
     \draw (3.5,0) arc (0:180:1.5) ;\node[above] at (2.5,0){$O$};
\end{tikzpicture}
\end{document}
moradov
  • 427

2 Answers2

1

Add ++.

\documentclass[border=30pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, calc, decorations.markings, quotes}
\begin{document}
\begin{tikzpicture}
\draw[thick, violet] (0,0) -- (4,0);
      \node[left] at (0,0){$O$};
     \node[right] at (4,0){$O'$};
    \fill[red] (2,0) circle (1.1pt);
    \draw[thick, red] (2,0) -- ++({1.5*cos(40)},{1.5*sin(40)});
     \draw (3.5,0) arc (0:180:1.5) ;\node[above] at (2.5,0){$O$};
\end{tikzpicture}
\end{document}

enter image description here

  • thank you for your answers which are very fast and very useful – moradov Mar 26 '18 at 15:39
  • In place of ({1.5*cos(40)},{1.5*sin(40)}) you should probably use (40:1.5), and you can add only one + here ;) – Kpym Mar 26 '18 at 16:51
  • @Kpym I agree with all these statements, but the reason why the original code didn't work was that at least one + was missing. –  Mar 26 '18 at 16:57
1

For calculations, you can use the \tikzmath command in tikz. This requires you to load the appropriate library:

\usepackage{tikz}
\usetikzlibrary{math}

You then define define variables inside the \tikzmath command and use these variables as coordinates, e.g.:

\begin{tikzpicture}
    \tikzmath{
        \angle = 40;
        \coordX = 1.5 * cos(\angle);
        \coordY = 1.5 * sin(\angle);
    }
    \draw[thick, red] (2,0) -- ++(\coordX,\coordY);
\end{tikzpicture}

I'm not quite sure if this will work since I've only used \tikzmath once so far. Hope this helps and doesn't contain too many mistakes (code is untested, math library apparently not necessary...see comment below).