4

Suppose I have a closed path that looks like:

 _
| |_
|___|

I want to draw, within that path, a scaled version of it so that the centers of the two figures are the same. That is, wherever this path is located, I wan't to be able to draw a similar path within this path.

A possible solution would be to move a path by its center point. Any suggestion? Thanks!

Michaël
  • 1,384
  • 11
  • 22
  • You could use the local bounding box feature of TikZ, however you would get then only the center of the outer rectangle of the path. Would that be ok? – Martin Scharrer Oct 26 '11 at 16:38
  • I'm not sure, but it may do the trick in my case. How would you go for getting the center of the bounding box of a path, then? Thanks! – Michaël Oct 26 '11 at 18:20

2 Answers2

2

There is actually a very nice way to scale the current path, so that it becomes slightly larger (or smaller, depending on your needs). It relies on the current path bounding box, in combination with scale around:

\begin{tikzpicture}
  \draw 
    plot [smooth cycle] 
    coordinates {(0:1cm) (90:1cm) (210:1cm)};

  \draw[scale around={1.5:(current path bounding box.center)}] 
    plot [smooth cycle] 
    coordinates {(0:1cm) (90:1cm) (210:1cm)};
\end{tikzpicture}

which yields the following result

scaling

Vincent Traag
  • 368
  • 2
  • 6
1

If I'm understanding you correctly, you want to draw a figure, and pick a point in it (which may be the center of mass, or may not) and scale the figure down to a copy of itself, with the center of scaling at the point you chose. If this is so, you want the scale = <factor> option: put this in the \draw command for the second shape, and all the coordinates will be scaled (around the origin (0,0)) by <factor>. If you want to scale around another center, use the option shift = {(<x>, <y>)} (note the braces) first.

You have to figure out what <x> and <y> are if you want to scale around a different center. One easy out is simply to draw your big shape so that its center of mass is actually at the origin. If you don't want to compute the center of mass yourself, you can use the method I describe in my answer Finding centroid of the content in whole tikzpicture, scope or node to have TikZ do it for you.

Ryan Reich
  • 37,958