1

In the following display, a point (-4,5) and a line are drawn. A dashed line is drawn from (-4,5) to the line indicating the distance between them. I call the intersection between the given line and the dashed line Q. Q = (0,-1). I draw a dashed line from (-4,5) to Q and draw a right-angle mark between the given line and the dashed line. A brace and label for it are drawn. Since the x-axis interferes with the brace, a thicker white brace is first drawn using the option draw=white to give the actual brace the appearance of being above the graph.

I would like two modifications. The y-axis interferes with right-angle mark. How do I "color" inside the right-angle mark white. Without guessing, how do I properly center the label "d" which indicates the distance between the point and line with respect to the brace?

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


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

\begin{document}

\begin{tikzpicture}
\begin{axis}[width=5in,clip=false,axis equal image,
    axis lines=middle,
    xmin=-7,xmax=7,
    ymin=-7,ymax=7,
    xlabel=$x$,ylabel=$y$,
    restrict y to domain=-7:7,
    enlargelimits={abs=0.5cm},
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    xtick={\empty},ytick={\empty},
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]

\addplot[latex-latex,samples=2,domain=-7:7,blue,name path = line_1] {(2/3)*x - 1} node[anchor=south east,pos=0.9,font=\footnotesize]{$y=\dfrac{2}{3}x - 1$};
\addplot[draw=none,samples=2,domain=-16/3:4,blue,name path = line_2] {(-3/2)*x - 1};
\addplot[mark=*,blue,mark size=1.5pt] coordinates{(-4,5)} node[anchor=west,font=\footnotesize]{$P$};
\draw[name intersections={of= line_1 and line_2, by={Q}}];

%These commands typeset a brace. To give the brace the appearance of being typeset over
%the x-axis, it is typeset in white with a line width of 2pt, which is 10 times the
%thickness of the thickness of the brace that is actually typeset.
\draw[draw=white,line width=4pt,decorate,decoration={brace,raise=5pt,amplitude=5pt,mirror}] (-4,5) -- (Q);
\draw[decorate,decoration={brace,raise=5pt,amplitude=5pt,mirror}] (-4,5) -- (Q);



%The following commands make the right-angle mark.
\coordinate (U) at ($(Q)!4mm!45:(1.5,0)$);
\draw (U) -- ($(Q)!(U)!(-4,5)$);
\draw (U) -- ($(Q)!(U)!(1.5,0)$);

%The following command draws a dashed line between (-4,5) and Q.
\draw[dashed] (-4,5) -- (Q);


\end{axis}
\end{tikzpicture}

\end{document}
  • 3
    What seems to be the question here? – Gonzalo Medina Jun 22 '15 at 19:09
  • Please always check your code before posting it. As it was it wouldn't compile since you forgot to load pgfplots. I've fixed that in my edit. – Gonzalo Medina Jun 22 '15 at 19:13
  • Is this meant as a showcase? Remember that this is a question and answer site, you seem to have posted an answer without a clear question. See also meta.tex.stackexchange.com/questions/2943/… – Torbjørn T. Jun 22 '15 at 19:24
  • @Torbjørn T. I can edit it and at the end say "I have code that gives me the display that I want ... but I am looking for other suggestions." – user74973 Jun 22 '15 at 20:54
  • @user74973 If that is the case then, yes, please edit so that your question is a question, indicate that you have an answer and then post your answer as an answer. That saves people a lot of time trying to figure out what is going on: it is clear and makes it possible to find things. – cfr Jun 23 '15 at 0:31
2

You can basically do everything as you go along the path with naming coordinates and continuing by referring to those. There is no need for intersections for this example.

\documentclass{standalone}
\usetikzlibrary{calc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}

\begin{document}

\begin{tikzpicture}
\begin{axis}[width=5in,clip=false,axis equal image,
    axis lines=middle,
    xmin=-7,xmax=7,
    ymin=-7,ymax=7,
    xlabel=$x$,ylabel=$y$,
    restrict y to domain=-7:7,
    enlargelimits={abs=0.5cm},
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    xtick={\empty},ytick={\empty},
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]

\addplot[latex-latex,samples=2,domain=-7:7,blue] {(2/3)*x - 1} 
    coordinate [pos=0] (s) 
    coordinate (e)
    node[anchor=south east,pos=0.9,font=\footnotesize]{$y=\dfrac{2}{3}x - 1$};

\draw[dashed,
    decoration={brace,raise=5pt,amplitude=5pt},
    postaction={draw,solid,decorate}] 
    ($(s)!0.5!(e)$) coordinate (m) --($($(s)!0.5!(e)$)!0.8!90:(e)$)
     node[circle,inner sep=2pt,fill=blue,label={[blue,font=\footnotesize]45:$P$}] (p){}
    ($($(m)!0.5!(p)$)!10pt!90:(p)$) node[anchor=east] {$d$};

\draw[fill=white] ($(m)!3mm!(e)$) coordinate (U) 
     -- ($(U)!3mm!90:(e)$) -- ($(m)!3mm!(p)$) -- (m) -- cycle;

\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.