2

I need to draw a rectangle between the midpoints of two rotated rectangles (shown below).

How do I do this?

My current code is shown below.

Current code

\draw[thick] (0,0) -- (6,0);
\draw[thick,fill=yellow!40, rotate around={26.5:(3.1,-5)}] (3,0) rectangle (3.2,-5);
\draw[thick,fill=yellow!40, rotate around={-26.5:(3.1,-5)}] (3,0) rectangle (3.2,-5);
\draw[fill=black] (3.1,-5) circle(0.11);
\node at (3.1,-5.3) {A};

Current result

enter image description here

Mockup of wanted result

enter image description here

  • Can you post a picture of what you intend to have?. I don't quite follow your requirement as such. –  Nov 14 '14 at 01:30
  • @HarishKumar I've updated the question. –  Nov 14 '14 at 01:33
  • Welcome to TeX.SE. While code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. – Peter Grill Nov 14 '14 at 01:40
  • @PeterGrill I'll make sure to do that from now on. –  Nov 14 '14 at 01:41

5 Answers5

1

Simply define two coordinates a and b, then draw a line with desired thickness. Change the pos value as you wish.

\documentclass[tikz,border=5]{standalone}
\begin{document}
  \begin{tikzpicture}
    \draw[thick] (0,0) -- (6,0);
\draw[thick,fill=yellow!40, rotate around={26.5:(3.1,-5)}] (3,0) rectangle (3.2,-5)coordinate[pos=0.5](a);
\draw[thick,fill=yellow!40, rotate around={-26.5:(3.1,-5)}] (3,0) rectangle (3.2,-5)coordinate[pos=0.5](b);
\draw[fill=black] (3.1,-5) circle(0.11);
\node at (3.1,-5.3) {A};
\draw[line width=2pt] (a) -- (b);
  \end{tikzpicture}
\end{document}

enter image description here

1

Instead of rectangles you can draw rectangular nodes and make reference to thier center anchors.

\documentclass[tikz,border=2mm]{standalone}

\begin{document}

\begin{tikzpicture}
\draw[thin,gray] (0,0) node[above] {(0,0)} grid (6,-6) node[below] {(6,-6)};
\node[draw, thick, fill=yellow!40, minimum height=5cm, minimum width=2mm, 
       inner sep=0pt, outer sep=0pt, anchor=south, rotate=26.5] at (3.1,-5) (a){};
\node[draw, thick, fill=yellow!40, minimum height=5cm, minimum width=2mm,
       inner sep=0pt, outer sep=0pt, anchor=south, rotate=-26.5] at (3.1,-5) (b){};
\draw[fill=black] (a.south) circle(0.11) node[below, outer sep=1mm]{A};
\draw[ultra thick] (a.center)--(b.center);
\end{tikzpicture}

\end{document}

enter image description here

Ignasi
  • 136,588
1

You can do this neatly in Metapost using the center operator, which returns a pair representing the center of the bbox of a given path.

An upside down A-shape

prologues := 3;
outputtemplate := "%j%c.eps";

beginfig(1);

pair apex; 
numeric u, alpha; 
path rectangle[]; 

u = 1cm;
apex = (3u, -5u); 
alpha = 53; % angle between the two legs

rectangle0 = unitsquare shifted 1/2 left xscaled 0.2u yscaled 5u;
rectangle1 = rectangle0 rotated +1/2 alpha shifted apex;
rectangle2 = rectangle0 rotated -1/2 alpha shifted apex;

rectangle3 = unitsquare shifted 1/2 down yscaled 0.2u 
                        xscaled length(center rectangle2 - center rectangle1)
                        shifted center rectangle1;

forsuffixes $=1,2,3:
  fill rectangle$ withcolor 0.4[white,red+green];
  draw rectangle$; 
endfor

fill fullcircle scaled .22u shifted apex;
label("A" infont "phvr8r",apex+8 down);

endfig;
end.
Thruston
  • 42,268
0

You can apply the same rotation to the centers of the non-rotated rectangle. In other words, the center of the non-rotated rectangles would be (3.1,-2.5). Hence the centers of the rotated rectangles are:

        ([rotate around={26.5:(3.1,-5)}]3.1,-2.5)

and

        ([rotate around={-26.5:(3.1,-5)}]3.1,-2.5)

Connecting these points yields:

enter image description here

I have just drawn a line, but that should let you draw any desired rectangle based on those coordinates.

Notes:

  • One of drawbacks of this solution is that you need to specify the rotation values twice. Hence, using \coordinates (as per Harish Kumar's solution) or \nodes (as per Ignasi's solution) isbetter.

Code:

\documentclass{article}
\usepackage{tikz}

\begin{document} \begin{tikzpicture} \draw[thick] (0,0) -- (6,0); \draw[thick,fill=yellow!40, rotate around={26.5:(3.1,-5)} ] (3,0) rectangle (3.2,-5) node (a) {}; \draw[thick,fill=yellow!40, rotate around={-26.5:(3.1,-5)}] (3,0) rectangle (3.2,-5) node (b) {}; \draw[fill=black] (3.1,-5) circle(0.11); \node at (3.1,-5.3) {A}; \draw [red, ultra thick] ([rotate around={26.5:(3.1,-5)}]3.1,-2.5) -- ([rotate around={-26.5:(3.1,-5)}]3.1,-2.5); \end{tikzpicture} \end{document}

Peter Grill
  • 223,288
0

A PSTricks solution:

\documentclass{article}

\usepackage{pstricks}

\begin{document}

\psset{fillstyle = solid}
\begin{pspicture}(6.2,6.52)
  \rput{115}(3.23,0.18){\psframe[fillcolor = yellow!60](0,0)(7,0.3)}
  \rput{65}(3.23,0.05){\psframe[fillcolor = yellow!60](0,0)(7,0.3)}
  \pscircle[fillcolor = black](3.1,0.12){0.15}
  \psframe[fillcolor = black](1.59,3.3)(4.6,3.4)
\end{pspicture}

\end{document}

output