but haven't thought about them since. I seem to recall they are a method
standard XYZ transformation matrices. Is there built in functionality for
Thanks for the code. I will keep this as a reference.
Post by berkenbYour problem appears to be solved, but for what it's worth, I wrote a 'loft'
function a while ago that sweeps the interpolation between two
two-dimensional profiles along a three-dimensional path. It is very similar
to the other 'sweep' libraries mentioned (except mine is poorly documented
and the code probably unreadable, sorry ;-)). The transformations along the
path are computed using quaternions and the usual restrictions apply
(profiles have to be singly-connected and have the same number of points in
them, no self-intersections).
Maybe it is useful to somebody...
Marko
function flatten(vec) = [for (v=vec) for(e=v) e];
function Q_im(q) = [q[1], q[2], q[3]];
function Q_conj(q) = [q[0], -q[1], -q[2], -q[3]];
function Q_mult(q,p) =
[(q[0]*p[0]-q[1]*p[1]-q[2]*p[2]-q[3]*p[3]),(q[1]*p[0]+q[0]*p[1]+q[2]*p[3]-q[3]*p[2]),(q[2]*p[0]+q[0]*p[2]-q[1]*p[3]+q[3]*p[1]),(q[3]*p[0]+q[0]*p[3]+q[1]*p[2]-q[2]*p[1])];
function rotQ(q, a, n) = Q_mult(flatten([cos(a/2),n*sin(a/2)]),q);
function poly_rotQ(list, q) = [for (v=list)
Q_im(Q_mult(q,Q_mult([0,v.x,v.y,v.z],Q_conj(q))))];
function poly_rot2d(list, a) = [for (x=list) [cos(a)*x[0]+sin(a)*x[1],
-sin(a)*x[0]+cos(a)*x[1]]];
function poly_translate(list, d) = [for (v=list) v+d];
function interp_lists(l1, w1, l2, w2) = [for (i=[0:len(l1)-1])
w1*l1[i]+w2*l2[i]];
function poly_loft_faces (N_z, N_x, closed=false) = flatten([
(closed ? ([for (i=[0:N_x-1]) [(N_z-1)*N_x+i, (N_z-1)*N_x+(i+1)%N_x,
i],
for (i=[0:N_x-1]) [(i+1)%N_x, i, (N_z-1)*N_x+(i+1)%N_x]])
: concat([[for (i=[0:N_x-1]) N_x-1-i]], [[for (i=[0:N_x-1])
(N_z-1)*N_x+i]])), // caps
for (i=[0:N_z-2],j=[0:N_x-1]) [[(i+1)*N_x+j, i*N_x+j,
i*N_x+((j+1)%N_x)],[i*N_x+((j+1)%N_x), (i+1)*N_x+((j+1)%N_x),
(i+1)*N_x+j]]]);
// extrude a cross section linearly interpolated between cross sections cr1
and cr2 along path 'path',
// with optional tangential twist linearly increasing along path
module loft (path, cr1, cr2, twist=0) {
p = flatten([path, [2*path[len(path)-1]-path[len(path)-2]]]);
pts = flatten([
for (i=1, d=p[1]-p[0], u=cross([0,0,1], d), un=norm(u), dn=norm(d),
a=asin(un/dn),
q=un>0?rotQ([1,0,0,0],a,u/un) : [1,0,0,0], n=d/dn, cr=cr1;
i<len(p);
d=p[i]-path[i-1], u=cross(n, d), un=norm(u), dn=norm(d),
a=asin(un/dn),
n=d/dn,q=un>0?rotQ(q,a,u/un):q,
cr=interp_lists(cr1,1-(i-1)/(len(p)-1),cr2,(i-1)/(len(p)-1)), i=i+1)
poly_translate(poly_rotQ(twist!=0?[for(v=poly_rot2d([for (v=cr)
[v.x,v.y,0]],i*twist/(len(p)-1))) [v.x,v.y,0]]:[for (v=cr) [v.x,v.y,0]], q),
p[i-1])
]);
fcs = poly_loft_faces(len(path), len(cr1));
polyhedron(pts, fcs, convexity=8);
}
pH = [[-1, 1], [-0.8,1], [-0.8, 0.1], [0.8, 0.1], [0.8, 1], [1, 1],
[1, -1], [0.8, -1], [0.8, -0.1], [-0.8, -0.1], [-0.8, -1], [-1, -1]];
pH2 = [for (v=pH) 2*v];
phelix = [for (i=[0:6:3*360]) 5*[cos(i), sin(i), i/360]];
loft(phelix, pH, pH2, -170);
--
Sent from: http://forum.openscad.org/
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org