3 ms·
I guess so, but I find it a mild inconvenience personally. I'd struggle to come up with an example where it would be a deal-breaker. Could you write about how y
by romwell 6y ago
I guess so, but I find it a mild inconvenience personally. I'd struggle to come up with an example where it would be a deal-breaker. Could you write about how you'd use it?
Incidentally, I ended up needing a function that places a cylinder between two points in OpenSCAD yesterday.
Here is my implementation - might come in handy!
// Transpose of matrix A (swap rows and columns)
function transpose(A) = [for (j = [0:len(A[0])-1]) [for(i = [0:len(A)-1]) A[i][j]]];
// Cylinder of radius r from P to Q
module cyl_between(P, Q, r){
v = Q - P; // vector from P to Q
L = norm(v); // height of the cylnder = dist(P, Q)
c = v / L; // unit vector: direction from P to Q
is_c_vertical = ( 1 - abs(c * [0, 0, 1]) < 1e-6); //is c parallel to z axis?
u = is_c_vertical ? [1, 0, 0] : cross([0, 0, 1], c); // normal to c and Z axis
a = u / norm(u); // unit vector normal to c and the Z axis
b = cross(c, a); // unit vector normal to a and b
// [a, b, c] is an orthonormal basis, i.e. the rotation matrix; P is the translation
MT = [a, b, c, P]; // the transformation matrix
M = transpose(MT); // OpenSCAD wants vectors in columns, so we need to transpose
multmatrix(M)
cylinder(h=L, r=r, $fn=24);
}