How to draw the following diagram with tikz?

Also available in Metapost...

enter image description here

\RequirePackage{luatex85}
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);

    path xx, yy, circle;
    pair O, A, B, C, D, E;
    numeric theta;

    xx = (6 left -- 6 right) scaled 1cm;
    yy = (1 down -- 6 up) scaled 1cm;
    circle = fullcircle scaled 10cm;

    theta = 42;

    O = origin;
    A = point 0 of circle;
    B = point theta * 8 / 360 of circle;
    C = (xpart B, 0);
    D = whatever[O,B]; D-A = whatever * up;
    E = whatever[A,D]; B-E = whatever * (B-O) rotated 90;

    drawarrow xx withpen pencircle scaled .8;
    drawarrow yy withpen pencircle scaled .8;
    draw subpath (-1/4, 17/4) of circle withcolor .67 red;

    draw E--B dashed evenly scaled 1/2 withcolor .75 blue;
    draw A--B dashed evenly scaled 1/2 withcolor .75 blue;

    draw A--D--O;
    draw C--B;

    label.rt  ("$x$", point 1 of xx);
    label.top ("$y$", point 1 of yy);

    label.llft("$\scriptstyle O$", O);
    label.lrt ("$\scriptstyle A$", A);
    label.top ("$\scriptstyle B$", B + 3 up);
    label.bot ("$\scriptstyle C$", C);
    label.top ("$\scriptstyle D$", D);
    label.rt  ("$\scriptstyle E$", E);

    label.ulft("$1$", 1/2 B);
    label.bot("$\cos\theta$", 1/2 C);

    path a; a = fullcircle scaled 42 cutafter (O--B);
    interim ahangle := 25; 
    drawarrow a withcolor .5 white;
    label.rt("$\theta$", point .5 of a);

    picture t;
    t = thelabel("$\theta$", point 1/2 theta * 8 / 360 of circle);
    unfill bbox t; draw t;

endfig;
\end{mplibcode}
\end{document}

Notes

  • left, right, up, and down are defined in plain MP to be the pairs (-1,0), (1,0), (0,1), and (0,-1). So they are convenient for describing the axes, as variations on the path left -- right. I could have written: xx = (-6cm,0) -- (6cm,0); instead, but I like using the names instead of the numbers.

  • fullcircle is also defined in plain MP, to be a circle with unit diameter, so to get a circle with a 5cm radius, I have defined fullcircle scaled 10cm.

  • fullcircle is defined in plain MP to have 8 "points" starting at 3 o'clock (as it were) and going round counter clockwise, so that 12 o'clock is point 2, and 6 o'clock is point 6, and so on. The construction point theta / 8 * 360 of circle gives the point that is theta degrees counter clockwise from point 0.


A bit crude, but given the angle a, the required point E is at (1,(1-cos(a))/sin(a)) or (1,cosec(a)-cot(a))

\documentclass[tikz,margin=5]{standalone}
\usetikzlibrary{angles,quotes}
\begin{document}
\begin{tikzpicture}[x=4cm, y=4cm, axes/.style={thin, gray, ->},
  dot/.style={.. dot={#1:0:;}}, 
  .. dot/.style args={#1:#2:#3;}{insert path={ 
    coordinate (#1) 
    node [circle, fill, inner sep=0, minimum size=2pt,label=#2:#1]{}
  }}]
\clip (-0.25, -0.25) rectangle (1.5,1.5);
\draw[axes] (-1.2,0) -- (1.2,0) node[right] {$x$};
\draw[axes] (0,-1.2) -- (0,1.2) node[above] {$y$};
\def\a{40}
\path
  (0,0)  [dot=O:225] 
  (0:1)  [dot=A:315]
  (\a:1) [dot=B:90]  
  (0:cos \a) [dot=C:270]
  (\a:sec \a) [dot=D]
  (1, cosec \a-cot \a) [dot=E];
\draw (O) circle[radius=1];
\draw (O) -- (B) -- (C);
\draw (B) -- (D) -- (A);
\draw [dashed] (B) -- (A);
\draw [dashed] (B) -- (E);
\pic ["$\theta$", draw, ->, angle radius=1cm] {angle=C--O--B};
\path (O) -- (B) node [midway, above] {$1$};
\path (O) -- (C) node [midway, below] {$\cos\theta$};
\end{tikzpicture}
\end{document}

enter image description here


Asymptote MWE:

//
// theta.asy
//
// To get theta.pdf, run 
//
// asy theta.asy
//

settings.tex="pdflatex";
import graph;
size(5cm);
import fontsize;defaultpen(fontsize(9pt));
texpreamble("\usepackage{lmodern}"
+"\usepackage{amsmath}"
+"\usepackage{amsfonts}"
+"\usepackage{amssymb}"
);

real w=0.5bp;
pen linePen=darkblue+w;
pen arcPen=orange+w;
pen markPen=gray(0.3)+w;
pen axisPen=gray(0.3)+w;
pen dashPen=gray(0.3)+w+linetype(new real[]{5,5})+squarecap;
arrowbar arr=Arrow(HookHead,size=2);

xaxis("$x$",0,1.1,axisPen,arr);
yaxis("$y$",0,1.1,axisPen,arr);

real R=1,theta=42;
pair O,A,B,C,D,E;

guide gc=Arc(O,R,-4,94);
A=(R,0); B=rotate(theta)*A; C=(B.x,0);
D=extension(O,B,A,A+(0,1));
E=extension(A,D,B,B+rotate(90)*(B-O));
draw(gc,arcPen);
draw(B--C^^O--D--A,linePen);
draw(A--B--E,dashPen);

pair[] p={O,A,B,C,D,E};
string[] lab={"O","A","B","C","D","E"};
pair[] dp={plain.SW,plain.SW,plain.N,plain.S,plain.N,plain.E,};
for(int i=0;i<p.length;++i){
    dot(p[i],UnFill);
    label(lab[i],p[i],dp[i]);
}

draw("$\theta$",arc(O,0.12,0,theta),markPen);
label("$1$",(O+B)/2,UnFill);
label("$\cos\theta$",(O+C)/2,UnFill);

enter image description here