# Rotate corner of triangle around opposite edge

I have two triangles in $$R^3$$:

1. $$p_1$$, $$p_2$$, $$p_3$$
2. $$p_1$$, $$p_2$$, $$p_4$$

The triangles share points $$p_1$$ and $$p_2$$ and thus edge $$p_2 - p_1$$.

I would like to rotate $$p_4$$ such that it will be diametrically with respect to $$p_3$$, i.e. the angle between $$p_3$$ and $$p_4$$ should be $$180$$ degrees or $$\pi$$.

I can derive the current angle between $$p_3$$ and $$p_4$$:

$$d_1 = (p_3 - p_1) \times (p_2 - p_1)$$

$$d_2 = (p_4 - p_1) \times (p_2 - p_1)$$

$$rad = \arccos(d_1 / |d_1| \cdot d_2 / |d_2|)$$

The next step would be to rotate $$p_4$$ around edge ($$p_2 - p_1$$) by $$\pi - rad$$. However I do not know how to rotate a corner of a triangle around the opposite edge. Therefore I was wondering if anybody would know how to accomplish this.

You have the angle $$\phi$$ and the axis of rotation $$\hat{n} = \frac{p_2-p_1}{|p_2-p_1|}$$. You only need Rodrigues' rotation formula: $$p_{\text{rot}} = p_4 \cos\phi + (\hat{n}\times p_4) \sin\phi + \hat{n}(\hat{n}\cdot p_4)(1-\cos\theta).$$