3

The following code gives the graph of two lines on the Cartesian plane. (I specify the lines by the angles at which they are inclined with respect to the positive x-axis. I doubt the code that I provide is efficient for doing this.) I am trying to get TikZ to draw these lines, with arrowheads, so that the coordinates of the points on these lines are between -3.75 and 3.75. Visually, these lines will be bounded by a square with sides parallel to the axes and 3.75 units from them. (The arrowheads of the axes intersect a square with sides parallel to the axes and 4 units from them.) I tried to use the intersections package. TikZ would not compile the last six commands, though.

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


\begin{document}



\begin{tikzpicture}[outer sep=0pt,p/.style={circle, fill,inner sep=1.5pt}]

\draw[draw=gray!30,latex-latex] (-3.75,0) +(-0.25cm,0) -- (3.75,0) -- +(0.25cm,0) node[below right] {$x$};

\clip (-3.75,-3.75) rectangle (3.75,3.75);

\draw[gray,dashed,line width=0.1pt] (-3.75,3.75) -- (3.75,3.75);
\draw[gray,dashed,line width=0.1pt] (-3.75,-3.75) -- (3.75,-3.75);
\draw[gray,dashed,line width=0.1pt] (-3.75,-3.75) -- (-3.75,3.75);
\draw[gray,dashed,line width=0.1pt] (3.75,-3.75) -- (3.75,3.75);

\draw[draw=blue!30,-latex] (0,0) -- (142:5);
\draw[draw=blue!30,-latex] (0,0) -- (-38:5);
\draw[draw=green!50,-latex] (0,0) -- (52:5);
\draw[draw=green!50,-latex] (0,0) -- (-128:5);

\coordinate[p,label={[fill=white]below right:$O$}] (O) at (0,0);

\coordinate (A) at (0:1);
\coordinate (B) at (52:1);
\path pic[draw, angle radius=5mm,"$\phi$",angle eccentricity=1.25] {angle = A--O--B};

\coordinate (a) at (180:1);
\coordinate (b) at (142:1);
\path pic[draw, angle radius=5mm,"$\theta$",angle eccentricity=1.25] {angle = b--O--a};

\coordinate (P) at (142:1);
\coordinate (Q) at (52:1);

\coordinate (R) at ($(O)!4mm! -45:(P)$);
\draw (R) -- ($(O)!(R)!(P)$);
\draw (R) -- ($(O)!(R)!(Q)$);

%The following code makes the right-angle mark and "colors" the inside of it white.
\begin{scope}[on background layer]
\draw[draw=gray!30,latex-latex] (0,3.75) +(0,0.25cm) node[above right] {$y$} -- (0,-3.75) -- +(0,-0.25cm);
\filldraw[fill=white] (O.center) -- ($(O)!(R)!(P)$) -- (R) -- ($(O)!(R)!(Q)$) -- cycle;
\end{scope}


%The following code is for placing arrowheads at the ends of the line segments.
%\path[name intersections={of=(-3.75,3.75) -- (3.75,3.75) and (0,0) -- (52:5), by=intersection-1}];
%\path[name intersections={of=(3.75,3.75) -- (3.75,-3.75) and (0,0) -- (-38:5), by=intersection-2}];
%\path[name intersections={of=(-3.75,-3.75) -- (3.75,-3.75) and (0,0) -- (-128:5), by=intersection-3}];
%\path[name intersections={of=(-3.75,3.75) -- (-3.75,-3.75) and (0,0) -- (142:5), by=intersection-4}];

%\draw[draw=green!50,latex-latex] (intersection-1) -- (intersection-3);
%\draw[draw=blue!30,latex-latex] (intersection-2) -- (intersection-4);

\end{tikzpicture}

\end{document}
  • I'm not sure I understand, could you provide a mock-up image of your intended goal? Or maybe reword it here in the comments. – Alenanno Apr 28 '15 at 16:46
  • About the last two lines, have you read the error message? It's quite self-explanatory: Error: No shape named R is known. You haven't defined a shape named R. – Alenanno Apr 28 '15 at 16:56
  • @Alenanno That is ridiculous. I have edited the post. – user74973 Apr 28 '15 at 17:22
  • I still don't understand what you want though. You want the diagonal paths to start and end at certain points, which ones? Do they need to be 45 degrees? Or others? Even a sketched mock-up image would be nice. – Alenanno Apr 28 '15 at 21:47
  • @Alenanno I don't know how to post a sketched mock-up image. (I am sure that my old computer would not be able to do it.) I want to draw two lines, with arrowheads, through the origin; they are to be at angles of 52 degrees and of 142 degrees, respectively; they are to be kept within a square, which is not drawn, centered at the origin that is 7.5 units wide and 7.5 units high. – user74973 Apr 28 '15 at 22:24
2

A line through the origin (0,0) with angle 52 degrees intersects a rectangle defined by corners (-3.75,-3.75) and (3.75,3.75) at point (52:{3.75/sin(52)}) while at angle 142 is (142:{3.75/cos(142)}).

\documentclass[10pt, border=5mm, tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,quotes}

\begin{document}    
\begin{tikzpicture}[outer sep=0pt,p/.style={circle, fill,inner sep=1.5pt}]

\draw[help lines] (-3.75,-3.75) rectangle (3.75,3.75);

\draw[draw=blue,latex-latex] (-4,0) coordinate (a) -- (4,0) coordinate (A) node[below right] {$x$};
\draw[draw=blue,latex-latex] (0,4) node[above right] {$y$} -- (0,-4);

\draw[red,latex-latex] (52:{3.75/sin(52)}) coordinate (B)--(52:{-3.75/sin(52)});
\draw[green,latex-latex] (142:{3.75/cos(142)}) --(142:{-3.75/cos(142)}) coordinate (b);

\coordinate[p,label={[fill=white]below right:$O$}] (O) at (0,0);

\path pic[draw, angle radius=5mm,"$\phi$",angle eccentricity=1.25] {angle = A--O--B};

\path pic[draw, angle radius=5mm,"$\theta$",angle eccentricity=1.25] {angle = b--O--a};

\coordinate (R) at ($(O)!4mm! -45:(b)$);
\draw (R) -- ($(O)!(R)!(b)$);
\draw (R) -- ($(O)!(R)!(B)$);

\end{tikzpicture}

\end{document}

enter image description here

| improve this answer | |
  • Yes, this is the display that I wanted. Thanks. You changed the code so that the lines are defined via rectangular coordinates. I was trying to use this as an example of plotting a line by using a path command on points specified using polar coordinates. – user74973 Apr 29 '15 at 12:18
  • @user74973 I've updated the answer. Now it uses polar coordinates and the trigonometry is correct. Previous answer was wrong. – Ignasi Apr 29 '15 at 17:09
  • I didn't know TikZ would calculate the radius of a point given in polar coordinates. You use {3.75/sin(52)} for the radius of the point, expressed in polar coordinates, at which the red line intersects the top side of the square, and you use {3.75/cos(142)} for the radius of the point, expressed in polar coordinates, at which the green line intersects the left side of the square. Nice. – user74973 Apr 30 '15 at 16:59
1

I think that I know what you mean. Look at the following code. I have the lines bounded by a square that is 2(3.75) = 7.5 centimeters wide and tall. The arrowheads got clipped, though.

\documentclass[10pt]{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,quotes}


\begin{document}


\begin{tikzpicture}[outer sep=0pt,p/.style={circle, fill,inner sep=1.5pt}]

\draw[draw=gray!30,latex-latex] (-3.75,0) +(-0.25cm,0) -- (3.75,0) -- +(0.25cm,0) node[below right] {$x$};
\draw[draw=gray!30,latex-latex] (0,3.75) +(0,0.25cm) node[above right] {$y$} -- (0,-3.75) -- +(0,-0.25cm);

\clip (-3.75,-3.75) rectangle (3.75,3.75);

\draw[gray,dashed,line width=0.1pt] (-3.75,3.75) -- (3.75,3.75);
\draw[gray,dashed,line width=0.1pt] (-3.75,-3.75) -- (3.75,-3.75);
\draw[gray,dashed,line width=0.1pt] (-3.75,-3.75) -- (-3.75,3.75);
\draw[gray,dashed,line width=0.1pt] (3.75,-3.75) -- (3.75,3.75);

\draw[draw=blue!30,-latex] (0,0) -- (142:5);
\draw[draw=blue!30,-latex] (0,0) -- (-38:5);
\draw[draw=green!50,-latex] (0,0) -- (52:5);
\draw[draw=green!50,-latex] (0,0) -- (-128:5);

\coordinate[p,label={[fill=white]below right:$O$}] (O) at (0,0);

\coordinate (A) at (0:1);
\coordinate (B) at (52:1);
\path pic[draw, angle radius=5mm,"$\phi$",angle eccentricity=1.25] {angle = A--O--B};

\coordinate (a) at (180:1);
\coordinate (b) at (142:1);
\path pic[draw, angle radius=5mm,"$\theta$",angle eccentricity=1.25] {angle = b--O--a};

\coordinate (P) at (142:1);
\coordinate (Q) at (52:1);

\coordinate (R) at ($(O)!4mm! -45:(P)$);
\draw (R) -- ($(O)!(R)!(P)$);
\draw (R) -- ($(O)!(R)!(Q)$);

\end{tikzpicture}

\end{document}
| improve this answer | |

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.