Skip to content

Instantly share code, notes, and snippets.

@pavly-gerges
Last active February 5, 2026 08:59
Show Gist options
  • Select an option

  • Save pavly-gerges/6b4c7f3d1940044625b1ac32714a77f6 to your computer and use it in GitHub Desktop.

Select an option

Save pavly-gerges/6b4c7f3d1940044625b1ac32714a77f6 to your computer and use it in GitHub Desktop.
Designing and implementing game programming software based on simple models derived from questions in algebra and trigonometry.

Linking between Algebra and Game programming patterns

Preface:

This is a demonstration for designing and implementing game programming software based on simple models derived from questions in algebra and trigonometry.

Table of contents:

  • Section 1.1: Problem
  • Section 1.2: Understanding the problem using algebra and logic
  • Section 2.1: Establishing a relation model.
  • Section 2.2: Solving the problem using the model.
  • Section 3.1: Designing software programming pattern.
  • Section 3.2: Writing the full pattern using the Automata Theory notations.

Section 1.1: The problem

The following problem asks to a generalization of finding at which time does two or more vehicles moving with different speeds will meet each other.

image

Section 1.2: Understanding the problem using algebra and logic

$\text{To solve this problem, it's essential to setup the environment and principles in which we could work our equations.} $

$$\text{Since both, Bill and Mary, will meet at a specific distance from Bill's House, it follows that the following is true; as the distance is calculated from Bill's House:}$$ $$(\text{Two Vehicles approaching one another, starting from } \rho) \land (d_{v} = d_t - \rho) \implies (d_{v1} - d_{v0}) \to Zero$$ $$\therefore\ Let,\ d_{Mary} - d_{Bill} = Zero$$ $$\text{By substituting in the distance formula: } d = \int_{House}^{d}{v.dt}$$ $$\int_{House}^{d}{v_{Mary}.dt_{Mary}} - \int_{House}^{d}{v_{Bill}.dt_{Bill}} = Zero$$ $$\text{Evaluating the integral using Limits of Riemann's Sum as partitions approach zero,}$$ $$\text{and when both Mary and Bill are moving at constant velocities:} \lim_{|P| \to 0} \sum_{d = House}^{D} v.dt$$ $$\therefore, \begin{equation*} \ v_{Mary}.\lim_{|P| \to 0} \sum_{d = House}^{D} dt_{Mary} - v_{Bill}.\lim_{|P| \to 0} \sum_{d = House}^{D} dt_{Bill} = 0 \end{equation*} $$

Section 2.1: Establishing a relation model

  • Since, Bill starts cycling at 2:00PM from his house, while Mary starts cycling at 2:10PM from Bill's house; it follows that, if we let the starting timestamp is $t_0 = 2:00PM$, consequently, Bill's time to cover distance $d$ would be $\delta (t_{B}) = t_{d} - t_0$, while Mary's time to cover the same distance $d$ would be $$\delta(t_{M}) = t_{d} - (t_{0} + 00:10) = (t_{d} - t_{0}) - 00:10 = \delta(t_{B}) - 00:10$$.

  • Converting the $00:10$ minutes to hours to match the timestamps, one could deduce the relation among both timestamps:

$$\delta(t_M) = \delta(t_{B}) - 10/60$$ $$\therefore,\ \delta(t_M) = \delta(t_{B}) - \frac{1}{6}$$

  • By back substitution into the equation from Section 1.2, as this limit could be evaluated as:

$$\lim_{D \to \infty} \sum_{d = House}^{D} \delta(t_{d}) = \frac{t_{d-1}-t_{d}}{D} \times D = (t_{d-1}-t_{d})$$ $$\text{ in the dth subintervals of } [t_{d-1}, t_{d}]$$

  • The final model shall become:

$$\therefore, \ v_{Mary}.\lim_{|P| \to 0} \sum_{d = House}^{D} dt_{Mary} - v_{Bill}.\lim_{|P| \to 0} \sum_{d = House}^{D} dt_{Bill} = 0 $$ $$ v_{Mary}.(\delta(t_{B}) - \frac{1}{6}) - (v_{Bill}.\delta(t_{B})) = 0 $$ $$ \therefore,\ v_{Mary}.\delta(t_{B}) - \frac{1}{6}.v_{Mary} - v_{Bill}.\delta(t_{B}) = 0 $$

Section 2.2: Solving the problem using the model

  • To solve the problem and find the timestamp in which both Mary and Bill shall caught one another using the problem demonstrated in the problem statement, one shall substitute Mary's and Bill's constant velocities into the equation, and find the $\delta(t_B)$ first.
  • Problem Complication: However, if Mary and Bill are accelerating, one should even find the integral of their acceleration in a specific timestamp to calculate their instantenous speed in the model.
  • The final timestamp difference could be calculated as follows from the initial timestamp $t_0$:

$$ 16.\delta(t_{B}) - \frac{16}{6} - 12.\delta(t_{B}) = 0 $$ $$ 4.\delta(t_B) = \frac{16}{6} = \frac{4 * 4}{6} = \frac{2}{3} $$ $$\therefore,\ \delta(t_B) = \frac{2}{3},\ \delta(t_M) = \frac{1}{2}$$

  • This means that Mary will require $\frac{1}{2}$ an hour starting from her timestamp (i.e., 02:10PM) to caught-up with Bill, who reaches the same assembly point after a $\frac{2}{3}$ of an hour starting from his timestamp.

  • Therefore, the timestamp in which they will meet could be calculated either by considering Bill's timestamp as the initial timestamp, and therefore will add $\frac{2}{3}$ of an hour to it or by considering Mary's timestamp as the initial timestamp, and therefore will add $\frac{1}{2}$ an hour to it.

$$\text{Timestamp in which Mary will catch up with Bill, considering 02:00PM as the initial timestamp:}$$ $$02:00PM + 00:\frac{2}{3}*60 = 02:40PM$$

Section 3.1: Designing software programming pattern

  • Designing a software that manipulates this mathematical model of this relationship is a daunting task to undergo, and requires problem generalization and abstraction using Particle Models or using Particle theory.
  • Consider, Jack, a friend of both Mary and Bill, who arrived at 2:12PM at Bill's House, and he requires to move with a specific speed to catch Bill and Mary at 2:40PM.
  • See, the problem is complicated. Thus, we need to derive a generalized formula to handle these issues.
  • To simplify the statement, the following is true:

$$d_{B} = d_{M} = d_{J}$$

  • As the distance is calculated from Bill's house.
  • The difference in timestamps are calculated as follows, in which $t_d$ is the timestamp at the location they will meet, and $t_0$ is the timestamp at which Bill has started cycling from his house $d_0$:

$$\therefore,\ \delta{t_B} = t_d - t_0$$ $$\delta{t_M} = t_d - (t_0 + \frac{10}{60}) = \delta{t_B} - \frac{1}{6}$$ $$\delta{t_J} = t_d - (t_0 + \frac{12}{60}) = \delta{t_B} - \frac{1}{5}$$

$$\therefore,\ v_{Mary}.(\delta{t_B} - \frac{1}{6}) = v_{Bill}.\delta(t_{B}) = v_{Jack}.(\delta{t_B} - \frac{1}{5})$$

  • Based on these facts, we could design a state-machine phase that would execute if one or more accelerating particles are at equal distance from the same starting point (Delta(d)-Zero pattern).

  • Furthermore, we could provide the pattern with some useful parameters out of the composition of the Velocity (i.e., the distance, and the calculated timestamp difference from an initial timestamp, and the new timestamp representing the clock).

Section 3.2: Writing the full pattern using the Automata Theory notations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment