Generalized formula for third point to form an equilateral triangle

complex numberscomplex-geometryvectors

We know two complex numbers $z_A,z_B$ corresponding to points $A$ and $B$ in the complex plane. We need to generally find $z_C$ corresponding to point $C$ such that $\triangle ABC$ is equilateral.

Note: $\exists~2$ points $C_1$ and $C_2$ that satisfy the condition.

I drew this picture

We know that in an equilateral triangle $h=\frac{\sqrt{3}}{2}l$. We have to go from the middle point $M~~\frac{\sqrt{3}}{2}|\vec{AB}|$ either up or down.

Let $O\in\mathcal{P}$.

$\vec{OC}=\vec{OM}+\vec{MC}$

$\vec{OM}=\frac{1}{2}(\vec{OA}+\vec{OB})$

We are left to find $\vec{MC}$.

$\vec{i}$ and $\vec{j}$ are the unit vectors of $O_x$ and $O_y$ respectively

$\vec{BA}\cdot\vec{i}=|\vec{AB}|\cdot|\vec{i}|\cdot cos\alpha$

$((x_A-x_B)\vec{i}+(y_A-y_B)\vec{j})\cdot\vec{i}=|\vec{AB}|\cdot cos\alpha$

$x_A-x_B=|\vec{AB}|\cdot cos\alpha\Rightarrow cos\alpha=\frac{x_A-x_B}{|\vec{AB}|}$

$|\vec{BA}\times\vec{i}|=|\vec{AB}|\cdot|\vec{i}|\cdot sin\alpha$

$|((x_A-x_B)\vec{i}+(y_A-y_B)\vec{j})\times\vec{i}|=|\vec{AB}|\cdot sin\alpha$

$|y_A-y_B|=|\vec{AB}|\cdot sin\alpha\Rightarrow sin\alpha=\frac{|y_A-y_B|}{|\vec{AB}|}$

$sin(\frac{\pi}{2}-\alpha)=cos\alpha\Rightarrow sin\theta=cos\alpha$

$cos(\frac{\pi}{2}-\alpha)=sin\alpha\Rightarrow cos\theta=sin\alpha$

$\vec{MC}=\pm|\vec{MC}|(cos\theta\cdot\vec{i}+sin\theta\cdot\vec{j})$ (we have $\pm$ because we can go either up or down)

$|\vec{MC}|=\frac{\sqrt{3}}{2}|\vec{AB}|$

$\vec{MC}=\pm\frac{\sqrt{3}}{2}|\vec{AB}|(\frac{|y_A-y_B|}{|\vec{AB}|}\vec{i}+\frac{x_A-x_B}{|\vec{AB}|}\vec{j})$

$\vec{MC}=\pm\frac{\sqrt{3}}{2}(|y_A-y_B|\vec{i}+(x_A-x_B)\vec{j})$

$\vec{OC}=\frac{1}{2}(\vec{OA}+\vec{OB})\pm\frac{\sqrt{3}}{2}(|y_A-y_B|\vec{i}+(x_A-x_B)\vec{j})$

Transforming into a complex equation we get:

$z_C=\frac{1}{2}(z_A+z_B)\pm\frac{\sqrt{3}}{2}(|Im(z_A)-Im(z_B)|+(Re(z_A)-Re(z_B))i)$

However, this does not seem to work when I graphically represent the points (I use Desmos). What do I do wrong?

I need this to simulate the Koch snowflake fractal. See https://www.youtube.com/watch?v=azBNsPa1WC4&ab_channel=KhanAcademy.

EDIT:

I've figured out what I did wrong. I did not consider $\alpha$ in the trigonometrical sense. The marked answer inspired me to solve the problem using the Euler formula.

To find $\alpha$ we have to imagine a translation such that $A$ is in the center of the orthogonal axis. We will consider $\alpha=\angle(\vec{AB};\vec{i})$ in the trigonometrical sense with $\alpha\in[-\pi;\pi]$. Hence,

$cos\alpha=\frac{Re(z_2)-Re(z_1)}{|z_2-z_1|}$

$sin\alpha=\frac{Im(z_2)-Im(z_1)}{|z_2-z_1|}$

We need to rotate $B$ from $\vec{AB}$ to the left (counter-clockwise) or to the right (clockwise) $\pm\frac{\pi}{3}$. Let's first consider the $+$ case.

$\delta=\alpha+\frac{\pi}{3}$

$cos\delta=cos(\alpha+\frac{\pi}{3})=\frac{1}{2}\cdot\frac{Re(z_2)-Re(z_1)}{|z_2-z_1|}-\frac{\sqrt{3}}{2}\cdot\frac{Im(z_2)-Im(z_1)}{|z_2-z_1|}$

$sin\delta=sin(\alpha+\frac{\pi}{3})=\frac{1}{2}\cdot\frac{Im(z_2)-Im(z_1)}{|z_2-z_1|}+\frac{\sqrt{3}}{2}\cdot\frac{Re(z_2)-Re(z_1)}{|z_2-z_1|}$

Let $\vec{r}$ be the unit vector oriented to the angle after the rotation.

$r=e^{i\delta}=cos\delta+i\cdot sin\delta=\frac{1}{2|z_2-z_1|}\Big(\big(\underbrace{Re(z_2)+i\cdot Im(z_2)}_{z_2}\big)-\big(\underbrace{Re(z_1)+i\cdot Im(z_1)}_{z_1}\big)+\sqrt{3}\big(\underbrace{i\cdot Re(z_2)-Im(z_2)}_{iz_2}\big)-\sqrt{3}\big(\underbrace{i\cdot Re(z_1)-Im(z_1)}_{iz_1}\big)\Big)$

$r=\frac{1}{2}\cdot\frac{z_2-z_1}{|z_2-z_1|}\cdot(1+i\sqrt{3})$

$z_3=z_1+|z_2-z_1|r$

$z_3=z_1+\frac{1}{2}(z_2-z_1)(1+i\sqrt{3})$

As for the $-$ case we are similarly going to get

$z_3=z_1+\frac{1}{2}(z_2-z_1)(1-i\sqrt{3})$

FINAL ANSWER

$\mathbf{z_3=z_1+(\frac{1}{2}\pm\frac{\sqrt{3}}{2}i)(z_2-z_1)}$

And what's most interesting to it is that $\frac{1}{2}\pm\frac{\sqrt{3}}{2}i$ turns out to be $-\omega$, where $\omega=\sqrt[3]{1}~$, the primitive cube root of unity.

So we can clearly say that

$\mathbf{z_3=z_1+\omega(z_1-z_2),~\omega\in\mathbb{C}-\mathbb{R}}$

EDIT2: I've just finished the project.

Here is the source code:

https://github.com/s1mplex-Neox/Koch/blob/main/koch.cpp

Here is the video:

https://youtu.be/cyuEGvcgLY8

Best Answer

I think you are overthinking this problem. Try this approach: let $\alpha=\angle(z2-z1)$. The the third point to create an equilateral triangle is given by

$$z_3=z_2+|z_2-z_1|e^{i(\pi+\alpha-\pi/3)}$$

Related Question