Handling vectors for double-bond graphics I'm working on a small molecular graphics tool for visualising ball-and-stick style molecules. I'm having trouble handling the linear algebra to position the two bonds in the double bonds. My linear algebra is, unfortunately, very weak. I can follow notation but struggle with working my own way through logical algebra.

If I'm overcomplicating this significantly then I'd appreciate some guidance on how so. Here is my working so far:



I currently have the atomic coordinates of each atom. All of the above atoms are in a plane due to the $sp^2$ nature of atom $i$, though the orientation of the plane is arbitrary.

$\textbf i$, $\textbf j$ and $\textbf k$ are atomic coordinates and $\textbf a$ and $\textbf b$ are vectors between them.

The orientation of the double bond must mean that both of the lines in the double bond are positioned in the plane, and I have quantified the plane as:

$\textbf{a} \times \textbf{b} \cdot (\textbf{r} - \textbf{r}_0) = 0$

where $\textbf r$ is any vector in the plane, and $\textbf{r}_0$ is any other point in the plane.

I can also say that the points which I am looking for on each atom make vectors with the centre of respective atoms at $90 ^\text{o}$ to $\textbf b$, and that the radius at which these points are positioned is constrained to a constant value (and therefore so is the length of said vector). If we call this vector $\textbf l$ we therefore have:

$(\textbf{a} \times \textbf{b}) \cdot (\textbf{l} - \textbf{i}) = 0$

$| \textbf{l} | = \text{const}.$

$\textbf{l} \cdot \textbf{b} = 0$

where $\textbf{a}$, $\textbf{b}$ and $\text{i}$ are all things which are numerically available to me.

I feel as though, based upon geometrical constraints, these algebraic relationships are enough to find only the 4 points which I want. But my amateur self has no idea how to do that.
I'm not sure I exactly know what you want, but such code is implemented in Avogadro and in other places.

The first thing to realize is that the unmarked atom in your plane is also your friend. You can calculate the plane of best fit using all 4 atoms.

You're making your work too hard, though. If you had a single bond, you simply draw a line or cylinder between atom i and j.

So the question at hand is how to displace two cylinders slightly in the plane of the bond. There are a few ways to do this. (Avogadro computes the plane of best fit for the molecule. Some people project towards the plane of the screen.)

My recommendation is to realize that atom k in your diagram is in one direction, and the unmarked atom is in the other. Let's call that other atom l. You can compute the vector between them: k - l. In practice, atom i is midway along this vector. So you want to displace the b vector in your diagram by a small amount, say 0.1 in one direction along that k - l vector, and 0.1 in the opposite direction.