0

In this tikzpicture

\documentclass[margin=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{calc}
\usetikzlibrary{shapes.arrows}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{shadings}
\usetikzlibrary{angles,quotes}
\usetikzlibrary{decorations.markings}

\begin{document}
    
\begin{tikzpicture}[]
    
    \coordinate [circle, ] (center) at (0,0);
    \coordinate (basecenter) at (0,-2);
    \coordinate (baseleft) at (-3,-2);
    \coordinate (baseright) at (3,-2);
    
    \draw [thick, gray, line width=0.5mm] ($(baseleft) + (-1,0)$) -- (basecenter) -- ($(baseright) + (1,0)$);
    \draw [fill=black!20, draw=black!50] ($(baseleft)+(-0.1,0)$) rectangle ($(baseleft) + (0.1,4)$);
    
    \coordinate (TXbottom) at ($(baseleft) + (0.1, 3)$);
    \coordinate (TXcenter) at ($(TXbottom) +(0.075,0.3)$);
    %\draw [draw=red, fill=red!30!white,rotate=-20] (TXbottom) rectangle ($(TXbottom) + (0.15,0.6)$);
    \draw[ draw=red, fill=red!30!white ] let \p1=($(TXcenter)-(center)$),\n1={atan2(\y1,\x1) - 90} in [rotate=\n1] (TXbottom) rectangle ($(TXbottom) + (0.6,-0.15)$);
    \draw[thin,blue] let \p1=($(TXcenter)-(center)$),\n1={atan2(\y1,\x1) - 90} in (TXbottom) -- ++(\n1:1.2) coordinate (incliTX);
    
    \path ($(TXbottom) + (0.075,0)$) -- ($(TXbottom) + (0.075,0.6)$) let \p1=($(TXcenter)-(center)$),\n1={atan2(\y1,\x1)-90 } in  node[midway, rotate=\n1, ] (inicioTX) {};
    \fill[black!70!] (inicioTX) circle (0.05);
    
    \draw[thin,blue] (TXbottom) -- ++(90:1.2) coordinate (vertTX);
    \pic [draw, latex-, "$\theta$", angle eccentricity=1.6, angle radius = .75cm,pic text options={shift={(0pt,0.25pt)}}] {angle = incliTX--TXbottom--vertTX};
    
    \draw [line width=1.2mm, draw=yellow!70!brown] ($(center) + (-2.9,0)$) -- ($(center) + (2.9,0)$);   

    \fill[black!70!] (center) circle (0.05);
    \draw [ draw=red,dashed,thick, -> ] (inicioTX) -- (center) coordinate (pabajo);

\end{tikzpicture}
\end{document}

enter image description here

I would like to start the dashed red arrow line from the geometric center of the $\theta$-rotated red rectangle. I have tried to rotate a middle node in the path from the bottom and the top of the red rectangle, but it does not work. The node is still in the no-rotated coordinates (black circle)

Besides, it seems the code is not much efficient and needs some time to compile. I would like to know how to start the dashed line from the rotated red rectangle center.

2

I actually like the calc syntax. You can access the center of the rectangle by placing a coordinate at pos=0.5 after the rectangle path construction.

\documentclass[tikz,margin=2mm]{standalone}
\usetikzlibrary{positioning}
\usetikzlibrary{calc}
\usetikzlibrary{shapes.arrows}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{shadings}
\usetikzlibrary{angles,quotes}
\usetikzlibrary{decorations.markings}

\begin{document}
    
\begin{tikzpicture}[]
    
    \coordinate [circle, ] (center) at (0,0);
    \coordinate (basecenter) at (0,-2);
    \coordinate (baseleft) at (-3,-2);
    \coordinate (baseright) at (3,-2);
    
    \draw [thick, gray, line width=0.5mm] ($(baseleft) + (-1,0)$) -- (basecenter) -- ($(baseright) + (1,0)$);
    \draw [fill=black!20, draw=black!50] ($(baseleft)+(-0.1,0)$) rectangle ($(baseleft) + (0.1,4)$);
    
    \coordinate (TXbottom) at ($(baseleft) + (0.1, 3)$);
    \coordinate (TXcenter) at ($(TXbottom) +(0.075,0.3)$);
    %\draw [draw=red, fill=red!30!white,rotate=-20] (TXbottom) rectangle ($(TXbottom) + (0.15,0.6)$);
    \draw[ draw=red, fill=red!30!white ] let
    \p1=($(TXcenter)-(center)$),\n1={atan2(\y1,\x1) - 90} 
    in [rotate=\n1] (TXbottom)  rectangle ($(TXbottom) + (0.6,-0.15)$)
    coordinate[pos=0.5] (c)
    (TXbottom)  ++(\n1:1.2) coordinate (incliTX)
    ($(TXbottom) + (0.075,0.6)$);
    \draw[thin,blue] let \p1=($(TXcenter)-(center)$),\n1={atan2(\y1,\x1) - 90}
    in (TXbottom) -- ++(\n1:1.2) coordinate (incliTX);
    
    
    \draw[thin,blue] (TXbottom) -- ++(90:1.2) coordinate (vertTX);
    \pic [draw, latex-, "$\theta$", angle eccentricity=1.6, 
    angle radius =.75cm,pic text options={shift={(0pt,0.25pt)}}] {angle =incliTX--TXbottom--vertTX};
    
    \draw [line width=1.2mm, draw=yellow!70!brown] ($(center) + (-2.9,0)$) -- ($(center) + (2.9,0)$);   

    \fill[black!70!] (center) circle (0.05);
    \draw [ draw=red,dashed,thick, -> ] (c) -- (center) coordinate (pabajo);
    \fill[black!70!] (c) circle (0.05);

\end{tikzpicture}
\end{document}

enter image description here

1
  • Thank you for your answer. Why the red arrow starts in the (c) node without any gap and between the arrowhead and (center) there is a space? – user1993416 Nov 24 '20 at 11:45
2

I'm not a fan of the whole \p1,\x1,\y1 approach, since none of them are legal macro names, and I have no idea what \n1 is supposed to be. Besides, this way you only have to compute atan2 once.

\documentclass[margin=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{calc}
\usetikzlibrary{shapes.arrows}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{shadings}
\usetikzlibrary{angles,quotes}
\usetikzlibrary{decorations.markings}

\begin{document}
    
\begin{tikzpicture}[]
    
    \coordinate (center) at (0,0);
    \coordinate (basecenter) at (0,-2);
    \coordinate (baseleft) at (-3,-2);
    \coordinate (baseright) at (3,-2);
    
    \draw [thick, gray, line width=0.5mm] ($(baseleft) + (-1,0)$) -- (basecenter) -- ($(baseright) + (1,0)$);
    \draw [fill=black!20, draw=black!50] ($(baseleft)+(-0.1,0)$) rectangle ($(baseleft) + (0.1,4)$);
    
    \coordinate (TXbottom) at ($(baseleft) + (0.1, 3)$);
    \coordinate (TXcenter) at ($(TXbottom) +(0.075,0.3)$);
    %\draw [draw=red, fill=red!30!white,rotate=-20] (TXbottom) rectangle ($(TXbottom) + (0.15,0.6)$);
    \path[overlay] ($(TXcenter)-(center)$);
    \pgfgetlastxy{\xp}{\yp}
    \pgfmathsetmacro{\angle}{atan2(\yp,\xp) - 90}
    
    \begin{scope}[shift=(TXbottom), local bounding box=redbox]
      \path[ draw=red, fill=red!30!white , rotate=\angle]  (0,0) rectangle (0.6,-0.15);
    \end{scope}
    
    \draw[thin,blue] (TXbottom) -- ++(\angle:1.2) coordinate (incliTX);
    
    \path ($(TXbottom) + (0.075,0)$) -- ($(TXbottom) + (0.075,0.6)$) node[midway, rotate=\angle, ] (inicioTX) {};
    %\fill[black!70!] (inicioTX) circle (0.05);
    
    \draw[thin,blue] (TXbottom) -- ++(90:1.2) coordinate (vertTX);
    \pic [draw, latex-, "$\theta$", angle eccentricity=1.6, angle radius = .75cm,pic text options={shift={(0pt,0.25pt)}}] {angle = incliTX--TXbottom--vertTX};
    
    \draw [line width=1.2mm, draw=yellow!70!brown] ($(center) + (-2.9,0)$) -- ($(center) + (2.9,0)$);   

    \fill[black!70!] (redbox.center) circle (0.05);
    \draw [ draw=red,dashed,thick, -> ] (redbox.center) -- (center) coordinate (pabajo);% set to (center)

\end{tikzpicture}
\end{document}
3
  • Thank you for the answer. I am sorry if my question is not clear. I am looking to start the dashed red arrow from a node that would be in the center of the red rectangle. The dark circle is the start and it is not in the center of that rectangle. – user1993416 Nov 23 '20 at 20:48
  • Do you know how to move the center node inicioTX to the center of the rotated red rectangle? or start the dashed red line from the center of the red rectangle? – user1993416 Nov 23 '20 at 21:12
  • I wasn't sure about the dark circle, as there appears to be two on them. – John Kormylo Nov 24 '20 at 14:37

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.