I have a case of difference() totally not working. In this sense,
totally means that rendering my shape alone results in a valid two
manifold, while substracting a cube causes an INvalid one.
Here's the code. I've marked the cube line with a
//HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!.
It's the 49th line.
// involute_gear_tooth and its math functions provided by:
// Parametric Involute Bevel and Spur Gears by GregFrost
// It is licensed under the Creative Commons - GNU GPL license.
// © 2010 by GregFrost
// http://www.thingiverse.com/thing:3575
// Alterations done: removed [0,0] from the polygon points and path
// Moved pre-union() calculations out as globals
//INPUT START
mod=0.5;
pcd_in=1000; //2147483647
CTTR=.5; // CTT Ratio. 0.5 For mod system. when=1,teeth should touch
Wr=35/2;
starts=1;
backlash=0;
involute_facets=5;
//INPUT END
//===================Module instantiation==========
// Spur body
*rotate([0,90,-90]) translate([0,PCD/2+Wr+dedendum,0])
difference()
{
cylinder(h=1,r=PCR-addendum,$fn=200);
}
// Spur teeth
translate([WPCR+PCR,-2.5,0])
rotate([90,180/N,180])
linear_extrude(height=5)
for(in=[0:N-1])//0:N-1
{
rotate([0,0,in360/N])
involute_gear_tooth();
}
//for(im=[0,1])
//rotate([im*180,0,0])
difference()
{
prism(involute_facets,0,1,30,-7.5,7.5);
//clean under z=0
translate([0,0,-10])
cylinder(r=4Wr,h=10);
//clean under z=0
*translate([-50,-50,7.499])
//HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
cube(100);
}
gtotal=10;
//===================Module instantiation end==========
pi=3.1415926535897932384626433832795;
N=ceil(pcd_in/mod);
PCD=Nmod;
PCR=PCD/2;
echo("Diameter: ",pcd_in,", correction: ",PCD);
echo("MOD ",mod);
echo("Teeth ",N);
addendum = mod;
outer_radius = PCR+addendum;
dedendum = 1.4mod;
WPCR=Wr+dedendum;
base_radius = PCR*cos(20);
echo("PCR=",PCR);
root_radius = PCD/2-dedendum;
CP=pi*mod;//*cos(helix_t);
CTT=CTTR*CP;
backlash_angle = backlash / PCR * 180 / pi;
half_thick_angle = (360 / N - backlash_angle) / 4;
min_radius = max (base_radius,root_radius);
pitch_point = involute (base_radius, involute_intersect_angle
(base_radius, PCR));
pitch_angle = atan2 (pitch_point[1], pitch_point[0]);
centre_angle = pitch_angle + half_thick_angle;
start_angle = involute_intersect_angle (base_radius, min_radius);
stop_angle = involute_intersect_angle (base_radius, outer_radius);
echo("Min radius= ",min_radius);
echo("Outer radius = ",outer_radius);
echo("Base radius = ",base_radius);
echo("Start angle = ",start_angle);
echo("Stop angle = ",stop_angle);
echo("Pitch angle=",pitch_angle);
echo("Half thick angle=",half_thick_angle);
echo("Centre angle = ",centre_angle);
res=(involute_facets!=0)?involute_facets:($fn==0)?5:$fn/4;
echo("0: ",my_inv_pt(0));
function Easin(z)= (z<1 ? asin(z) : 180+asin(z-2));
function givez(p)=[p[0],p[1],0];
function givez_mirrory(p)=[p[0],-p[1],0];
function Ez(z)=PCR-abs(z-PCR);
A=PCR/CP/startspi2;
function helix(z)=AEasin(z/PCR); //Returns angle(progress around
z-axis) of helix done from height 0 to z
function
helix_angle(z)=atan(CPstarts*sqrt(pow(PCR,2)-pow(z,2))/PCR/360);
//Returns the angle of the helix at a specific point (the one we would
get by unwrapping it around z-axis and having it on a plane)
function tf(z,p)=
translate_point(
rotateZ( //progresses the helix
translate_point( // moves so teeth touch spur's pitch
circle
rotateY( //rotates so teeth are vertical to spur's
perimeter
rotateX( //rotates so cross section is normal
to helix
// strech_point(
translate_point( //because involute
tooth creates the teeth at PCR. This returns them so [0,0,0] is the centre
p
,[-PCR,0,0])
// ,[1,1,1])
,-(90-helix_angle(Ez(z))))
,Easin(z/PCR))
,[WPCR+PCR-(z<PCR?1:-1)sqrt(pow(PCR,2)-pow(Ez(z),2)),0,0])
,helix(z))
,[0,0,Ez(z)])
;
function top(z,p)=tf(PCRsin(asin(z/PCR)+360/A),p);
function bcf(x)=givez(my_inv_pt(x));
function mcf(x)=givez_mirrory(my_inv_pt(x));
//square(5);
//C refers to curve, t to transformation
//c is also current, n is next
module prism(cn,c0,c1,tn,t0,t1) //Base Curve Function, Transformation
Function must exist
{
{
dc=(c1-c0)/cn;
dt=(t1-t0)/tn;
echo("main module called for z=[",t0,",",t1,"] @ ",tn,": dz=",dt);
for(i_start=[0:starts-1])
rotate([0,0,360i_start/starts])
{
for(t=[t0:1dt:t1-dt])
{
//echo("z:",t);
// Outer tooth surface
polyhedron(
points=[tf(t,bcf(c1)),tf(t,mcf(c1)),tf(t+dt,bcf(c1)),tf(t+dt,mcf(c1))],
faces=[[2,1,0],[1,2,3]]);
// Inner tooth surface
polyhedron(
points=[tf(t,bcf(c0)),tf(t,mcf(c0)),tf(t+dt,bcf(c0)),tf(t+dt,mcf(c0))],
faces=[[0,1,2],[3,2,1]]);
// Direct solid connection of tooth with radius
*polyhedron(
points=[tf(t,bcf(c0)),tf(t,mcf(c0)),tf(t+dt,bcf(c0)),tf(t+dt,mcf(c0)),[0,0,tf(t,bcf(c0))[2]],[0,0,tf(t,mcf(c0))[2]],[0,0,tf(t+dt,bcf(c0))[2]],[0,0,tf(t+dt,mcf(c0))[2]]],
faces=[[0,2,4],[5,3,1]]);
//Between teeth surface (a difficult one)
polyhedron(
points=[tf(t,bcf(c0)),tf(t+dt,bcf(c0)),top(t,mcf(c0)),top(t+dt,mcf(c0))],
faces=[[0,1,2],[3,2,1]]);
//Side tooth surfaces
for(c=[c0:dc:c1-dc])
{
//echo("-------------");
//echo("z=",t,"c=",c,"pa_i=",tinvolute_facets/dt + c/dc,"
pa: ", tf(t,mcf(c)));
//echo("RotX angle:
",-(90-helix_angle(Ez(t))),"(RAD:",-(90-helix_angle(Ez(t)))*pi/180);
//echo("");
//Top tooth side
polyhedron(
points=[tf(t,bcf(c)),tf(t,bcf(c+dc)),tf(t+dt,bcf(c)),tf(t+dt,bcf(c+dc))],
faces=[[2,1,0],[1,2,3]]);
//Bottom tooth side
polyhedron(
points=[tf(t,mcf(c)),tf(t,mcf(c+dc)),tf(t+dt,mcf(c)),tf(t+dt,mcf(c+dc))],
faces=[[0,1,2],[3,2,1]]);
}
}
echo("Cap @ z=",t0);
for(c=[c0:dc:c1-dc])
polyhedron(
points=[tf(t0,bcf(c)),tf(t0,bcf(c+dc)),tf(t0,mcf(c)),tf(t0,mcf(c+dc))],
faces=[[0,1,2],[3,2,1]]);
echo("Cap @ z=",t1);
for(c=[c0:dc:c1-dc])
polyhedron(
points=[tf(t1,bcf(c)),tf(t1,bcf(c+dc)),tf(t1,mcf(c)),tf(t1,mcf(c+dc))],
faces=[[2,1,0],[1,2,3]]);
}
}
}
module involute_gear_tooth ()
{
// echo("0",base_radius);
// echo("1",start_angle);
// echo("2",stop_angle);
// echo("3",res);
// echo("4",pitch_point);
// echo("5",pitch_angle);
// echo("6",centre_angle);
union ()
{
for (i=[1:res])
assign (
point1=involute (base_radius,start_angle+(stop_angle -
start_angle)*(i-1)/res),
point2=involute (base_radius,start_angle+(stop_angle -
start_angle)*i/res))
{
assign (
side1_point1=my_inv_pt(i-1),
side1_point2=my_inv_pt(i),
side2_point1=mirror_point (rotate_point (centre_angle,
point1)),
side2_point2=mirror_point (rotate_point (centre_angle,
point2)))
{
//echo("i=",i," Polypts: ",side1_point1,",
",side1_point2,", ",side2_point2,", ",side2_point1);
polygon (
points=[side1_point1,side1_point2,side2_point2,side2_point1],
paths=[[0,1,2,3,0]]);
}
}
}
}
// Mathematical Functions for involute_gear_tooth
//===============
// Finds the angle of the involute about the base radius at the given
distance (radius) from it's center.
//source:
http://www.mathhelpforum.com/math-help/geometry/136011-circle-involute-solving-y-any-given-x.html
//progress=0 to 1
function my_inv_pt(progress)=rotate_point(centre_angle,involute
(base_radius,start_angle+(stop_angle - start_angle)*progress));
function involute_intersect_angle (base_radius, radius) = sqrt (pow
(radius/base_radius, 2) - 1) * 180 / pi;
// Calculate the involute position for a given base radius and involute
angle.
function rotated_involute (rotate, base_radius, involute_angle) =
[
cos (rotate) * involute (base_radius, involute_angle)[0] + sin
(rotate) * involute (base_radius, involute_angle)[1],
cos (rotate) * involute (base_radius, involute_angle)[1] - sin
(rotate) * involute (base_radius, involute_angle)[0]
];
function mirror_point (coord) =
[
coord[0],
-coord[1]
];
function rotate_point (rotate, coord) =
[
cos (rotate) * coord[0] + sin (rotate) * coord[1],
cos (rotate) * coord[1] - sin (rotate) * coord[0]
];
function involute (base_radius, involute_angle) =
[
base_radius*(cos (involute_angle) + involute_anglepi/180sin
(involute_angle)),
base_radius*(sin (involute_angle) - involute_anglepi/180cos
(involute_angle)),
];
---============================
module involute_gear_tooth ()
{
union ()
{
for (i=[1:res])
assign (
point1=involute (base_radius,start_angle+(stop_angle -
start_angle)*(i-1)/res),
point2=involute (base_radius,start_angle+(stop_angle -
start_angle)*i/res))
{
assign (
side1_point1=rotate_point (centre_angle, point1),
side1_point2=rotate_point (centre_angle, point2),
side2_point1=mirror_point (rotate_point (centre_angle,
point1)),
side2_point2=mirror_point (rotate_point (centre_angle,
point2)))
{
polygon (
points=[side1_point1,side1_point2,side2_point2,side2_point1],
paths=[[0,1,2,3,4]]);
}
}
}
}
function translate_point(p,d)=[p[0]+d[0],p[1]+d[1],p[2]+d[2]];
function rotateX(p,t)=[
p[0],
p[1]*cos(t)-p[2]*sin(t),
p[1]*sin(t)+p[2]*cos(t)];
function rotateY(p,t)=[
p[2]*sin(t)+p[0]*cos(t),
p[1],
p[2]*cos(t)-p[0]*sin(t),];
function rotateZ(p,t)=[
p[0]*cos(t)-p[1]*sin(t),
p[0]*sin(t)+p[1]*cos(t),
p[2]];
function strech_point(p,s)=[p[0]*s[0],p[1]*s[2],p[2]*s[2]];
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
Your prism() is producing bad geometry.
http://forum.openscad.org/file/n16737/td16736.jpg
CGAL can't work with it.
Admin - PM me if you need anything, or if I've done something stupid...
Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.
View this message in context: http://forum.openscad.org/Difference-not-working-tp16736p16737.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
OpenSCAD states it's a good geometry.
http://smg.photobucket.com/user/lordasriel/media/lightworm_zps4qfbipfs.png.html
What can be wrong?
On 27/03/16 12:28 AM, MichaelAtOz wrote:
Your prism() is producing bad geometry.
http://forum.openscad.org/file/n16737/td16736.jpg
CGAL can't work with it.
Admin - PM me if you need anything, or if I've done something stupid...
Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.
View this message in context: http://forum.openscad.org/Difference-not-working-tp16736p16737.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
My image about, is an export of just your prism() object, loaded into
netfabb, it shows you have
1480 triangles,
1480 shells and
1480 holes
To my that means you have 1480 disconnected bits.
The yellow bits are the holes.
Admin - PM me if you need anything, or if I've done something stupid...
Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.
View this message in context: http://forum.openscad.org/Difference-not-working-tp16736p16739.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
You also don't have ends, it is open geometry.
http://forum.openscad.org/file/n16740/td16736_ends.jpg
Admin - PM me if you need anything, or if I've done something stupid...
Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.
View this message in context: http://forum.openscad.org/Difference-not-working-tp16736p16740.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Sorry - disregard that. My debugging got rid of the ends.
Admin - PM me if you need anything, or if I've done something stupid...
Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.
View this message in context: http://forum.openscad.org/Difference-not-working-tp16736p16741.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
View/Thrown-together
http://forum.openscad.org/file/n16742/td16736_poly.jpg
Your polys are wrong.
See debugging polyhedrons
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Primitive_Solids#polyhedron
.
Admin - PM me if you need anything, or if I've done something stupid...
Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.
View this message in context: http://forum.openscad.org/Difference-not-working-tp16736p16742.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Your last picture doesn't show any error. It seems to me like an
openscad solid with the default gold coloring and having the show edges on.
If you render it, does it state it as simple?
Mine does; if it didn't, I wouldn't disturb you with my mails.
On 27/03/16 2:44 AM, MichaelAtOz wrote:
View/Thrown-together
http://forum.openscad.org/file/n16742/td16736_poly.jpg
Your polys are wrong.
See debugging polyhedrons
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Primitive_Solids#polyhedron
.
Admin - PM me if you need anything, or if I've done something stupid...
Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.
View this message in context: http://forum.openscad.org/Difference-not-working-tp16736p16742.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
OpenSCAD doesn't report an error if you pass bad arguments to polyhedron().
If all you try to do with the bad polyhedron is display it, then it
displays all of the faces, without regard to whether the faces are properly
connected to each other. So this kind of program will appear to work. As
soon as you try to perform a CSG operation on a bad polyhedron, only then
do you have problems: sometimes an error is reported, sometimes you get
nonsense results but no error is reported.
On 27 March 2016 at 05:48, George Menoutis l_as@msn.com wrote:
Your last picture doesn't show any error. It seems to me like an
openscad solid with the default gold coloring and having the show edges on.
If you render it, does it state it as simple?
Mine does; if it didn't, I wouldn't disturb you with my mails.
On 27/03/16 2:44 AM, MichaelAtOz wrote:
View/Thrown-together
http://forum.openscad.org/file/n16742/td16736_poly.jpg
Your polys are wrong.
See debugging polyhedrons
<
.
Admin - PM me if you need anything, or if I've done something stupid...
Unless specifically shown otherwise above, my contribution is in the
Public Domain; to the extent possible under law, I have waived all
copyright and related or neighbouring rights to this work. Obviously
inclusion of works of previous authors is not included in the above.
The TPP is no simple “trade agreement.” Fight it!
http://www.ourfairdeal.org/ time is running out!
--
View this message in context:
Sent from the OpenSCAD mailing list archive at Nabble.com.
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
I tried out and it is as you say. Thank you.
On 27/03/16 11:58 PM, doug moen wrote:
OpenSCAD doesn't report an error if you pass bad arguments to polyhedron(). If all you try to do with the bad polyhedron is display it, then it displays all of the faces, without regard to whether the faces are properly connected to each other. So this kind of program will appear to work. As soon as you try to perform a CSG operation on a bad polyhedron, only then do you have problems: sometimes an error is reported, sometimes you get nonsense results but no error is reported.
On 27 March 2016 at 05:48, George Menoutis <l_as@msn.commailto:l_as@msn.com> wrote:
Your last picture doesn't show any error. It seems to me like an
openscad solid with the default gold coloring and having the show edges on.
If you render it, does it state it as simple?
Mine does; if it didn't, I wouldn't disturb you with my mails.
On 27/03/16 2:44 AM, MichaelAtOz wrote:
View/Thrown-together
http://forum.openscad.org/file/n16742/td16736_poly.jpg
Your polys are wrong.
See debugging polyhedrons
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Primitive_Solids#polyhedron
.
Admin - PM me if you need anything, or if I've done something stupid...
Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.
View this message in context: http://forum.openscad.org/Difference-not-working-tp16736p16742.html http://forum.openscad.org/Difference-not-working-tp16736p16742.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
OpenSCAD mailing list
Discuss@lists.openscad.orgmailto:Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
OpenSCAD mailing list
Discuss@lists.openscad.orgmailto:Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
OpenSCAD mailing list
Discuss@lists.openscad.orgmailto:Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
[https://ipmcdn.avast.com/images/2016/icons/icon-envelope-tick-round-orange-v1.png]https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient&utm_term=oa-2115-v2-c No threats detected. www.avast.comhttps://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient&utm_term=oa-2115-v2-c