Welcome! Log In Create A New Profile

Advanced

Problem with union/difference

Posted by txoof 
Problem with union/difference
January 13, 2013 02:11PM
I'm trying desperately to get three cylinders to join together so I can make a negative space for a countersunk M3 screw. I can't seem to get them all to union properly, however. When the union of the three cylinders is subtracted from a cube a "phantom" layer appears between two of the cylinders. I can't for the life of me figure out what the problem is. Here's a code snip that produces the problem:

//draw counter sunk hole
module draw_csHole (){
  // m3 counter sunk hole
  // m3 dia=5.60
  // m3 headheight=1.5
  // m3 threads=3.0

  dia=5.8;
  headht=1.6;
  thread=3.1;
  
  translate ([0,0,-headht])union(){
    // head
    cylinder(r2=dia/2,r1=thread/2,h=headht, $fn=24);
    translate([0,0,-20])cylinder(r=thread/2,h=50, $fn=24);
    translate([0,0,headht]) cylinder(r=dia/2,h=10, $fn=24);
  }

}

difference(){
translate ([0,0,-2.5])cube([10,10,5]);
draw_csHole();

}

Any suggestions are very welcome!
Re: Problem with union/difference
January 14, 2013 02:41AM
It is the classic coincident faces problem.

Change your code to overlap by 0.001mm and then it is fine:
//draw counter sunk hole
module draw_csHole (){
  // m3 counter sunk hole
  // m3 dia=5.60
  // m3 headheight=1.5
  // m3 threads=3.0

  dia=5.8;
  headht=1.6;
  thread=3.1;
  
  translate ([0,0,-headht])union(){
    // head
    cylinder(r2=dia/2,r1=thread/2,h=headht, $fn=24);
    translate([0,0,-20])cylinder(r=thread/2,h=50, $fn=24);
    translate([0,0,headht-0.001]) cylinder(r=dia/2,h=10, $fn=24);
  }

}

difference(){
	translate ([0,0,-2.5])cube([10,10,5]);
	draw_csHole();
}


Bob Morrison
Wörth am Rhein, Germany
"Luke, use the source!"
BLOG - PHOTOS - Thingiverse
Re: Problem with union/difference
January 14, 2013 02:11PM
@rhmorrison
Thanks for the suggestion. That's exactly what I ended up doing! Is there not a better way to solve this problem? It feels like such a hack to solve the problem this way. Any suggestions on a better way to do this would be greatly appreciated.
Puschkin
Re: Problem with union/difference
January 16, 2013 04:17AM
Hello,
I am new to OpenSCAD and I have a similar problem with phantom layers.
I reduced the behavior to a minimal example. OpenCSG has those overlaying phantom layers.
difference(){
	cylinder(h=10, r=10);
	translate([0,0,-1]) cylinder(h=12, r=7);
}
color("Red")
	intersection(){
		translate([0,0,5]) cube([20,2,10], true);
		cylinder(h=10, r=7);
}

Is there a proper way to get an object that fits in another?
Re: Problem with union/difference
January 16, 2013 04:30AM
Looks like an OpenGL problem. The compiled object (STL saved after pressing F6) looks fine.


Bob Morrison
Wörth am Rhein, Germany
"Luke, use the source!"
BLOG - PHOTOS - Thingiverse
Puschkin
Re: Problem with union/difference
January 16, 2013 07:21AM
Thanks Bob,
your're right.
Is there a way to export .stl with color information?
Re: Problem with union/difference
January 16, 2013 07:36AM
Quote
Puschkin
Is there a way to export .stl with color information?

No!

What is it you want to accomplish?


Bob Morrison
Wörth am Rhein, Germany
"Luke, use the source!"
BLOG - PHOTOS - Thingiverse
Sorry, only registered users may post in this forum.

Click here to login