2

I'm trying to come up with a way to draw "parametric" right triangles, meaning that I change the length of the hypotenuse \hypo and one of the internal angles \alfa and it should draw the triangle for me. So far I have done this

\documentclass[border=1mm]{standalone}

\usepackage{tikz}

\usetikzlibrary{calc, angles, intersections}

\begin{document}
    \begin{tikzpicture}
        \def\alfa{55}
        \def\hypo{3}
        \draw[name path= A-C] (0,0) node[below left] (A) {A} -- (90-\alfa:3);
        \draw (0,0) -- (\hypo,0) node[below right] (B) {B} -- ++ (180-\alfa:3);
        \path[name path= B-C] (\hypo,0) -- ++ (180-\alfa:3);
        \node [name intersections={of= A-C and B-C}, above] at (intersection-1) {C};
    \end{tikzpicture}
\end{document}

I can't figure out how to trim the two catheti at at their intersection.

On top of that I don't think it's a good idea to hard-code their length (here 3 units). I did it because if they are too short, then they don't intersect and Tikz can't find the intersection. It would be better to let LaTeX (or Tikz) figure out the correct length to get to the intersection and not passed it. I've tried to look for a solution in the manual and online, but I can't find anything really helpful. Any idea how to do this?

1 Answer 1

5

You can use overlay to exclude auxiliary coordinates from the bounding box. BTW, you do not need the intersections library for computing the intersection between straight lines.

\documentclass[border=1mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
   \def\alfa{55}
   \def\hypo{3}
   \path[overlay] (0,0) coordinate (A) ++ (90-\alfa:1) coordinate (C')
    (\hypo,0) coordinate (B)  ++ (180-\alfa:1) coordinate (C'')
    (intersection of A--C' and B--C'') coordinate (C);
    %or
    %(intersection cs:first line={(A)--(C')},second line={(B)--(C'')}) coordinate (C);
   \draw (A) node[below left]  {$A$}    -- (B) node[below right] {$B$}
    -- (C) node[above]{$C$} -- cycle;
\end{tikzpicture}
\end{document}

enter image description here

Of course one can compute the coordinates of C analytically, see e.g. this thread.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .