2

I have the display that I want ... but I do not know how the code gives it! The following display has a square sharing an edge with an equilateral triangle. I position point A with the command

\node (A-label) at ($(A)+(225:10pt)$) {$A$};.

I want the label D to be the same distance below the (invisible) line through points A and D and directly below the vertex to which D is a label. Using the Pythagorean Theorem, the distance needed is

10pt*sqrt(2)*(1/2) = 5pt*sqrt(2).

I use the code

\node (D-label) at ($(D)+(-90:5pt*sqrt(2))$) {$D$};

and get an error; I use the code

\node (D-label) at ($(D)+(-90:5pt*sqrt(2)$) {$D$};

and get the label positioned correctly. My concern is that I am missing a right parenthesis in the last command.

\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections}

\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\begin{document}

\begin{tikzpicture}

\coordinate (A) at (-1,-1);
\coordinate (B) at (-1,1);
\coordinate (C) at (1,1);
\coordinate (D) at (1,-1);

\draw (A) -- (B) -- (C) -- (D) -- cycle;

\path[name path=ray1] (C) -- ($(C) + (-30:3)$);
\path[name path=ray2] (D) -- ($(D) + (30:3)$);


\coordinate[name intersections={of=ray1 and ray2,by={P}}];
\node[label={right:$P$}] at (P) {};
%\draw (P) -- ($(D)!(P)!(C)$);


\draw (C) -- (P) -- (D);

\node[fill=white,circle,inner sep=0.5pt] (A-label) at ($(A)+(225:10pt)$) {$A$};
\node[fill=white,circle,inner sep=0.5pt] (B-label) at ($(B)+(135:10pt)$) {$B$};
\node[fill=white,circle,inner sep=0.5pt] (C-label) at ($(C)+(90:5pt*sqrt(2)$) {$C$};
\node[fill=white,circle,inner sep=0.5pt] (D-label) at ($(D)+(-90:5pt*sqrt(2)$) {$D$};
\node[fill=white,circle,inner sep=0.5pt] (P-label) at ($(P)+(0:10pt)$) {$P$};

\end{tikzpicture}

\end{document}
user74973
  • 4,071
  • 1
    Nice coincidence. I just updated the parenthesis issue addressing question. http://tex.stackexchange.com/questions/41828/using-math-in-tikz The gist is that TikZ don't perform delimiter balancing as long as it understands the context. – percusse Jun 02 '15 at 00:32

1 Answers1

1

The node D-label has the x coordinate from node D and the y coordinate from node A-label. Then the perpendicular coordinate system simplifies the calculation from

($(D)+(-90:5pt*sqrt(2)$)

to

(D |- A-label)

The position of C-label is calculated the same way:

(C |- B-label)

Result

The

\node (D-label) at ($(D)+(-90:5pt*sqrt(2))$) {$D$};

is not working, because the parser sees the closing parentheses of sqrt(2) and thinks, the coordinate is finished. Curly argument braces help:

\node (D-label) at ($(D)+(-90:{5pt*sqrt(2)})$) {$D$};
Heiko Oberdiek
  • 271,626