For istance, with Tikz, I can draw a circle centered in the point (0,0) with radius 2. How can I draw a rectangle centerd in (0,0) giving height and basis?
3 Answers
Last but not least, you could use a node, whose shape is rectangle and apply its anchor to its center:
\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
% I want to center the rectangle here
\filldraw (0,0) node [below] {center here} circle (1pt);
% drawing the node with shape=rectangle and anchor=center
\node [draw, thick, shape=rectangle, minimum width=3cm, minimum height=2cm, anchor=center] at (0,0) {};
\end{tikzpicture}
\end{document}
You can use the shift
key:
\draw[shift={(2,1)}] (-3,-2) rectangle (3,2);
With this method, you can also rotate the rectangle around the center:
\draw[shift={(2,1)},rotate=20] (-3,-2) rectangle (3,2);
If you use the tikzpackage calc you can achieve this quite easily.
If A is the center and dim the basis/height of the rectangle
\coordinate (A) at (2,2);
\coordinate (dim) at (3,4);
you could calculate the lower left and upper right coordinate with:
\coordinate (LL) at ($(A)-0.5*(dim)$);
\coordinate (UR) at ($(A)+0.5*(dim)$);
And then draw the rectangle between those two points.
If you need this often I recommend creating a macro for it - se here: A macro of drawing a rectangle with several parameters in TikZ