OpenSCAD:如何从矢量到矢量绘制圆柱体?

wiz*_*lus 5 math 3d openscad

我在任意位置有两个对象,我想在一个对象和另一个对象之间绘制一个圆柱体。搜索数学解决方案告诉我,我需要点积和叉积分别作为角度和轴,但我在生成四元数或将结果转换为 的参数时迷失了方向rotate

这是我到目前为止所拥有的:

function dot (v1, v2) = [v1[0] * v2[0], v1[1] * v2[1], v1[2] * v2[2]];
function normalize (v) = v / norm(v);
function distance (v1, v2) = sqrt(
    pow(v2[0] - v1[0], 2) +
    pow(v2[1] - v1[1], 2) +
    pow(v2[2] - v1[2], 2)
);
function lookAt(v1, v2) =
    let(n1 = normalize(v1))
    let(n2 = normalize(v2))
    let(v = dot(n1, n2))
    let(angle = [acos(v[0]), acos(v[1]), acos(v[2])])
    let(axis = normalize(cross(n1, n2)))
    [0, 0, 0]; // I don't know what to return here


module cylTo(v1, v2) {
    translate(v1)
    rotate(lookAt(v1, v2))
    cylinder(distance(v1, v2), 2);
}

v1 = [-33, -20, 22];
v2 = [20, 20, -20];

// Draw sphere 1
translate(v1)
sphere(10);

// Draw sphere 2
translate(v2)
sphere(10);

// Draw cylinder between the two
cylTo(v1, v2);
Run Code Online (Sandbox Code Playgroud)

需要什么才能使rotate()acylinder()指向另一个对象?

wiz*_*lus 3

我找到了一个简单的解决方案,可以在两点之间近似形成一个圆柱体,但它并不精确,因为它产生的是一个药丸(具有圆形末端),而不是一个具有平端的圆柱体。

// Draw cylinder between the two
hull() {
    translate(v1)
    sphere(2);

    translate(v2)
    sphere(2);
}
Run Code Online (Sandbox Code Playgroud)