Diagrams in LaTeX – How to Draw a Diagram in LaTeX

diagrams

I am trying to draw a ripple pendulum similar to the below diagram but have absolutely no idea how to start, or even if it can be done in LaTeX? Another complication is I need it to have a purple background

backgroundcolor=blue!20

Here is the diagram I am trying to draw. Thank you for any help or guidance 🙂
enter image description here

Best Answer

One LaTeX-friendly tool for doing this type of drawing is MetaPost. Getting started details are in the linked answer.

One technique for filling the background of an image, is to save the whole drawing in a picture variable, and then fill the bbox of the picture with the background colour, and then draw the picture on top.

Here's an example using a version of the OP image.

enter image description here

prologues := 3;
outputtemplate := "%j%c.eps";

beginfig(1);

u = 1.4cm;

numeric theta[];
theta1 = 12;
theta2 = 24;
theta3 = 36;

path segment[];
segment1 = (origin -- down) scaled 1.2u rotated theta1;
segment2 = (origin -- down) scaled 1.2u rotated theta2 shifted point 1 of segment1;
segment3 = (origin -- down) scaled 1.2u rotated theta3 shifted point 1 of segment2;

picture pendulum;
pendulum = image(
    draw (left--right) scaled 2u;
    for i=1 upto 3:
      draw segment[i];
      draw (origin--down) scaled 1u
                          shifted point 0 of segment[i] 
                          dashed withdots scaled 1/3;
      label.urt(btex $\ell$ etex, point 1/2 of segment[i]);
      label.urt(btex $m$    etex, point   1 of segment[i]);
      draw subpath(0, 1/45 (theta[i]-8)) of fullcircle 
           rotated 274 scaled .6u shifted point 0 of segment[i]
           withpen pencircle scaled .3;  
    endfor
    for i=1 upto 3:
      fill fullcircle scaled 4 shifted point 1 of segment[i] withcolor .87 blue;
    endfor
    label(btex $\theta_1$ etex scaled 0.8, point 0 of segment1 shifted (-6,-12));
    label(btex $\theta_2$ etex scaled 0.8, point 0 of segment2 shifted ( 6,-25));
    label(btex $\theta_3$ etex scaled 0.8, point 0 of segment3 shifted ( 8,-20));
);

bboxmargin := 10;
fill bbox pendulum withcolor .2[white,blue];
draw pendulum;

endfig;
end.
Related Question