Problem with difference() method

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem with difference() method

arecibokck
Hello, I am new to this forum/mailing list just as much as I am new to OpenSCAD. I have been trying to make a 3D model with the following code -

$fn = 200;

module polygons()
{
        for (i=[57:1:41]){
                translate([0,-i,9]){
                        rotate([90,10,0]){
                                circle(10,$fn=9);
                        }
                }
        }
}

difference(){
       
        rotate([90,0,0]){

                cylinder(r=4,h=58);
        }
        polygons();
}

The problem I am facing is that even though it shows the model exactly as I want it upon compiling the code(F5), the render process (F6) gives me just a cylinder, almost like it completely ignores the diff with my polygons() module. The console shows the following output as it renders the model -

Module cache size: 0 modules
Compiling design (CSG Tree generation)...
Rendering Polygon Mesh using CGAL...
PolySetCache hit: cylinder($fn=200,$fa=12,$fs=2,h=58,r1=4,
CGAL Cache insert: cylinder($fn=200,$fa=12,$fs=2,h=58,r1=4, (518904 bytes)
PolySetCache hit: circle($fn=9,$fa=12,$fs=2,r=10);
CGAL Cache insert: circle($fn=9,$fa=12,$fs=2,r=10); (4312 bytes)
CGAL Cache insert: multmatrix([[0.984808,0.173648,2.77556e- (0 bytes)
CGAL Cache hit: multmatrix([[0.984808,0.173648,2.77556e- (0 bytes)
CGAL Cache hit: multmatrix([[0.984808,0.173648,2.77556e- (0 bytes)
CGAL Cache hit: multmatrix([[0.984808,0.173648,2.77556e- (0 bytes)
CGAL Cache hit: multmatrix([[0.984808,0.173648,2.77556e- (0 bytes)
CGAL Cache hit: multmatrix([[0.984808,0.173648,2.77556e- (0 bytes)
CGAL Cache hit: multmatrix([[0.984808,0.173648,2.77556e- (0 bytes)
CGAL Cache hit: multmatrix([[0.984808,0.173648,2.77556e- (0 bytes)
CGAL Cache hit: multmatrix([[0.984808,0.173648,2.77556e- (0 bytes)
CGAL Cache hit: multmatrix([[0.984808,0.173648,2.77556e- (0 bytes)
CGAL Cache hit: multmatrix([[0.984808,0.173648,2.77556e- (0 bytes)
CGAL Cache hit: multmatrix([[0.984808,0.173648,2.77556e- (0 bytes)
CGAL Cache hit: multmatrix([[0.984808,0.173648,2.77556e- (0 bytes)
CGAL Cache hit: multmatrix([[0.984808,0.173648,2.77556e- (0 bytes)
CGAL Cache hit: multmatrix([[0.984808,0.173648,2.77556e- (0 bytes)
CGAL Cache hit: multmatrix([[0.984808,0.173648,2.77556e- (0 bytes)
CGAL Cache hit: multmatrix([[0.984808,0.173648,2.77556e- (0 bytes)
CGAL Cache insert: multmatrix([[1,0,0,0],[0,1,0,-41],[0,0,1 (0 bytes)
CGAL Cache insert: multmatrix([[1,0,0,0],[0,1,0,-42],[0,0,1 (0 bytes)
CGAL Cache insert: multmatrix([[1,0,0,0],[0,1,0,-43],[0,0,1 (0 bytes)
CGAL Cache insert: multmatrix([[1,0,0,0],[0,1,0,-44],[0,0,1 (0 bytes)
CGAL Cache insert: multmatrix([[1,0,0,0],[0,1,0,-45],[0,0,1 (0 bytes)
CGAL Cache insert: multmatrix([[1,0,0,0],[0,1,0,-46],[0,0,1 (0 bytes)
CGAL Cache insert: multmatrix([[1,0,0,0],[0,1,0,-47],[0,0,1 (0 bytes)
CGAL Cache insert: multmatrix([[1,0,0,0],[0,1,0,-48],[0,0,1 (0 bytes)
CGAL Cache insert: multmatrix([[1,0,0,0],[0,1,0,-49],[0,0,1 (0 bytes)
CGAL Cache insert: multmatrix([[1,0,0,0],[0,1,0,-50],[0,0,1 (0 bytes)
CGAL Cache insert: multmatrix([[1,0,0,0],[0,1,0,-51],[0,0,1 (0 bytes)
CGAL Cache insert: multmatrix([[1,0,0,0],[0,1,0,-52],[0,0,1 (0 bytes)
CGAL Cache insert: multmatrix([[1,0,0,0],[0,1,0,-53],[0,0,1 (0 bytes)
CGAL Cache insert: multmatrix([[1,0,0,0],[0,1,0,-54],[0,0,1 (0 bytes)
CGAL Cache insert: multmatrix([[1,0,0,0],[0,1,0,-55],[0,0,1 (0 bytes)
CGAL Cache insert: multmatrix([[1,0,0,0],[0,1,0,-56],[0,0,1 (0 bytes)
CGAL Cache insert: multmatrix([[1,0,0,0],[0,1,0,-57],[0,0,1 (0 bytes)
CGAL Cache insert: group(){multmatrix([[1,0,0,0],[0,1,0,-41 (0 bytes)
CGAL Cache insert: multmatrix([[1,0,0,0],[0,2.22045e-16,-1, (518904 bytes)
CGAL Cache insert: group(){group(){multmatrix([[1,0,0,0],[0 (0 bytes)
CGAL Cache insert: difference(){multmatrix([[1,0,0,0],[0,2. (518904 bytes)
CGAL Cache insert: group(){difference(){multmatrix([[1,0,0, (518904 bytes)
PolySets in cache: 2
PolySet cache size in bytes: 42440
CGAL Polyhedrons in cache: 25
CGAL cache size in bytes: 2079928
   Top level object is a 3D object:
   Simple:        yes
   Valid:         yes
   Vertices:      400
   Halfedges:    1200
   Edges:         600
   Halffacets:    404
   Facets:        202
   Volumes:         2
Total rendering time: 0 hours, 0 minutes, 0 seconds
Rendering finished.

On compiling -



On rendering -



Now I tried some suggestions on my Ubuntu 14.04 desktop, actually just about any solution related to problems using the diff method I found online like flushing the cache before rendering, changing convexity among others. None of it solved my problem. I really wish to achieve the result that comes up on compiling the code, if any of you can give me something that will achieve that either by fixing the code here or completely rewriting it, I will be very grateful!
Reply | Threaded
Open this post in threaded view
|

Re: Problem with difference() method

jon_bondy
Your loop goes from 57 to 41; that is, it will never execute (create any
polygons).  But even if it had, polygons are 2D and the cylinder is 3D,
so the difference will do nothing.  You could use linear_extrude() to
give the circles some 3D height

Jon


On 9/19/2016 7:47 AM, arecibokck wrote:

> Hello, I am new to this forum/mailing list just as much as I am new to
> OpenSCAD. I have been trying to make a 3D model with the following code -
>
> $fn = 200;
>
> module polygons()
> {
> for (i=[57:1:41]){
> translate([0,-i,9]){
> rotate([90,10,0]){
> circle(10,$fn=9);
> }
> }
> }
> }
>
> difference(){
>
> rotate([90,0,0]){
>
> cylinder(r=4,h=58);
> }
> polygons();
> }
>
> The problem I am facing is that even though it shows the model exactly as I
> want it upon compiling the code(F5), the render process (F6) gives me just a
> cylinder, almost like it completely ignores the diff with my polygons()
> module. The console shows the following output as it renders the model -
>
> Module cache size: 0 modules
> Compiling design (CSG Tree generation)...
> Rendering Polygon Mesh using CGAL...
> PolySetCache hit: cylinder($fn=200,$fa=12,$fs=2,h=58,r1=4,
> CGAL Cache insert: cylinder($fn=200,$fa=12,$fs=2,h=58,r1=4, (518904 bytes)
> PolySetCache hit: circle($fn=9,$fa=12,$fs=2,r=10);
> CGAL Cache insert: circle($fn=9,$fa=12,$fs=2,r=10); (4312 bytes)
> CGAL Cache insert: multmatrix([[0.984808,0.173648,2.77556e- (0 bytes)
> CGAL Cache hit: multmatrix([[0.984808,0.173648,2.77556e- (0 bytes)
> CGAL Cache hit: multmatrix([[0.984808,0.173648,2.77556e- (0 bytes)
> CGAL Cache hit: multmatrix([[0.984808,0.173648,2.77556e- (0 bytes)
> CGAL Cache hit: multmatrix([[0.984808,0.173648,2.77556e- (0 bytes)
> CGAL Cache hit: multmatrix([[0.984808,0.173648,2.77556e- (0 bytes)
> CGAL Cache hit: multmatrix([[0.984808,0.173648,2.77556e- (0 bytes)
> CGAL Cache hit: multmatrix([[0.984808,0.173648,2.77556e- (0 bytes)
> CGAL Cache hit: multmatrix([[0.984808,0.173648,2.77556e- (0 bytes)
> CGAL Cache hit: multmatrix([[0.984808,0.173648,2.77556e- (0 bytes)
> CGAL Cache hit: multmatrix([[0.984808,0.173648,2.77556e- (0 bytes)
> CGAL Cache hit: multmatrix([[0.984808,0.173648,2.77556e- (0 bytes)
> CGAL Cache hit: multmatrix([[0.984808,0.173648,2.77556e- (0 bytes)
> CGAL Cache hit: multmatrix([[0.984808,0.173648,2.77556e- (0 bytes)
> CGAL Cache hit: multmatrix([[0.984808,0.173648,2.77556e- (0 bytes)
> CGAL Cache hit: multmatrix([[0.984808,0.173648,2.77556e- (0 bytes)
> CGAL Cache hit: multmatrix([[0.984808,0.173648,2.77556e- (0 bytes)
> CGAL Cache insert: multmatrix([[1,0,0,0],[0,1,0,-41],[0,0,1 (0 bytes)
> CGAL Cache insert: multmatrix([[1,0,0,0],[0,1,0,-42],[0,0,1 (0 bytes)
> CGAL Cache insert: multmatrix([[1,0,0,0],[0,1,0,-43],[0,0,1 (0 bytes)
> CGAL Cache insert: multmatrix([[1,0,0,0],[0,1,0,-44],[0,0,1 (0 bytes)
> CGAL Cache insert: multmatrix([[1,0,0,0],[0,1,0,-45],[0,0,1 (0 bytes)
> CGAL Cache insert: multmatrix([[1,0,0,0],[0,1,0,-46],[0,0,1 (0 bytes)
> CGAL Cache insert: multmatrix([[1,0,0,0],[0,1,0,-47],[0,0,1 (0 bytes)
> CGAL Cache insert: multmatrix([[1,0,0,0],[0,1,0,-48],[0,0,1 (0 bytes)
> CGAL Cache insert: multmatrix([[1,0,0,0],[0,1,0,-49],[0,0,1 (0 bytes)
> CGAL Cache insert: multmatrix([[1,0,0,0],[0,1,0,-50],[0,0,1 (0 bytes)
> CGAL Cache insert: multmatrix([[1,0,0,0],[0,1,0,-51],[0,0,1 (0 bytes)
> CGAL Cache insert: multmatrix([[1,0,0,0],[0,1,0,-52],[0,0,1 (0 bytes)
> CGAL Cache insert: multmatrix([[1,0,0,0],[0,1,0,-53],[0,0,1 (0 bytes)
> CGAL Cache insert: multmatrix([[1,0,0,0],[0,1,0,-54],[0,0,1 (0 bytes)
> CGAL Cache insert: multmatrix([[1,0,0,0],[0,1,0,-55],[0,0,1 (0 bytes)
> CGAL Cache insert: multmatrix([[1,0,0,0],[0,1,0,-56],[0,0,1 (0 bytes)
> CGAL Cache insert: multmatrix([[1,0,0,0],[0,1,0,-57],[0,0,1 (0 bytes)
> CGAL Cache insert: group(){multmatrix([[1,0,0,0],[0,1,0,-41 (0 bytes)
> CGAL Cache insert: multmatrix([[1,0,0,0],[0,2.22045e-16,-1, (518904 bytes)
> CGAL Cache insert: group(){group(){multmatrix([[1,0,0,0],[0 (0 bytes)
> CGAL Cache insert: difference(){multmatrix([[1,0,0,0],[0,2. (518904 bytes)
> CGAL Cache insert: group(){difference(){multmatrix([[1,0,0, (518904 bytes)
> PolySets in cache: 2
> PolySet cache size in bytes: 42440
> CGAL Polyhedrons in cache: 25
> CGAL cache size in bytes: 2079928
>     Top level object is a 3D object:
>     Simple:        yes
>     Valid:         yes
>     Vertices:      400
>     Halfedges:    1200
>     Edges:         600
>     Halffacets:    404
>     Facets:        202
>     Volumes:         2
> Total rendering time: 0 hours, 0 minutes, 0 seconds
> Rendering finished.
>
> On compiling -
>
> <http://forum.openscad.org/file/n18421/render.render>
>
> On rendering -
>
> <http://forum.openscad.org/file/n18421/render1.render1>
>
> Now I tried some suggestions on my Ubuntu 14.04 desktop, actually just about
> any solution related to problems using the diff method I found online like
> flushing the cache before rendering, changing convexity among others. None
> of it solved my problem. I really wish to achieve the result that comes up
> on compiling the code, if any of you can give me something that will achieve
> that either by fixing the code here or completely rewriting it, I will be
> very grateful!
>
>
>
> --
> View this message in context: http://forum.openscad.org/Problem-with-difference-method-tp18421.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
>
>
>
> -----
> No virus found in this message.
> Checked by AVG - www.avg.com
> Version: 2016.0.7797 / Virus Database: 4656/13042 - Release Date: 09/18/16
>
>


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Problem with difference() method

arecibokck
The loop actually worked fine and created the polygons (The results I got were attached as images before). I guess if the starting index is higher it just accordingly counts backwards but you were right about the incompatibility between the 2D polygons and the 3D cylinder creating problems for their diff. Your suggestion to use linear_extrude() I am glad to say worked! Here is the code now -

$fn = 200;

module polygons()
{
        linear_extrude(height = 17.5, convexity = 10, twist = 0)
        circle(10,$fn=9);
}

difference(){
       
        rotate([90,0,0]){
                cylinder(r=4,h=58);
        }
       
        translate([0,-41,9]){
                rotate([90,10,0]){
                        polygons();
                }
        }

}

It now gives me exactly what I want! Thank you!
tp3
Reply | Threaded
Open this post in threaded view
|

Re: Problem with difference() method

tp3
On 09/19/2016 02:27 PM, arecibokck wrote:
> The loop actually worked fine and created the polygons
>
That means you are running a quite old OpenSCAD version.
I think that changed in 2014.03 which added the possibility
to give negative step values.

// This produces an empty list as the step is always
// honored in recent versions if explicitly given.
echo([ for (a = [57:1:41]) a ]);
// ECHO: []


// This works as expected.
echo([ for (a = [57:-1:41]) a ]);
// ECHO: [57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41]


// This indeed works but produces a warning. For backward
// compatibility it still behaves like very old OpenSCAD
// versions.
// Note how it swapped the range parameter and generates
// the values in ascending order.
echo([ for (a = [57:41]) a ]);
// DEPRECATED: Using ranges of the form [begin:end] with begin value greater than the end value is deprecated.
// ECHO: [41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57]

ciao,
  Torsten.


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
-- Torsten