@VectorStyler: At this point, you must think I am spamming this thread, but I promise this adds a great deal of value to what you're doing. My colleague who helped with the writing reverse engineered the number, 0.39 from pure screenshots. He did use AI, but even then - it is quite brilliant that he did it. Albeit he did not have to. Blender had worked it all out!
Found this brilliant piece of code from a Blender thread, which of course, is Open Source:
We use: 0.39 × own segment. Their comment explains why: a Bézier curve best approximates a quarter circle when the handle is 0.5519 of the radius, and dividing that by the chord, √2, gives 0.39.
This is it.
if (ELEM(BEZIER_HANDLE_AUTO, type_left, type_right)) {
const float3 prev_diff = position - prev_position;
const float3 next_diff = next_position - position;
float prev_len = math::length(prev_diff);
float next_len = math::length(next_diff);
if (prev_len == 0.0f) {
prev_len = 1.0f;
}
if (next_len == 0.0f) {
next_len = 1.0f;
}
const float3 dir = next_diff / next_len + prev_diff / prev_len;
/* The magic number 2.5614 is derived from approximating a circular arc at the control point.
* Given the constraints:
*
* - `P0=(0,1),P1=(c,1),P2=(1,c),P3=(1,0)`.
* - The first derivative of the curve must agree with the circular arc derivative at the
* endpoints.
* - Minimize the maximum radial drift.
* one can compute `c ≈ 0.5519150244935105707435627`.
* The distance from P0 to P3 is `sqrt(2)`.
*
* The magic factor for `len` is `(sqrt(2) / 0.5519150244935105707435627) ≈ 2.562375546255352`.
* In older code of blender a slightly worse approximation of 2.5614 is used. It's kept
* for compatibility.
*
* See https://spencermortensen.com/articles/bezier-circle/. */
const float len = math::length(dir) * 2.5614f;
if (len != 0.0f) {
if (type_left == BEZIER_HANDLE_AUTO) {
const float prev_len_clamped = std::min(prev_len, next_len * 5.0f);
left = position + dir * -(prev_len_clamped / len);
}
if (type_right == BEZIER_HANDLE_AUTO) {
const float next_len_clamped = std::min(next_len, prev_len * 5.0f);
right = position + dir * (next_len_clamped / len);
}
}
}
https://tikz.dev/library-edges - And then, there is also this library, which again uses the same value, rounded up 0.3915... So we hit the jackpot.
From these, we have two more suggestions. The ability to clamp handles and to approximate true circles. I'll explain more later.