# Non-Linear Transformations

75 messages
1234
Open this post in threaded view
|

## Non-Linear Transformations

 OpenSCAD currently supports a whole range of specific linear transformations such as translate(), rotate() and scale(), in addition to the generic linear transformation multmatrix(). OpenSCAD does not provide support for non-linear transformations.  I think support for non-linear transformations would be very useful and this could be accomplished with a new transformation command: transform(x_expression, y_expression, z_expression) reserved names within transform() expressions: x, y & z, these represent the vertex being processed The examples below use this syntax. Equivalent Linear Transformations: 1) pass data through, no change to vertices transform(x, y, z) { ... } 2) scale([xf,yf,zf]) { ... }   <->   transform(xf*x, yf*y, zf*z) { ... } 3) translate([x1,y1,z1]) { ... }   <->   transform(x+x1, y+y1, z+z1) { ... } 4) multmatrix([[xx, xy, xz, xc], [yx, yy, yz, yc], [zx, zy, zz, zc], [0, 0, 0, 1]) { ... }   <->     transform(xx*x+xy*y+xz*z+xc, yx*x+yy*y+yz*z+yc, zx*x+zy*y+zz*z+zc) { ... } Non-Linear Transformations: 1) exponential x scaling transform(x*x, y, z) { ... } 2) "conic" expansion in x-y plane, scale factor=1 for z=20 transform(x*z/20 ,y*z/20 ,z) cylinder(h=40, r=10); 3) scale specific co-ordinate ranges transform(x>0?2*x:x, abs(y)>50?3*y:y, z) { ... } 4) insert "gap" of 40mm centred on y=0 transform(x ,y>0?y+20:y-20, z) cylinder(h=20, r=10); Comments please! Cheers, Trygon
Open this post in threaded view
|

## Re: Non-Linear Transformations

 Administrator > On Nov 16, 2015, at 10:11 AM, Trygon <[hidden email]> wrote: > > OpenSCAD does not provide support for non-linear transformations.  I think > support for non-linear transformations would be very useful and this could > be accomplished with a new transformation command: > Would this be conceptually similar to the proposed bend modifier? https://github.com/openscad/openscad/issues/815 -Marius _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: Non-Linear Transformations

Open this post in threaded view
|

## Re: Non-Linear Transformations

 In reply to this post by Trygon I like the idea of providing non-linear transformations. However, the suggested approach seems to break the current treatment of parameters. The suggested syntax looks as if conventional parameters were passed, but actually the arguments need to be treated in a very different way, that is as functions. Others will know better if that syntax fits into the language. But I am afraid that it does not. What about enhancing the language by functions as arguments to provide the suggested functionality? Am 16.11.2015 um 16:11 schrieb Trygon: ```OpenSCAD currently supports a whole range of specific linear transformations such as translate(), rotate() and scale(), in addition to the generic linear transformation multmatrix(). OpenSCAD does not provide support for non-linear transformations. I think support for non-linear transformations would be very useful and this could be accomplished with a new transformation command: transform(x_expression, y_expression, z_expression) reserved names within transform() expressions: x, y & z, these represent the vertex being processed The examples below use this syntax. Equivalent Linear Transformations: 1) pass data through, no change to vertices transform(x, y, z) { ... } 2) scale([xf,yf,zf]) { ... } <-> transform(xf*x, yf*y, zf*z) { ... } 3) translate([x1,y1,z1]) { ... } <-> transform(x+x1, y+y1, z+z1) { ... } 4) multmatrix([[xx, xy, xz, xc], [yx, yy, yz, yc], [zx, zy, zz, zc], [0, 0, 0, 1]) { ... } <-> transform(xx*x+xy*y+xz*z+xc, yx*x+yy*y+yz*z+yc, zx*x+zy*y+zz*z+zc) { ... } Non-Linear Transformations: 1) exponential x scaling transform(x*x, y, z) { ... } 2) "conic" expansion in x-y plane, scale factor=1 for z=20 transform(x*z/20 ,y*z/20 ,z) cylinder(h=40, r=10); 3) scale specific co-ordinate ranges transform(x>0?2*x:x, abs(y)>50?3*y:y, z) { ... } 4) insert "gap" of 40mm centred on y=0 transform(x ,y>0?y+20:y-20, z) cylinder(h=20, r=10); Comments please! Cheers, Trygon -- View this message in context: http://forum.openscad.org/Non-Linear-Transformations-tp14539.html Sent from the OpenSCAD mailing list archive at Nabble.com. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org ``` _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: Non-Linear Transformations

 In reply to this post by Trygon Trygon wrote 1) exponential x scaling transform(x*x, y, z) { ... } 2) "conic" expansion in x-y plane, scale factor=1 for z=20 transform(x*z/20 ,y*z/20 ,z) cylinder(h=40, r=10); 3) scale specific co-ordinate ranges transform(x>0?2*x:x, abs(y)>50?3*y:y, z) { ... } 4) insert "gap" of 40mm centred on y=0 transform(x ,y>0?y+20:y-20, z) cylinder(h=20, r=10); 1) exponential: it should better be called power law or polynomial.   It's a relatively unique requirement... 2) conic: I believe it's actually linear and doable with a simple multmatrix() 3) scale specific co-ordinate ranges and 4） insert gap both are easily doable with a smartly written module using difference() and/or projection() So only the x = x*x exponential (sic) is new, I'm not very convinced it justifies inventing a whole new syntax for it.
Open this post in threaded view
|

## Re: Non-Linear Transformations

 Another way to represent the transformation is as a single function that maps a point [x,y,z] to another point.If you think of this function as mapping every point in a 3D shape, then this is extremely powerful, as you can model any conceivable spatial transformation: twisting, bending, etc.In practice, there are difficulties, as pointed out byhttps://github.com/openscad/openscad/issues/815The problem is that, with many of the more interesting transformations, it's not enough to simply transform each vertex. You may need to subdivide the mesh to create smaller faces, and then transform each vertex in the subdivided mesh. An example would be applying a twist or bend transformation to a cube, with just the 8 vertices.On 16 November 2015 at 12:35, ctchin wrote:Trygon wrote > 1) exponential x scaling > transform(x*x, y, z) { ... } > > 2) "conic" expansion in x-y plane, scale factor=1 for z=20 > transform(x*z/20 ,y*z/20 ,z) cylinder(h=40, r=10); > > 3) scale specific co-ordinate ranges > transform(x>0?2*x:x, abs(y)>50?3*y:y, z) { ... } > > 4) insert "gap" of 40mm centred on y=0 > transform(x ,y>0?y+20:y-20, z) cylinder(h=20, r=10); 1) exponential: it should better be called power law or polynomial. It's a relatively unique requirement... 2) conic: I believe it's actually linear and doable with a simple multmatrix() 3) scale specific co-ordinate ranges and 4） insert gap both are easily doable with a smartly written module using difference() and/or projection() So only the x = x*x exponential (sic) is new, I'm not very convinced it justifies inventing a whole new syntax for it. -- View this message in context: http://forum.openscad.org/Non-Linear-Transformations-tp14539p14548.html Sent from the OpenSCAD mailing list archive at Nabble.com. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: Non-Linear Transformations

 In reply to this post by kintel Yes this could be used to bend objects, I think this would work: transform(y*sin(x), y*cos(x), z) As noted in the proposed bend modifier discussion, unless the object has sufficient vertices it will just deform (unpleasantly), e.g. a simple cube with 8 vertices would not work well. However this is a different issue. If the use of x, y & z as reserved names makes the "syntax looks as if conventional parameters were passed", perhaps x(), y() & z() could be used instead as reserved functions, such that "the arguments need to be...functions"? The above example would become: transform( y()*sin(x()), y()*cos(x()), z() ) -Trygon
Open this post in threaded view
|

## Re: Non-Linear Transformations

Open this post in threaded view
|

## Re: Non-Linear Transformations

 The more I read the more I understand the request, the more I'm convinced there's a lot loony ideas being thrown around.   The syntax x(), whether it's built-in or not, is a function call with no input parameters (adopting the default values if possible).   For non-linear or more precisely non-affine transformation to work the way you imagine it, will require re-meshing the children with some level of smartly selected resolution.  Which spells... no universally acceptable algorithm exists.   If it doesn't work sensibly on a cube() primitive, it's highly questionable it ought to be added to OpenSCAD.
Open this post in threaded view
|

## Re: Non-Linear Transformations

 In reply to this post by Trygon // non-linear transformation: 2D bend demo x1=-40; x2=40; y1=30; y2=40; step=10; p1=concat([for(i=[x1:step:x2]) [i,y1]],[for(i=[x2:-step:x1]) [i,y2]]); polygon(p1); // translate([0,-20,0]) transform(y*sin(x),y*cos(x)) polygon(p1); p2=[for(i=p1) [i[1]*sin(i[0]),i[1]*cos(i[0])]]; translate ([0,-20,0]) polygon(p2);
Open this post in threaded view
|

## Re: Non-Linear Transformations

Open this post in threaded view
|

## Re: Non-Linear Transformations

 In reply to this post by ctchin You are perfectly right! Anyway only ismorphic nonlinear transformations would make sense. Most of them are not isomorphic in a general sense - but might be in a subset, as the given examples. A more general approach for this feature would be to get hands on the mesh points, as requested in my topic "feature request: obj2vec(); bug report: freeze on standby recovery (Windows)". Then, everyone is free to use his own mappings even non-isomorphic ones and also responsible if the resulting polyhedron will be malformed. > If it doesn't work sensibly on a cube() primitive, it's highly > questionable it ought to be added to OpenSCAD.
Open this post in threaded view
|

## Re: Non-Linear Transformations

Open this post in threaded view
|

## Re: Non-Linear Transformations

 Well, a non-isomorphic map in R³->R³ will have singularities (points, lines or planes) in the sense that more than one points will be mapped to the same point - so no inverse map can be found. As bijectivity is lost, vertices and triangles simply might get lost. Restricting a non-isomorphic map to a region (partial isomorphism), say to the unit cube, it might be locally isomorphic as long as the region does not contain any fix points. So if we have a (partial) isomorphism all points (of a region) will be mapped to separate image points and no merging can occur (numerically yes, which is still another severe problem). Also triangle orientation will be mapped in the same sense, as a partial flip of orientation of a triangle would need a singularity for separation. But you are right. Proving that a map is a (partial) isomorphism will only be a first step. Even then, non-intersecting triangles might intersect after being mapped (think of simply mapping one axis to a vortex like the Archimedian spiral), and demand some careful post processing.   To sum it up: Non-linear operations have many pitfalls. I guess one could allow for some of them in very specific contexts, like with extrusion operations. For linear_extrusion() instead of linear scaling and twisting one could think of nonlinear stepping or allow for a vector expressing an ordered list of values, which will be used as z-heights, while scaling and twisting will be done in a linear fashion with equidistant stepping as it is done now.
Open this post in threaded view
|

## Re: Non-Linear Transformations

 This post was updated on . In reply to this post by ctchin @ctchin you said, "conic: I believe it's actually linear and doable with a simple multmatrix()", with regard to: transform(x*z/20 ,y*z/20 ,z) This transformation would be really useful for a model that I am scripting at present, I couldn't work out how to do it with multmatrix(), please could you provide the affine transformation matrix to use. Thanks, Trygon
Open this post in threaded view
|

## Re: Non-Linear Transformations

 @Doug - This remeshing algorithm was designed specifically for this exact purpose and worked very well at the time. (1992). May be worth a read:  - http://www.red3d.com/cwr/papers/1992/df.html
Open this post in threaded view
|

## Re: Non-Linear Transformations

Open this post in threaded view
|

## Re: Non-Linear Transformations

 In reply to this post by Neon22 Oh, nice. This algorithm "removes excess detail in crowded regions where the surface is contracting", which is more sophisticated than what I specified.On 16 November 2015 at 16:45, Neon22 wrote:@Doug - This remeshing algorithm was designed specifically for this exact purpose and worked very well at the time. (1992). May be worth a read:  - http://www.red3d.com/cwr/papers/1992/df.html -- View this message in context: http://forum.openscad.org/Non-Linear-Transformations-tp14539p14581.html Sent from the OpenSCAD mailing list archive at Nabble.com. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: Non-Linear Transformations

 Administrator In reply to this post by doug.moen > On Nov 16, 2015, at 16:52 PM, doug moen <[hidden email]> wrote: > > I tried using the perspective transformation matrix from wikipedia in OpenSCAD and it didn't work, I got a run-time error. Don't remember the details, it was a while ago. At the time, I concluded that we don't support arbitrary affine transformations. > The perspective transformation is not affine. We currently don’t support non-affine transformations because CGAL doesn’t.  -Marius _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org