3 ms·
>Funny thing is, also as a programmer, I find openSCAD annoying. I really want object-oriented objects Have you tried OpenJSCAD? It's OpenSCAD meets Javascript
by romwell 6y ago
>Funny thing is, also as a programmer, I find openSCAD annoying. I really want object-oriented objects
Have you tried OpenJSCAD? It's OpenSCAD meets Javascript.
Now, to address the things you mentioned:
>I want to be able to make a cylinder from point A to point B.
You can write a function that does it in OpenSCAD already
> I want to be able to declare a cube and then refer to its corners.
Referring to vertices of a solid in general seems to be incompatible with OpenSCAD's paradigm of modeling with boolean operations. You don't know where the vertices are until you render.
You can already write a helper function which returns you the vertices of a cube. More than that, you would need another tool. It's not about syntax, to my understanding.
[1]https://openjscad.org/ https://openjscad.org/
- ajb 6y agoHaven't tried OpenJSCAD - thanks for the reference. > Referring to vertices of a solid in general seems to be incompatible with OpenSCAD's paradigm of modeling with boolean operations. You don't know where the vertices are until you render. Is it? Well I suppose it is in the general case. It would be hard to refer to an edge that has been created as a result of some difference operation. But the corners of a cube are still valid reference points even if they've been chopped off, and aren't part of the final solid.
- romwell 6y agoI 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); }