4

In words what I'm trying to do is: "Extend the three green lines from their specified point of origin at their specified angle to meet the blue line" How would you recommend doing this?

\def \tubeLength{10}
\def \lightLength{5}
\def \angleDown{340}
\def \lightSpacing{1}

\begin{document}
\begin{tikzpicture}[scale=.5]

% tube
\draw (0,0) -- (\angleDown:\tubeLength);
\draw (0,0) ++(\angleDown-270:4*\lightSpacing) -- ++(\angleDown:\tubeLength);

% diffracted light
\foreach \y in {\lightSpacing, 2*\lightSpacing, 3*\lightSpacing}
  \draw[green] (0,\y) -- ++(\angleDown:\lightLength);

% lense center line
\path (0,0) -- (\angleDown:\lightLength) coordinate (A)
  node[below left] {A};
\path [draw, very thick, blue] (A) -- ++(\angleDown-270:4*\lightSpacing)
  coordinate (B)
  node[above right,black] {B};

\end{tikzpicture}

enter image description here

6

If you used the tikz library calc then you can write

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}

\def \tubeLength{10}
\def \lightLength{5}
\def \angleDown{340}
\def \lightSpacing{1}

\begin{tikzpicture}

  % tube
  \draw (0,0) -- (\angleDown:\tubeLength);
  \draw (0,0) ++(\angleDown-270:4*\lightSpacing) -- ++(\angleDown:\tubeLength);

  % lense center line
  \path (0,0) -- (\angleDown:\lightLength) coordinate (A) node[below left] {A};
  \path [draw, very thick, blue] (A) -- ++(\angleDown-270:4*\lightSpacing) coordinate (B) node[above right,black] {B};

  % diffracted light
  \foreach \y/\x in {\lightSpacing/1, 2*\lightSpacing/2, 3*\lightSpacing/3}
    {
      \coordinate (DL\x) at (0,\y);
      \draw[green] (DL\x)  -- ($(A)!(DL\x)!(B)$);
    }

\end{tikzpicture}

\end{document}

enter image description here

The syntax ($<coordinate>!<projection coordinate>!<angle>:<second coordinate>$) will give you the projection of the given point to the desired line.

1
  • Thank you so much! this is exactly what I was looking for and also led me to an interesting section of the manual. – mbigras Oct 28 '13 at 0:30
4

If you simply rotate your coordinate systems about \angleDown you don’t need to change anything with your code except to remove \angleDown.

Though, I removed as much \defs as simply possible.
You can adjust both tubeLength and lightLength by changing the y vector of PGF/TikZ, the default is y=1cm. Setting it to y=2cm, will make the tubeLength 20cm long and the lightLength 10cm (at least without scale).

Code

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}[scale=.5, rotate=340, every label/.append style={black}]
\def\lightLength{5}
% tube
\draw    (0,0) -- ++ (right:10) coordinate (tubeLength);
\draw (-270:4) -- ++ (tubeLength);
% diffracted light
\foreach \y in {1,...,3} \draw[green] (0,\y) -- ++(right:\lightLength);
% lense center line
\path (right:\lightLength)                     coordinate[label=below left:A]  (A);
\path [draw, very thick, blue] (A) -- ++(up:4) coordinate[label=above right:B] (B);
\end{tikzpicture}
\end{document}

Output

enter image description here

3

A solution with PSTricks. Unfortunately, there is no ($ (A)!0.25!(B) $)-like syntax in PSTricks so the temp as an auxiliary node is necessary.

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-eucl}
\begin{document}
\begin{pspicture}[showgrid](8,8)
    \pstGeonode[PosAngle={-90,90},CurveType=polyline,linecolor=blue](3,1){A}(5,6){B}
    \psline([offset=2]{A}B)([offset=-2]{A}B)
    \psline([offset=2]{B}A)([offset=-2]{B}A)
    \multido{\n=.25+.25}{3}{%
        \nodexn{\n(B)-\n(A)+(A)}{temp}
        \psline[linecolor=green]([offset=3]{B}temp)(temp)
    }
\end{pspicture}
\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.