# Plotting SVM hyperplane margin

I'm trying to understand how to plot SVM hyperplane and its margins by this example: https://scikit-learn.org/stable/auto_examples/svm/plot_svm_margin.html

And I got stuck at the plotting the parallels part:

# plot the parallels to the separating hyperplane that pass through the
# support vectors (margin away from hyperplane in direction
# perpendicular to hyperplane). This is sqrt(1+a^2) away vertically in
# 2-d.
margin = 1 / np.sqrt(np.sum(clf.coef_ ** 2))
yy_down = yy - np.sqrt(1 + a ** 2) * margin
yy_up = yy + np.sqrt(1 + a ** 2) * margin


At the comment section we see:

This is sqrt(1+a^2) away vertically in 2-d.

So, my question is why np.sqrt(1 + a ** 2) * margin is the vertical distance from a hyperplane to its parallel line? How did we come up with it?

*Note: a here is just a slope of a hyperplane, and margin is a magnitude of the distance between the hyperplane and the parallel dashed line.

I also drew a picture as I can see the problem:

This boils down to trigonometry. The distance between the points in the y axis that you represent here by a red line is calculated by multiplying the distance between the two parallel lines (here represented by the margin) and the sqrt(1 + a ** 2).
1. this equation, often used to represent a line: y = mx + c.