[Tex/LaTex] How to create MetaPost image for LaTeX

metapost

im trying to figure out how to create this image in metapost

Im trying to figure out how to create this image in MetaPost

Best Answer

UPDATE

I have made some adjustments and added some explanation on the methods used. Note I changed the color names just for compatibility reasons.

enter image description here

\documentclass{article}
\usepackage{amsmath,amssymb}
%-------------------------------------------------------------------------------------
% The caption package is used just to illustrate the caption shown in the image.
\usepackage{caption}
\captionsetup[figure]{font={bf},format=plain}
%-------------------------------------------------------------------------------------
\usepackage[shellescape]{gmp}
\begin{document}
Angles may be measured in degrees or radians. Using the relationship $\pi \text{ radians } = 180^\circ $, we gather that 
    \[1 \text{ radian } = \frac{180^\circ}{\pi}\; (\approx 57.3 \text{ degrees})\]
See Figure~\ref{fig:radian} for an illustration of the size of a radian.
\begin{figure}
\centering
\begin{mpost}
    % Let us define the colours to be used similar to the dvipsnames OrangeRedMP and CeruleanMP
    %-------------------------------------------------------------------------------------
    % Stating the names of new colors. MetaPost only accepts RGB.
    color OrangeRedMP; 
    color CeruleanMP;
    OrangeRedMP = (236/256,13/256,88/256); 
    CeruleanMP = (19/256,163/256,229/256);
    %-------------------------------------------------------------------------------------
    % Defining the nodes for the axis and their coordinates
    pair A,B,C,D,E;
    A := (-2.5cm,0); B := (2.5cm,0); C := (0,-2.5cm); D := (0,2.5cm); 
    %-------------------------------------------------------------------------------------
    % Defining the value of pi to calculate the value of a radian
    numeric pi; pi := 3.1415926;
    numeric radian; radian := 180/pi;
    %-------------------------------------------------------------------------------------
    % Draw the axis with arrows and labeling them
    drawarrow A -- B;
    drawarrow C -- D;
    label.rt  (btex $x$ etex,B);
    label.top (btex $y$ etex,D);
    %-------------------------------------------------------------------------------------
    % Other labels of the diagram
    label.llft(btex $0$ etex,origin);
    label.bot (btex $r$ etex,origin) shifted (0.75cm,0cm) withcolor OrangeRedMP;
    label.rt  (btex $\theta=1$ radian etex,C) shifted (0.5cm,0.3cm);
    %-------------------------------------------------------------------------------------
    % Angle theta with label
    label (btex $\theta$ etex,origin+dir(radian/2)*5mm) withcolor OrangeRedMP;
    drawarrow 0.75cm * dir 0 {dir 90} ..
              0.75cm * dir radian {dir(90+radian)} withcolor OrangeRedMP;
    %-------------------------------------------------------------------------------------
    % Circle scaled
    draw fullcircle scaled 3cm withcolor CeruleanMP; 
    % Comment the line above and uncomment below to see increased line width
    %draw fullcircle scaled 3cm withpen pencircle scaled 1.1 withcolor CeruleanMP;
    %-------------------------------------------------------------------------------------
    % Rays containing 1 radian  
    drawarrow (0,0) -- 2cm*dir 0 withcolor OrangeRedMP;
    drawarrow (0,0) -- 2cm*dir radian withcolor OrangeRedMP;
    %-------------------------------------------------------------------------------------
    % Defining arc of length of r and label
    path arc;
    arc = 1.5cm * dir 0 {dir 90} ..
          1.5cm * dir radian {dir(90+radian)};
    % Define position of radius label on arc and putting the label
    E := point(0.5) of arc; 
    label.urt (btex $r$ etex, E) withcolor OrangeRedMP;
    % Draw arc
    draw arc withcolor OrangeRedMP;
\end{mpost}
\caption{}
\label{fig:radian}
\end{figure}
\end{document}

This is the old MWE for reference:

enter image description here

\documentclass{article}
\usepackage[shellescape]{gmp}
\begin{document}
\begin{mpost}
%beginfig(1};
    color OrangeRed;
    color Cerulean;
    OrangeRed = (236/256,13/256,88/256);
    Cerulean = (19/256,163/256,229/256);
    pair A,B,C,D;
    A := (-2.5cm,0); B := (2.5cm,0); C := (0,-2.5cm); D := (0,2.5cm);
    numeric pi; pi := 3.1415926;
    numeric radian; radian := 180/pi;
    drawarrow A -- B;
    drawarrow C -- D;
    label.rt  (btex $x$ etex,B);
    label.top (btex $y$ etex,D);
    label.llft(btex $0$ etex,origin);
    label.urt (btex $\theta$ etex,origin) shifted (0.25cm,0cm) withcolor OrangeRed;
    label.bot (btex $r$ etex,origin) shifted (0.75cm,0cm) withcolor OrangeRed;
    label.urt (btex $r$ etex,origin) shifted (1.35cm,0.6cm) withcolor OrangeRed;
    label.rt  (btex $\theta=1$ radian etex,C) shifted (1.5cm,0.3cm);
    draw fullcircle scaled 3cm withcolor Cerulean;
    drawarrow (0,0) -- 2cm*dir 0 withcolor OrangeRed;
    drawarrow (0,0) -- 2cm*dir radian withcolor OrangeRed;
    draw 1.5cm * dir 0 {dir 90} ..
         1.5cm * dir radian {dir(90+radian)} withcolor OrangeRed;
    drawarrow 0.75cm * dir 0 {dir 90} ..
              0.75cm * dir radian {dir(90+radian)} withcolor OrangeRed;

%endfig;
\end{mpost}
\end{document}
Related Question