discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

question on my code

JD
Jerry Davis
Wed, Apr 15, 2015 10:29 PM

I have a module, called cylhole, which creates a cylinder with a hole in it.
If I call it by itself, it works like I want it to.
If I call it in a difference() it somehow leaves the hole filled.

I am not sure why, and what could I do to do what I really want to do.

Here is the code:

$fn = 60;

// driver gear diameter = 16.32 mm
// driven gear bottom diameter = 45.42 mm
// driven gear top diameter = 13.55 mm
// top layer = 3.15 mm on top of bottom layer

// bottom layer has driver gear and bottom driven gear
// top layer has rack and top driver gear

cube_l = 88;
cube_w = 60;
cube_h = 5;

module cylhole(r=3, h=3, hole=1) {
difference() {
cylinder(r=r, h=h, center=true);
cylinder(r=hole, h=h+1, center=true);
}
}

module bottom(r1=3, r2=3, foclen=9, nr=0) {
fl = (cube_l/8) + (foclen/2) + nr;
fr = (cube_l/8) - (foclen/2) + nr;

difference() {
cube([cube_l, cube_w, cube_h], center=true);
translate([fl, 0, 2]) color("Aqua") cylhole(r=r1, h=cube_h, hole=1,
center=true);
translate([fr, 0, 2]) color("Blue") cylhole(r=r2, h=cube_h, hole=1,
center=true);
}
}

// this doesn't ... hmm.
bottom(r1=16.32/2, r2=45.42/2, foclen=28, nr=7);

// this does what I think it should do
translate([0, cube_w+20, 0]) cylhole(12, 5, 2);

Jerry

--
Extra Ham Operator: K7AZJ
Registered Linux User: 275424
Raspberry Pi and Arduino developer

The most exciting phrase to hear in science - the one that heralds new
discoveries - is not "Eureka!" but "That's funny...".
- Isaac. Asimov

I
*f you give someone a program, you will frustrate them for a day; if you
teach them how to program, you will frustrate them for a lifetime. *-
Anonymous

If writing good code requires very little comments, then writing really
excellent code requires no comments at all!
- Ken Thompson

I have a module, called cylhole, which creates a cylinder with a hole in it. If I call it by itself, it works like I want it to. If I call it in a difference() it somehow leaves the hole filled. I am not sure why, and what could I do to do what I really want to do. Here is the code: $fn = 60; // driver gear diameter = 16.32 mm // driven gear bottom diameter = 45.42 mm // driven gear top diameter = 13.55 mm // top layer = 3.15 mm on top of bottom layer // bottom layer has driver gear and bottom driven gear // top layer has rack and top driver gear cube_l = 88; cube_w = 60; cube_h = 5; module cylhole(r=3, h=3, hole=1) { difference() { cylinder(r=r, h=h, center=true); cylinder(r=hole, h=h+1, center=true); } } module bottom(r1=3, r2=3, foclen=9, nr=0) { fl = (cube_l/8) + (foclen/2) + nr; fr = (cube_l/8) - (foclen/2) + nr; difference() { cube([cube_l, cube_w, cube_h], center=true); translate([fl, 0, 2]) color("Aqua") cylhole(r=r1, h=cube_h, hole=1, center=true); translate([fr, 0, 2]) color("Blue") cylhole(r=r2, h=cube_h, hole=1, center=true); } } // this doesn't ... hmm. bottom(r1=16.32/2, r2=45.42/2, foclen=28, nr=7); // this does what I think it should do translate([0, cube_w+20, 0]) cylhole(12, 5, 2); Jerry -- Extra Ham Operator: K7AZJ Registered Linux User: 275424 Raspberry Pi and Arduino developer *The most exciting phrase to hear in science - the one that heralds new discoveries - is not "Eureka!" but "That's funny...".*- Isaac. Asimov *I* *f you give someone a program, you will frustrate them for a day; if you teach them how to program, you will frustrate them for a lifetime. *- Anonymous *If writing good code requires very little comments, then writing really excellent code requires no comments at all!*- Ken Thompson
YA
Yona Appletree
Wed, Apr 15, 2015 10:38 PM

Jerry,

I'm not sure I understand the problem. It seems like it works to me...
you end up with a cylinder in the middle of the "bottom" section as I
would expect:

What are you expecting it to do, exactly?

  • Yona

Jerry Davis mailto:jdawgaz@gmail.com
April 15, 2015 at 15:29
I have a module, called cylhole, which creates a cylinder with a hole
in it.
If I call it by itself, it works like I want it to.
If I call it in a difference() it somehow leaves the hole filled.

I am not sure why, and what could I do to do what I really want to do.

Here is the code:

$fn = 60;

// driver gear diameter = 16.32 mm
// driven gear bottom diameter = 45.42 mm
// driven gear top diameter = 13.55 mm
// top layer = 3.15 mm on top of bottom layer

// bottom layer has driver gear and bottom driven gear
// top layer has rack and top driver gear

cube_l = 88;
cube_w = 60;
cube_h = 5;

module cylhole(r=3, h=3, hole=1) {
difference() {
cylinder(r=r, h=h, center=true);
cylinder(r=hole, h=h+1, center=true);
}
}

module bottom(r1=3, r2=3, foclen=9, nr=0) {
fl = (cube_l/8) + (foclen/2) + nr;
fr = (cube_l/8) - (foclen/2) + nr;
difference() {
cube([cube_l, cube_w, cube_h], center=true);
translate([fl, 0, 2]) color("Aqua") cylhole(r=r1, h=cube_h,
hole=1, center=true);
translate([fr, 0, 2]) color("Blue") cylhole(r=r2, h=cube_h,
hole=1, center=true);
}
}

// this doesn't ... hmm.
bottom(r1=16.32/2, r2=45.42/2, foclen=28, nr=7);

// this does what I think it should do
translate([0, cube_w+20, 0]) cylhole(12, 5, 2);

Jerry

--
Extra Ham Operator: K7AZJ
Registered Linux User: 275424
Raspberry Pi and Arduino developer

/The most exciting phrase to hear in science - the one that heralds
new discoveries - is not "Eureka!" but "That's funny...".
/- Isaac. Asimov

/I//f you give someone a program, you will frustrate them for a day;
if you teach them how to program, you will frustrate them for a lifetime.
/- Anonymous

/If writing good code requires very little comments, then writing
really excellent code requires no comments at all!
/- Ken Thompson


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

Jerry, I'm not sure I understand the problem. It seems like it works to me... you end up with a cylinder in the middle of the "bottom" section as I would expect: What are you expecting it to do, exactly? - Yona > Jerry Davis <mailto:jdawgaz@gmail.com> > April 15, 2015 at 15:29 > I have a module, called cylhole, which creates a cylinder with a hole > in it. > If I call it by itself, it works like I want it to. > If I call it in a difference() it somehow leaves the hole filled. > > I am not sure why, and what could I do to do what I really want to do. > > Here is the code: > > $fn = 60; > > // driver gear diameter = 16.32 mm > // driven gear bottom diameter = 45.42 mm > // driven gear top diameter = 13.55 mm > // top layer = 3.15 mm on top of bottom layer > > // bottom layer has driver gear and bottom driven gear > // top layer has rack and top driver gear > > cube_l = 88; > cube_w = 60; > cube_h = 5; > > module cylhole(r=3, h=3, hole=1) { > difference() { > cylinder(r=r, h=h, center=true); > cylinder(r=hole, h=h+1, center=true); > } > } > > module bottom(r1=3, r2=3, foclen=9, nr=0) { > fl = (cube_l/8) + (foclen/2) + nr; > fr = (cube_l/8) - (foclen/2) + nr; > difference() { > cube([cube_l, cube_w, cube_h], center=true); > translate([fl, 0, 2]) color("Aqua") cylhole(r=r1, h=cube_h, > hole=1, center=true); > translate([fr, 0, 2]) color("Blue") cylhole(r=r2, h=cube_h, > hole=1, center=true); > } > } > > // this doesn't ... hmm. > bottom(r1=16.32/2, r2=45.42/2, foclen=28, nr=7); > > // this does what I think it should do > translate([0, cube_w+20, 0]) cylhole(12, 5, 2); > > Jerry > > -- > Extra Ham Operator: K7AZJ > Registered Linux User: 275424 > Raspberry Pi and Arduino developer > > /The most exciting phrase to hear in science - the one that heralds > new discoveries - is not "Eureka!" but "That's funny...". > /- Isaac. Asimov > > /I//f you give someone a program, you will frustrate them for a day; > if you teach them how to program, you will frustrate them for a lifetime. > /- Anonymous > > /If writing good code requires very little comments, then writing > really excellent code requires no comments at all! > /- Ken Thompson > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
DV
david vanhorn
Wed, Apr 15, 2015 11:02 PM

I see why you were confused.

The module you've created basically is an unthreaded spacer.  A cylinder
with a hole in the middle.
If  you differenced that (shoved that spacer into) with a lump of clay,
you'd end  up with the picture above.

Sounds like you were expecting a hole with the OD of the unthreaded spacer.

This is a case of "be careful what you ask for, you may get it."  :)

On Wed, Apr 15, 2015 at 4:38 PM, Yona Appletree hypher@gmail.com wrote:

Jerry,

I'm not sure I understand the problem. It seems like it works to me... you
end up with a cylinder in the middle of the "bottom" section as I would
expect:

What are you expecting it to do, exactly?

  • Yona

    Jerry Davis jdawgaz@gmail.com
    April 15, 2015 at 15:29
    I have a module, called cylhole, which creates a cylinder with a hole in
    it.
    If I call it by itself, it works like I want it to.
    If I call it in a difference() it somehow leaves the hole filled.

I am not sure why, and what could I do to do what I really want to do.

Here is the code:

$fn = 60;

// driver gear diameter = 16.32 mm
// driven gear bottom diameter = 45.42 mm
// driven gear top diameter = 13.55 mm
// top layer = 3.15 mm on top of bottom layer

// bottom layer has driver gear and bottom driven gear
// top layer has rack and top driver gear

cube_l = 88;
cube_w = 60;
cube_h = 5;

module cylhole(r=3, h=3, hole=1) {
difference() {
cylinder(r=r, h=h, center=true);
cylinder(r=hole, h=h+1, center=true);
}
}

module bottom(r1=3, r2=3, foclen=9, nr=0) {
fl = (cube_l/8) + (foclen/2) + nr;
fr = (cube_l/8) - (foclen/2) + nr;

difference() {
cube([cube_l, cube_w, cube_h], center=true);
translate([fl, 0, 2]) color("Aqua") cylhole(r=r1, h=cube_h, hole=1,
center=true);
translate([fr, 0, 2]) color("Blue") cylhole(r=r2, h=cube_h, hole=1,
center=true);
}
}

// this doesn't ... hmm.
bottom(r1=16.32/2, r2=45.42/2, foclen=28, nr=7);

// this does what I think it should do
translate([0, cube_w+20, 0]) cylhole(12, 5, 2);

Jerry

--
Extra Ham Operator: K7AZJ
Registered Linux User: 275424
Raspberry Pi and Arduino developer

The most exciting phrase to hear in science - the one that heralds new
discoveries - is not "Eureka!" but "That's funny...".
- Isaac. Asimov

I
*f you give someone a program, you will frustrate them for a day; if you
teach them how to program, you will frustrate them for a lifetime. *-
Anonymous

If writing good code requires very little comments, then writing really
excellent code requires no comments at all!
- Ken Thompson


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

I see why you were confused. The module you've created basically is an unthreaded spacer. A cylinder with a hole in the middle. If you differenced that (shoved that spacer into) with a lump of clay, you'd end up with the picture above. Sounds like you were expecting a hole with the OD of the unthreaded spacer. This is a case of "be careful what you ask for, you may get it." :) On Wed, Apr 15, 2015 at 4:38 PM, Yona Appletree <hypher@gmail.com> wrote: > Jerry, > > I'm not sure I understand the problem. It seems like it works to me... you > end up with a cylinder in the middle of the "bottom" section as I would > expect: > > > > What are you expecting it to do, exactly? > > - Yona > > Jerry Davis <jdawgaz@gmail.com> > April 15, 2015 at 15:29 > I have a module, called cylhole, which creates a cylinder with a hole in > it. > If I call it by itself, it works like I want it to. > If I call it in a difference() it somehow leaves the hole filled. > > I am not sure why, and what could I do to do what I really want to do. > > Here is the code: > > $fn = 60; > > // driver gear diameter = 16.32 mm > // driven gear bottom diameter = 45.42 mm > // driven gear top diameter = 13.55 mm > // top layer = 3.15 mm on top of bottom layer > > // bottom layer has driver gear and bottom driven gear > // top layer has rack and top driver gear > > cube_l = 88; > cube_w = 60; > cube_h = 5; > > module cylhole(r=3, h=3, hole=1) { > difference() { > cylinder(r=r, h=h, center=true); > cylinder(r=hole, h=h+1, center=true); > } > } > > module bottom(r1=3, r2=3, foclen=9, nr=0) { > fl = (cube_l/8) + (foclen/2) + nr; > fr = (cube_l/8) - (foclen/2) + nr; > > difference() { > cube([cube_l, cube_w, cube_h], center=true); > translate([fl, 0, 2]) color("Aqua") cylhole(r=r1, h=cube_h, hole=1, > center=true); > translate([fr, 0, 2]) color("Blue") cylhole(r=r2, h=cube_h, hole=1, > center=true); > } > } > > // this doesn't ... hmm. > bottom(r1=16.32/2, r2=45.42/2, foclen=28, nr=7); > > // this does what I think it should do > translate([0, cube_w+20, 0]) cylhole(12, 5, 2); > > Jerry > > -- > Extra Ham Operator: K7AZJ > Registered Linux User: 275424 > Raspberry Pi and Arduino developer > > > *The most exciting phrase to hear in science - the one that heralds new > discoveries - is not "Eureka!" but "That's funny...".*- Isaac. Asimov > > *I* > *f you give someone a program, you will frustrate them for a day; if you > teach them how to program, you will frustrate them for a lifetime. *- > Anonymous > > > *If writing good code requires very little comments, then writing really > excellent code requires no comments at all!*- Ken Thompson > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > >
JD
Jerry Davis
Thu, Apr 16, 2015 12:15 AM

ok, I got it. because I had a hole in the cylhole module, that hole when
differenced in the bottom module, became the opposite.

I got rid of the cylhole module and changed the difference() to be:

difference() {
cube([cube_l, cube_w, cube_h], center=true);
translate([fl, 0, 2]) color("Aqua") cylinder(r=r1, h=cube_h,
center=true);
translate([fl, 0, -1]) color("Aqua") cylinder(r=2, h=cube_h,
center=true);
translate([fr, 0, 2]) color("Blue") cylinder(r=r2, h=cube_h,
center=true);
translate([fr, 0, -1]) color("Blue") cylinder(r=2, h=cube_h,
center=true);
}

and now it is as I wanted.
Boy, did I learn a lesson there!

Jerry

--
Extra Ham Operator: K7AZJ
Registered Linux User: 275424
Raspberry Pi and Arduino developer

The most exciting phrase to hear in science - the one that heralds new
discoveries - is not "Eureka!" but "That's funny...".
- Isaac. Asimov

I
*f you give someone a program, you will frustrate them for a day; if you
teach them how to program, you will frustrate them for a lifetime. *-
Anonymous

If writing good code requires very little comments, then writing really
excellent code requires no comments at all!
- Ken Thompson

On Wed, Apr 15, 2015 at 4:02 PM, david vanhorn kc6ete@gmail.com wrote:

I see why you were confused.

The module you've created basically is an unthreaded spacer.  A cylinder
with a hole in the middle.
If  you differenced that (shoved that spacer into) with a lump of clay,
you'd end  up with the picture above.

Sounds like you were expecting a hole with the OD of the unthreaded
spacer.

This is a case of "be careful what you ask for, you may get it."  :)

On Wed, Apr 15, 2015 at 4:38 PM, Yona Appletree hypher@gmail.com wrote:

Jerry,

I'm not sure I understand the problem. It seems like it works to me...
you end up with a cylinder in the middle of the "bottom" section as I would
expect:

What are you expecting it to do, exactly?

  • Yona

    Jerry Davis jdawgaz@gmail.com
    April 15, 2015 at 15:29
    I have a module, called cylhole, which creates a cylinder with a hole in
    it.
    If I call it by itself, it works like I want it to.
    If I call it in a difference() it somehow leaves the hole filled.

I am not sure why, and what could I do to do what I really want to do.

Here is the code:

$fn = 60;

// driver gear diameter = 16.32 mm
// driven gear bottom diameter = 45.42 mm
// driven gear top diameter = 13.55 mm
// top layer = 3.15 mm on top of bottom layer

// bottom layer has driver gear and bottom driven gear
// top layer has rack and top driver gear

cube_l = 88;
cube_w = 60;
cube_h = 5;

module cylhole(r=3, h=3, hole=1) {
difference() {
cylinder(r=r, h=h, center=true);
cylinder(r=hole, h=h+1, center=true);
}
}

module bottom(r1=3, r2=3, foclen=9, nr=0) {
fl = (cube_l/8) + (foclen/2) + nr;
fr = (cube_l/8) - (foclen/2) + nr;

difference() {
cube([cube_l, cube_w, cube_h], center=true);
translate([fl, 0, 2]) color("Aqua") cylhole(r=r1, h=cube_h, hole=1,
center=true);
translate([fr, 0, 2]) color("Blue") cylhole(r=r2, h=cube_h, hole=1,
center=true);
}
}

// this doesn't ... hmm.
bottom(r1=16.32/2, r2=45.42/2, foclen=28, nr=7);

// this does what I think it should do
translate([0, cube_w+20, 0]) cylhole(12, 5, 2);

Jerry

--
Extra Ham Operator: K7AZJ
Registered Linux User: 275424
Raspberry Pi and Arduino developer

The most exciting phrase to hear in science - the one that heralds new
discoveries - is not "Eureka!" but "That's funny...".
- Isaac. Asimov

I
*f you give someone a program, you will frustrate them for a day; if you
teach them how to program, you will frustrate them for a lifetime. *-
Anonymous

If writing good code requires very little comments, then writing really
excellent code requires no comments at all!
- Ken Thompson


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

ok, I got it. because I had a hole in the cylhole module, that hole when differenced in the bottom module, became the opposite. I got rid of the cylhole module and changed the difference() to be: difference() { cube([cube_l, cube_w, cube_h], center=true); translate([fl, 0, 2]) color("Aqua") cylinder(r=r1, h=cube_h, center=true); translate([fl, 0, -1]) color("Aqua") cylinder(r=2, h=cube_h, center=true); translate([fr, 0, 2]) color("Blue") cylinder(r=r2, h=cube_h, center=true); translate([fr, 0, -1]) color("Blue") cylinder(r=2, h=cube_h, center=true); } and now it is as I wanted. Boy, did I learn a lesson there! Jerry -- Extra Ham Operator: K7AZJ Registered Linux User: 275424 Raspberry Pi and Arduino developer *The most exciting phrase to hear in science - the one that heralds new discoveries - is not "Eureka!" but "That's funny...".*- Isaac. Asimov *I* *f you give someone a program, you will frustrate them for a day; if you teach them how to program, you will frustrate them for a lifetime. *- Anonymous *If writing good code requires very little comments, then writing really excellent code requires no comments at all!*- Ken Thompson On Wed, Apr 15, 2015 at 4:02 PM, david vanhorn <kc6ete@gmail.com> wrote: > I see why you were confused. > > The module you've created basically is an unthreaded spacer. A cylinder > with a hole in the middle. > If you differenced that (shoved that spacer into) with a lump of clay, > you'd end up with the picture above. > > Sounds like you were expecting a hole with the OD of the unthreaded > spacer. > > This is a case of "be careful what you ask for, you may get it." :) > > > > > > > On Wed, Apr 15, 2015 at 4:38 PM, Yona Appletree <hypher@gmail.com> wrote: > >> Jerry, >> >> I'm not sure I understand the problem. It seems like it works to me... >> you end up with a cylinder in the middle of the "bottom" section as I would >> expect: >> >> >> >> What are you expecting it to do, exactly? >> >> - Yona >> >> Jerry Davis <jdawgaz@gmail.com> >> April 15, 2015 at 15:29 >> I have a module, called cylhole, which creates a cylinder with a hole in >> it. >> If I call it by itself, it works like I want it to. >> If I call it in a difference() it somehow leaves the hole filled. >> >> I am not sure why, and what could I do to do what I really want to do. >> >> Here is the code: >> >> $fn = 60; >> >> // driver gear diameter = 16.32 mm >> // driven gear bottom diameter = 45.42 mm >> // driven gear top diameter = 13.55 mm >> // top layer = 3.15 mm on top of bottom layer >> >> // bottom layer has driver gear and bottom driven gear >> // top layer has rack and top driver gear >> >> cube_l = 88; >> cube_w = 60; >> cube_h = 5; >> >> module cylhole(r=3, h=3, hole=1) { >> difference() { >> cylinder(r=r, h=h, center=true); >> cylinder(r=hole, h=h+1, center=true); >> } >> } >> >> module bottom(r1=3, r2=3, foclen=9, nr=0) { >> fl = (cube_l/8) + (foclen/2) + nr; >> fr = (cube_l/8) - (foclen/2) + nr; >> >> difference() { >> cube([cube_l, cube_w, cube_h], center=true); >> translate([fl, 0, 2]) color("Aqua") cylhole(r=r1, h=cube_h, hole=1, >> center=true); >> translate([fr, 0, 2]) color("Blue") cylhole(r=r2, h=cube_h, hole=1, >> center=true); >> } >> } >> >> // this doesn't ... hmm. >> bottom(r1=16.32/2, r2=45.42/2, foclen=28, nr=7); >> >> // this does what I think it should do >> translate([0, cube_w+20, 0]) cylhole(12, 5, 2); >> >> Jerry >> >> -- >> Extra Ham Operator: K7AZJ >> Registered Linux User: 275424 >> Raspberry Pi and Arduino developer >> >> >> *The most exciting phrase to hear in science - the one that heralds new >> discoveries - is not "Eureka!" but "That's funny...".*- Isaac. Asimov >> >> *I* >> *f you give someone a program, you will frustrate them for a day; if you >> teach them how to program, you will frustrate them for a lifetime. *- >> Anonymous >> >> >> *If writing good code requires very little comments, then writing really >> excellent code requires no comments at all!*- Ken Thompson >> _______________________________________________ >> OpenSCAD mailing list >> Discuss@lists.openscad.org >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >> >> >> _______________________________________________ >> OpenSCAD mailing list >> Discuss@lists.openscad.org >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >> >> > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > >