1

I'm trying to draw a line (PC2), that passes through some arbitrary point (A) and is parallel to another line (PC1).

PC1 is defined by a gradient (PCslp) and a y intercept (PCint). Obviously, as parallel lines, PC1 and PC2 have the same gradient. The y intercept is differnet, and can be calculated using point (A) and the gradient: take the y value of (A) and subtract the x value of (A) multiplied by the gradient (PCslp).

The code I am using is as follows:

\documentclass[tikz, border=2mm]{standalone}
\usepackage{tikz}
\usepackage{calc}

\usetikzlibrary{calc,intersections}

\begin{document}

\begin{tikzpicture}[
        PC/.style={red, thick},
        dot/.style={circle,fill=black,minimum size=4pt,inner sep=0pt,outer sep=-1pt}
      ]

% Define linear parameters 
\def\PCint{0.2}   %Y-intercept 
\def\PCslp{0.8}   %Slope 
\def\PC{\x,{\PCslp*\x+\PCint}}

\draw[PC, domain=0:5] 
  plot (\PC)
  node [right] {$PC_1$};

\draw [domain=0:5]
  let
    \p1=(61.28041pt, 26.23682pt),
    \n1={\y1-\PCslp*\x1} in

  % points the plot should pass through...
  node [dot,label=above:{$A$}] at (\x1,\y1) {}
  node [dot,label=above:{$B$}] at (0,\n1) {}

  % first try for a plot...
  plot ({\x,\PCslp*\x-\n1})
  node [right] {$PC_2$};

\end{tikzpicture}
\end{document}

Unfortunately, the result I'm getting is not what I expected:

enter image description here

Can anybody point out what I'm doing wrong?

Cheers

nik

  • First, plot ({\x,\PCslp*\x-\n1}) should be plot (\x,{\PCslp*\x+\n1}), but this doesn't work either. If you leave out the +\n1 you get the right slope, and if you leave out the \PCslp*x you get the right intercept. – John Kormylo May 7 '16 at 13:54
  • Aha! \n1 is defined in screen units (-22.78769pt) and for some reason you cannot combine screen units and unscaled units in this calculation. – John Kormylo May 7 '16 at 14:03
  • From the pgfmanual (page 132 of the current version): »An expression like (2+3cm,0) does not mean the same as (2cm+3cm,0). Instead, if <x> or <y> internally uses a mixture of dimensions and dimensionless values, then all dimensionless values are “upgraded” to dimensions by interpreting them as pt. So, 2+3cm is the same dimension as 2pt+3cm – esdd May 7 '16 at 14:17
1

A bit of a kludge, but it works:

\documentclass[tikz, border=2mm]{standalone}
\usepackage{tikz}
\usepackage{calc}

\usetikzlibrary{calc,intersections}

\begin{document}

\begin{tikzpicture}[
        PC/.style={red, thick},
        dot/.style={circle,fill=black,minimum size=4pt,inner sep=0pt,outer sep=-1pt}
      ]

% Define linear parameters 
\def\PCint{0.2}   %Y-intercept 
\def\PCslp{0.8}   %Slope 
\def\PC{\x,{\PCslp*\x+\PCint}}

\draw[PC, domain=0:5] 
  plot (\PC)
  node [right] {$PC_1$};

\draw [domain=0:5]
  let
    \p1=(61.28041pt, 26.23682pt),
    \n1={\y1-\PCslp*\x1} in

  % points the plot should pass through...
  node [dot,label=above:{$A$}] at (\x1,\y1) {}
  node [dot,label=above:{$B$}] at (0,\n1) {}

  % first try for a plot...
  plot[yshift=\n1] (\x,\PCslp*\x)
  node [right,yshift=\n1] {$PC_2$};

\end{tikzpicture}
\end{document}

demo

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.