Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I've tried to make a unit circle to explain the angles, but the circle is not on the right place within the defined axes. Am I using the wrong method? Or can't I use the axis definition as in the code. I also want the intersection of the segment and the circle to define sin and cos of the angle (but that I think I will find later with the tkz-euclide)

My code:

\documentclass[11pt,a4paper]{article} % use larger type; default would be 10pt
\usepackage{tikz}
\usepackage{tkz-euclide}
\usetkzobj{all} %% om allerhande objecten te gebruiken zoals gradenboog...
\usetikzlibrary{calc,intersections,through,backgrounds,snakes}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\usepgfplotslibrary{statistics}
\begin{document}
 \begin{tikzpicture}
 \begin{axis}%
 [
    grid=major, 
    x=50mm,
    y=50mm,
    xmin=-1.1, xmax=1.1,
    xtick={-1,0,1},   
    minor xtick={-1,-0.9,...,1},
    xminorgrids = true,
    xlabel={\tiny $x$},
    axis x line=middle,
    ymin=-1.1, ymax=1.1,
    ytick={-1,0,1},
    minor ytick={-1,-0.9,...,1},
    yminorgrids = true,
    ylabel={\scriptsize $y$},
    axis y line=middle,
    no markers,
    samples=100,
    ]

 \draw[blue] (axis cs:0,0) circle[radius=1];
 \end{axis}     
 \tkzDefPoint(0,0){A}
 \tkzDrawCircle[R](A,5cm)
 \tkzDefPoint[shift={(0,0)}](0:5.2){B}
 \tkzDefPoint[shift={(0,0)}](50:5.2){C}
 \tkzDefPoint[shift={(0,0)}](130:5.2){D}

 \tkzDrawSegments[color = red, line width = 1pt](A,B A,C)
 \tkzDrawSegments[color = blue, line width = 1pt](A,B A,D)

 \tkzDrawPoints(A) \tkzLabelPoints(A)
 \tkzMarkAngle[fill= blue,size=2.5cm, opacity=.4](B,A,D);
 \tkzMarkAngle[fill= red,size=1.5cm, opacity=.7](B,A,C);

 \tkzFindAngle(B,A,C) \tkzGetAngle{angleBAC}; 
 \FPround\angleBAC\angleBAC{0}
 \tkzLabelAngle[pos = 1](B,A,C){\angleBAC$^\circ$ };

 \tkzFindAngle(B,A,D) \tkzGetAngle{angleBAD};
 \FPround\angleBAD\angleBAD{0}
 \tkzLabelAngle[pos = 2](B,A,D){\angleBAD$^\circ$ };    

 \end{tikzpicture}
\end{document}

I also have the problem when the angle > 180 it gives the wrong angle, because \tkzGetAngle only works in the interval -180° +180°.

unit circle

share|improve this question

1 Answer 1

up vote 4 down vote accepted

You sort of ask three quite different questions. For the first:

By default the anchor of a pgfplots axis is set to south west, and the position is set to (0,0) in the coordinate system of tikzpicture. You can change the position with at={(x,y)}, but as your circle is set around (0,0) that isn't necessary. You just need to add anchor=center to the axis options.

For the second:

To get the intersection between the line segments and the circle you can use

\tkzInterLC[R](A,C)(A,5cm)\tkzGetSecondPoint{CC} 
\tkzInterLC[R](A,D)(A,5cm)\tkzGetSecondPoint{DC}

CC and DC is the intersections. In the below code I've drawn and labeled those points, but I haven't drawn the lines corresponding to the sine and cosine.

enter image description here

\documentclass[11pt]{standalone} % use larger type; default would be 10pt
\usepackage{tikz}
\usepackage{tkz-euclide}
\usetkzobj{all} %% om allerhande objecten te gebruiken zoals gradenboog...
\usetikzlibrary{calc,intersections,through,backgrounds,snakes}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\usepgfplotslibrary{statistics}
\begin{document}
 \begin{tikzpicture}
 \begin{axis}%
 [
    anchor=center,  % sets axis anchor to the axis origin
    grid=major, 
    x=50mm,
    y=50mm,
    xmin=-1.1, xmax=1.1,
    xtick={-1,0,1},   
    minor xtick={-1,-0.9,...,1},
    xminorgrids = true,
    xlabel={\tiny $x$},
    axis x line=middle,
    ymin=-1.1, ymax=1.1,
    ytick={-1,0,1},
    minor ytick={-1,-0.9,...,1},
    yminorgrids = true,
    ylabel={\scriptsize $y$},
    axis y line=middle,
    no markers,
    samples=100,
    ]

 \draw[blue] (axis cs:0,0) circle[radius=1];
 \end{axis}     
 \tkzDefPoint(0,0){A}
 \tkzDrawCircle[R](A,5cm)
 \tkzDefPoint[shift={(0,0)}](0:5.2){B}
 \tkzDefPoint[shift={(0,0)}](50:5.2){C}
 \tkzDefPoint[shift={(0,0)}](130:5.2){D}

 \tkzDrawSegments[color = red, line width = 1pt](A,B A,C)
 \tkzDrawSegments[color = blue, line width = 1pt](A,B A,D)


 % Finds the intersections of segments and circle
 \tkzInterLC[R](A,C)(A,5cm)\tkzGetSecondPoint{CC}
 \tkzInterLC[R](A,D)(A,5cm)\tkzGetSecondPoint{DC}

 % draw and label points
 \tkzDrawPoints(A,CC,DC) \tkzLabelPoints(A,CC,DC)

 \tkzMarkAngle[fill= blue,size=2.5cm, opacity=.4](B,A,D);
 \tkzMarkAngle[fill= red,size=1.5cm, opacity=.7](B,A,C);

 \tkzFindAngle(B,A,C) \tkzGetAngle{angleBAC}; 
 \FPround\angleBAC\angleBAC{0}
 \tkzLabelAngle[pos = 1](B,A,C){\angleBAC$^\circ$ };

 \tkzFindAngle(B,A,D) \tkzGetAngle{angleBAD};
 \FPround\angleBAD\angleBAD{0}
 \tkzLabelAngle[pos = 2](B,A,D){\angleBAD$^\circ$ };    

 \end{tikzpicture}
\end{document}
share|improve this answer
    
+1. Very pretty solution. I's typing one using \begin{scope}[xshift=5.5cm,yshift=5.5cm]\end{scope} to affect the second part of the code. –  Sigur Dec 30 '13 at 10:51
    
@Sigur don't understand your comment. Where should I put your code? As Torbjørn T. code is working for me. –  Arne Dec 30 '13 at 12:42
1  
@Arne, don't worry. I was saying that my solution was not so pretty. You don't need to use my code. –  Sigur Dec 30 '13 at 13:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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