4

i am trying to draw a point relative to a rectangle and than shift the whole rectangle so that this point is aligned with another point.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}
    \coordinate (origin) at (0,0);
    \fill (origin) circle (2pt);
    \path (-1.5,-1.5) -- (1.5,1.5);
    \begin{scope}
        \draw (-1,-1) coordinate (rect_lower_left) 
                    rectangle (1,1)
                    coordinate (rect_top_right);
        \coordinate (rect_top_left) at (rect_lower_left |- rect_top_right);
        \fill[red] (rect_top_left) circle (2pt);
        \fill[blue] (rect_lower_left) circle (2pt);
        \coordinate (ref_point) at ($(rect_top_left)!0.3!(rect_lower_left)$);
        \fill[green] (ref_point) circle (2pt);
    \end{scope}
\end{tikzpicture}
\end{document}

Result Picture

The result is shown in the picture above. I want the green point to be on the same hight as the black one. Of course I could shift the black one easily, but in the actual problem the black one is a point calculated in reference to points of the rest of the picture.

This picture shows the desired result.

enter image description here

So my idea was to add a shifting operation to the scope. But of course I cannot use a point that is added within the scope.

Another approach would be defining a new shape with anchor points. But this seems to be a bit extreme.

Maybe you have a complete other approach for me. I am drawing a circuit with cicuitikz. But now I need an IC (integrated circuit) with 8 ports. And of course I would like to have the IC aligned with the rest of the circuit to get straight lines. Is there another way of achieving this? edit: with the right search terms I found: Circuitikz - IC circuit with relative coordinates

Thanks for your help in advance, Gunter

Gunter
  • 443

1 Answers1

4

I propose another solution

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}

    \coordinate (origin) at (2,1);
    \fill (origin) circle (2pt);
    \path (-1.5,-1.5) -- (1.5,1.5);
\begin{scope}[shift={(origin)}]
\coordinate (ref_point) at (-1,0);
  \fill[green] (ref_point) circle (2pt);
\coordinate (rightRect) at (1,0);
\coordinate (rect_top_left) at ($(ref_point)+0.3*(0,2)$);
  \fill[red] (rect_top_left) circle (2pt);
\coordinate (rect_lower_left) at ($(ref_point)-0.7*(0,2)$);
  \fill[blue] (rect_lower_left) circle (2pt);

    \draw (rect_lower_left) 
                rectangle (rect_top_left-|rightRect)
                coordinate (rect_top_right);
\end{scope}
\end{tikzpicture}

\end{document

enter image description here

rpapa
  • 12,350
  • This indeed works as requested. It is not as charming as i would appreciate it. But it's definitely a very good starting point. – Gunter Sep 28 '13 at 17:21
  • I don't think this is very different from the other answer; in these cases, it's best to edit the previous answer (maybe retaining also the old code). Probably you're better to remove the other answer. – egreg Sep 28 '13 at 21:54