Aligning Bézier curve I'm trying to calculate the tight bounding box of a Bézier curve. The curve is in 3D space and can have any amount of points.
These articles are pretty much the only resources on the internet:
https://pomax.github.io/bezierinfo/#aligning
https://snoozetime.github.io/2018/05/22/bezier-curve-bounding-box.html
However they all use curves in 2D space.
Both of them firstly align the curve so that it starts at (0,0) and so that the last point lies on the x-axis.
This is the code used:
https://pomax.github.io/bezierinfo/chapters/tightbounds/tightbounds.js
translatePoints(points) {
    // translate to (0,0)
    let m = points[0];
    return points.map(v => {
        return {
            x: v.x - m.x,
            y: v.y - m.y
        }
    });
}

rotatePoints(points) {
    // rotate so that last point is (...,0)
    let last = points.length - 1;
    let dx = points[last].x;
    let dy = points[last].y;
    let a = atan2(dy, dx);
    return points.map(v => {
        return {
            a: a,
            x: v.x * cos(-a) - v.y * sin(-a),
            y: v.x * sin(-a) + v.y * cos(-a)
        };
    });
}

I am having trouble converting the rotation function from 2D to 3D.
Could anyone help me?
 A: Are you sure you want to do this? Getting a BB that’s axis-aligned and not very tight is easy — just box the control points. If you want the box to be tighter, divide the curve into a number of smaller subsegments, and box those subsegments, but this is usually not worth the effort. If you really want the minimal axis-aligned BB, you have to find the places where the curve tangent is parallel to the axis system’s principal planes. This is fairly easy for a cubic curve, but you said your curves have arbitrary degree, so you’ll need numerical root-finding. In my experience, trying to find the minimal BB is never worth the effort it takes.
If you want to allow the orientation of your boxes to vary, then the problem gets much harder. You can parameterized the box orientation either by using Euler angles or quaternions, and then use optimization code to minimize. This is easy to say, but hard to do.
Bounding boxes are typically used to make a quick exit from some algorithm, to avoid doing more detailed computations. For this, they don’t need to be super-tight. Making the boxes minimal is a lot of work, and typically is not worth the effort.
