A new AI-enabled workflow for generating diagrams for questions

In recent years, AI tools like DALL-E and MidJourney have gained popularity for generating stunning, artistic images. However, when it comes to creating scientific illustrations, particularly for exams, we need accuracy, clarity, and precision. This is where LaTeX, a document preparation system widely used in academia, shines. Combined with the intelligence of ChatGPT, LaTeX can produce exactly the images you need without the artistic flair or ambiguity that tools like DALL-E might introduce.

The process of generating science exam images using ChatGPT and LaTeX is straightforward:

  1. Describe the Diagram: You begin by providing a detailed description of the diagram or scientific illustration you need. For example, “Generate a diagram using Latex showing a free-body diagram of a block on an inclined plane with friction.”
  2. ChatGPT Generates LaTeX Code: Based on your description, ChatGPT can generate the appropriate LaTeX code, using packages like TikZ or PGFPlots to create the required scientific diagram. The output might look like this:
    \documentclass{standalone}
    \usepackage{tikz}
    \begin{document}
    \begin{tikzpicture}
    % Inclined plane
    \draw[thick] (0,0) -- (4,2);
    \draw[thick] (0,0) -- (4,0);
    % Block
    \draw[fill=gray] (2,1) rectangle (2.5,1.5);
    % Forces
    \draw[->,thick] (2.25,1.25) -- (2.25,2.25) node[above] {Normal Force};
    \draw[->,thick] (2.25,1.25) -- (2.25,0.25) node[below] {Weight};
    \draw[->,thick] (2.25,1.25) -- (3.25,1.25) node[right] {Friction};
    \end{tikzpicture}
    \end{document}
  3. Compile the LaTeX Code: Once the code is generated, you can compile it using any LaTeX editor (such as Overleaf or a local LaTeX distribution).
  4. Check for Errors: The diagram is unlikely to look perfect in the first iteration. For example, the above code gives the following:
  5. Edit: You can either instruct ChatGPT to modify specific sections of the diagram or make the changes yourself. After 3 more iterations, for example, ChatGPT produced the following codes:
    \begin{tikzpicture}
    % Inclined plane
    \draw[thick] (0,0) -- (4,2);
    \draw[thick] (0,0) -- (4,0);
    % Block (rotated to match the slope)
    \draw[fill=gray, rotate around={26.565:(2.25,1.25)}] (2,1) rectangle (2.5,1.5);
    % Forces (adjusted for friction up the slope)
    % Normal Force (perpendicular to the slope)
    \draw[->,thick] (2.25,1.25) -- ++(-0.447,0.894) node[above left] {Normal Force};
    % Weight (straight down)
    \draw[->,thick] (2.25,1.25) -- (2.25,0.25) node[below] {Weight};
    % Friction (along the slope, now pointing up the incline)
    \draw[->,thick] (2.25,1.25) -- ++(0.894,0.447) node[above right] {Friction};
    \end{tikzpicture}
  6. This is the output image:
  7. Integrate into Teaching Materials: Once you are satisfied with the output, the compiled image can then be saved as a PDF, PNG, or any other image format and directly embedded into your exam materials.

The following are similar images made using the same workflow and their corresponding codes, which I made changes to manually instead as it was faster for me once I became familiar with the coordinate-system based drawing method.

      \begin{tikzpicture}
        
        % Draw the base container (mercury reservoir)
        \draw[draw=none, fill=gray!30] (-2,-0.2) rectangle (2,-1);
        \draw[thick] (-2,-1) -- (-2,0.4);
        \draw[thick] (2,-1) -- (2,0.4);
        \draw[thick] (-2,-1) -- (2,-1);
        \draw[thick] (-2,-0.2) -- (-0.1,-0.2);
        \draw[thick] (0.1,-0.2) -- (2,-0.2);
                
        
        % Mercury inside the tube
        \draw[draw=none, fill=gray!30] (-0.1,3) -- (-0.1,-0.3) -- (0.1,-0.3) -- (0.1,3) -- cycle;
        \draw[thick] (-0.1,3) -- (0.1,3);
        
        % Draw the glass tube
        \draw[thick] (0.1,4) -- (0.1,-0.4); % Tube
        \draw[thick] (-0.1,4) -- (-0.1,-0.4); % Tube
        % Label for the mercury level
        \draw[<-] (0,2) -- (-1.1,2) node[left]{mercury column};
        \draw[<-] (0,3.7) -- (-1.1,3.7) node[left]{vacuum};
        \draw[thick] (0,4) ++(0:0.1cm) arc (0:180:0.1cm);
        
        % Labels for height
        \draw[<->] (0.5,3) -- (0.5,-0.2) node[midway,right]{h};
        
        % Add some text labels
        \node at (0,-1.5) {mercury reservoir};
        
        \end{tikzpicture} 
\begin{tikzpicture}

        % Draw principal axis
        \draw[thick] (-5,0) -- (2,0) node at (-4.5,0.2) {principal axis};
    
        % Draw the lens
        \draw[thick] (-2,-1.5) arc[start angle=270, end angle=90, x radius=0.15cm, y radius=1.5cm];
        \draw[thick] (-2,1.5) arc[start angle=90, end angle=270, x radius=-0.15cm, y radius=1.5cm];
    
        % Draw the focal points
        \node at (1, 0) [above] {focal point, $F$};
        \draw[fill] (1, 0) circle [radius=0.05];
        \node at (-2, 0) [below] {optical centre};
        \draw[fill] (-2, 0) circle [radius=0.05];    
        % Draw the 3 rays parallel to the principal axis (before hitting the lens)
        \draw[thick] (-5,1) -- (-2,1);
        \draw[thick] (-5,0.5) -- (-2,0.5);
        \draw[thick] (-5,-0.5) -- (-2,-0.5);
        \draw[thick] (-5,-1) -- (-2,-1);
        \draw[thick, ->] (-4,1) -- (-3,1);
        \draw[thick, ->] (-4,0.5) -- (-3,0.5);
        \draw[thick, ->] (-4,-0.5) -- (-3,-0.5);
        \draw[thick, ->] (-4,-1) -- (-3,-1);
        \draw[thick, ->] (-4,0) -- (-3,0);
    
        % Rays converging to the focal point F
        \draw[thick] (-2,1) -- (1,0);
        \draw[thick] (-2,0.5) -- (1,0);
        \draw[thick] (-2,-0.5) -- (1,0);
        \draw[thick] (-2,-1) -- (1,0);
        \draw[thick, ->] (-2,1) -- (-0.5,0.5);
        \draw[thick, ->] (-2,0.5) -- (-0.5,0.25);
        \draw[thick, ->] (-2,0) -- (-0.5,0);
        \draw[thick, ->] (-2,-0.5) -- (-0.5,-0.25);
        \draw[thick, ->] (-2,-1) -- (-0.5,-0.5);
    
        \node at (-0.5, 1.3) {converging lens};
        % Focal length
        \draw[thick, <->] (-2,-1.2) -- (1,-1.2);
        \node at (-0.5, -1.5) {focal length, $f$};        
    \end{tikzpicture}
 \begin{tikzpicture}
        % Draw the wave
        \draw[thick, domain=0:6.28, smooth, variable=\x] plot ({\x}, {sin(2*\x r)});
        
        % Draw the x-axis
        \draw[->] (0, 0) -- (6.5, 0) node at (6.4,0.3) {distance};
        
        % Draw the y-axis
        \draw[->] (0, -1.5) -- (0, 1.5) node[above] {displacement};
        
        % Draw the amplitude arrow
        \draw[<->, thick] (0.785, 0) -- (0.785, 1) node[midway, right] {amplitude};
    
        % Draw the wavelength arrow
        \draw[<->, thick] (0.785, 1.1) -- (3.925, 1.1) node at (2.355,1.4) {wavelength};
    
        % Label the points
        \node at (-0.2, 1) {$A$};
        \node at (-0.3, -1) {$-A$};
        \node at (3.14, -0.2) {$\lambda$};
        \node at (6.28, -0.2) {2$\lambda$};
        \end{tikzpicture}

Turning Effect due to Non-Perpendicular Forces

When applying the principle of moments to calculate the magnitude of a force creating a turning effect, where the force is not perpendicular to the length of the object, there are two approaches.

Take the following problem:

A uniform rectangular beam has negligible thickness and weight 850 N. Its length is 5.0 m and it is in contact with the top of a support at point P. P is 0.80 m from one end of the beam.

The beam is held stationary, at an angle of 30° to the horizontal, by a rope that is attached to the bottom corner of the other end of the beam.

Calculate the magnitude of the force T on the beam due to the tension in the rope.

Approach 1: Identifying the perpendicular distance between line of action of the force and pivot

In the applet above, check the box that says “Show perp dist” to see the lines representing the perpendicular distances between each line of action of the force and the pivot P.

Taking moments about P,

Clockwise moment due to T = Anti-clockwise moment due to W

$$T \times (5.0\text{ m} – 0.8\text{ m}) \sin 30^{\circ} = W \times (\dfrac{5.0\text{ m}}{2} – 0.8\text{ m}) \cos 30^{\circ}$$

$$T \times 2.10 \text{ m} = 850 \text{ N} \times 1.472 \text{ m}$$

$$T = 596 \approx 600 \text{ N}$$

Approach 2: Resolving the forces to obtain components of forces perpendicular to the beam

In the same applet, check the box that says “Resolve forces”

Taking moments about P,

Clockwise moment due to $T_{\perp}$ = Anti-clockwise moment due to $W_{\perp}$

$$T \sin 30^{\circ} \times (5.0\text{ m} – 0.8\text{ m}) = 850 \text{ N} \cos 30^{\circ} \times (\dfrac{5.0\text{ m}}{2} – 0.8\text{ m})$$

$$T \times 0.500 \times 4.2 \text{ m} = 850 \text{ N} \times 0.866 \times 1.7 \text{ m}$$

$$T = 596 \approx 600 \text{ N}$$

DC Circuits Practice

The simulation below allows students to practise calculating potential differences and currents of a slightly complex circuit, involving three different modes that can be toggled by clicking on the switch.

Link: https://www.geogebra.org/m/jkckp9pr

Mode 1: Two Resistors in Series

When resistors \( R_1 \) and \( R_2 \) are connected in series, the total resistance is simply the sum of the individual resistances:

\[ R_{\text{total}} = R_1 + R_2 \]

The current \( I \) through the circuit is given by Ohm’s Law:

\[ I = \frac{V_{\text{total}}}{R_{\text{total}}} = \frac{V_{\text{total}}}{R_1 + R_2} \]

where \( V_{\text{total}} \) is the total potential difference supplied by the source.

The potential difference across each resistor can be calculated using:

\[ V_1 = I \cdot R_1, \quad V_2 = I \cdot R_2 \]

Mode 2: \( R_1 \) and \( R_3 \) in Parallel, \( R_2 \) in Series

In this mode, resistors \( R_1 \) and \( R_3 \) are in parallel, and \( R_2 \) is in series with the combination. First, calculate the equivalent resistance of the parallel combination:

\[ \frac{1}{R_{\text{parallel}}} = \frac{1}{R_1} + \frac{1}{R_3} \]

Thus, the total resistance is:

\[ R_{\text{total}} = R_{\text{parallel}} + R_2 \]

The current through the circuit is:

\[ I = \frac{V_{\text{total}}}{R_{\text{total}}} \]

The potential difference across \( R_2 \) is:

\[ V_2 = I \cdot R_2 \]

Since \( R_1 \) and \( R_3 \) are in parallel, they share the same potential difference:

\[ V_1 = V_3 = V_{\text{total}} – V_2 \]

The current through each parallel resistor can be found using Ohm’s Law:

\[ I_1 = \frac{V_1}{R_1}, \quad I_3 = \frac{V_3}{R_3} \]

Mode 3: \( R_1 \) and \( R_2 \) in Series, \( R_3 \) in Parallel

Here, resistors \( R_1 \) and \( R_2 \) are connected in series, and the combination is in parallel with \( R_3 \). First, calculate the resistance of the series combination:

\[ R_{\text{series}} = R_1 + R_2 \]

Then, find the total resistance of the parallel combination:

\[ \frac{1}{R_{\text{total}}} = \frac{1}{R_{\text{series}}} + \frac{1}{R_3} \]

The total current is:

\[ I = \frac{V_{\text{total}}}{R_{\text{total}}} \]

The voltage across the parallel combination is the same for both branches:

\[ V_1 + V_2 = V_3 = V_{\text{total}} \]

The current through \( R_3 \) is:

\[ I_3 = \frac{V_3}{R_3} \]

The current through \( R_1 \) and \( R_2 \), which are in series, is the same:

\[ I_{\text{series}} = \frac{V_{\text{total}}}{R_1 + R_2} \]

The voltage across each series resistor is:

\[ V_1 = I_{\text{series}} \cdot R_1, \quad V_2 = I_{\text{series}} \cdot R_2 \]

Representing a Longitudinal Wave Graphically

I modified an existing simulation to demonstrate how the displacement of particles along a longitudinal wave can be represented in graphical form.

Essentially, one would have to determine for each particle, its displacement from the equilibrium position and its corresponding position along the wave’s direction. On the graph, positive displacement indicates movement in one direction (e.g., to the right), while negative displacement indicates movement in the opposite direction (e.g., to the left).

For the full view, go to https://www.geogebra.org/m/kq3e2qjk

Lift on an Aerofoil: Coanda Effect, not Bernoulli

The commonly taught explanation (for people from my generation) for how airplanes generate lift often relies on the Bernoulli Principle, which states that faster airflow over the curved top of a wing reduces pressure, creating lift. However, this explanation oversimplifies the complex physics involved and is labelled an inaccurate theory by NASA. The true mechanism behind lift is better explained by the Coanda Effect, which describes how a fluid, like air, tends to follow a curved surface, such as an aerofoil.

In this video, John Collins (award winning paper airplane maker and author) explains how the Coanda Effect ensures that airflow stays attached to the wing’s surface, curving around it and being deflected downward. This downward deflection of air is critical because, according to Newton’s Third Law of Motion, the downward push of air results in an equal and opposite upward force—lift.

Understanding the Coanda Effect gives a more accurate picture of how lift is generated and explains why certain wing shapes and angles are more effective. Unlike the Bernoulli-based explanation, the Coanda Effect shows why airflow remains attached to the wing, ensuring the necessary conditions for lift.

Interactive Heating and Cooling Curves

Heating and cooling curves are graphical representations that show how the temperature of a substance changes as heat is added or removed over time. They illustrate the behavior of substances as they go through different states—solid, liquid, and gas.

Heating Curve: This curve shows how the temperature of a substance increases as it absorbs heat. The curve typically rises as the substance heats up, with plateaus indicating phase changes, where the substance absorbs energy but its temperature remains constant. Check out the heating curves for water and nitrogen using the drop-down menu.

Cooling Curve: This curve is the opposite of the heating curve. It shows how the temperature decreases as the substance loses heat. Like the heating curve, it also has plateaus where phase changes occur, but this time, the substance releases energy. In addition to water, you can also see the cooling curve for ethanol.

With these ChatGPT-generated interactive graphs, users can change the rate of heat input or released from the substance. They can also read the descriptions that explain the changes in the average PE and KE of the molecules during each process.