Since the quadratic Bézier curve will have only one bend after drawing, it will render poorly when multiple nodes are connected. And at 45°, 135°, 225°, 315°, special treatment is needed, otherwise the curve obtained is too large in radian.
After deciding to use the cubic Bezier curve, we need to calculate the two control points C1,C2 when drawing the curve, and then draw it by CanvasRenderingContext2D.bezierCurveTo.
Since we need two control points, we will divide the line S-E between the starting point SP(start point) and the end point EP(end point) into 4 parts. The following points are obtained.
\[\begin{align*}Split_{m} = (\frac{(X_{SP}+X_{EP})}2,\frac{(Y_{SP}+Y_{EP})}2)\\\end{align*}\] The formula L(x) for S-E is obtained as \[L(x) = \frac{X_{Split_{m}}}{Y_{Slit_{m}}}x\] From L(x) we know that the slope of S-E satisfies \[\tan \theta = \frac{X_{Split_{m}}}{Y_{Slit_{m}}}\]
Then, using \[Split_{m}\] as the origin of the coordinate system and establishing the right angle coordinate system, we get