Adrian Mariano wrote:
Has anybody animated sun and planet gears? Of course.
https://github.com/BelfrySCAD/BOSL2/wiki/gears.scad#functionmodule-spur_gear
See the spur gear module, section 8 above. Be warned that the gears code
is under development right now. It was found to be producing invalid
gears, and the fixes may not yet be entirely complete.
On Wed, Aug 2, 2023 at 1:36 AM mikeonenine@web.de wrote:
Jordan Brown wrote:
Nice model.
Huh. I didn't know that formal parameter specifications were optional.
But still you might want to add the formal parameters (R, r for squircle()
and d for carr()). to avoid the warning messages.
Ah, so that’s what they are for. I never bothered with them in the past,
as they didn’t seem to do anything, and ignored the error messages - if the
code works, that’s good enough for me. But now I know where all the error
messages come from!
You have an undefined variable "e" used in the translate in carrier().
Oh yes, thank you. That must have crept in from another project. In fact
all 3 of those animation lines are superfluous. The animaton comes at the
end, but should probably read rotate([0,0,$t*360/n]) for this particular
application.
Insert rotate([0,0,75/n -14-n]) in the squircle module and the carrier
always comes out with one corner at the top, whatever the number of sides -
well, more or less. I derived that from a plot of rotation against number
of sides, not by calculation from first principles.
BTW I like center=true. It’s very handy e.g. for cutouts: once you have
worked out the correct depth on one side, the other side is the same but
with the opposite sign (see code above). Should be possible to select it as
the default value.
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
I wondered, because I had found a while back that toothed belts can only be used in a very limited way in conjunction with cogwheels. The wheels have to have 20 teeth and the belt 47 (forty-seven) or a multiple thereof, among other things. Why 47?
On 8/3/2023 7:47 PM, mikeonenine@web.de wrote:
||
|What is a vec3 of justification values? A "translate([x,y,z])" in the
module, where x, y and z are 0 or the negative side length?|
First, by a vec3 I mean a vector/list/array of three numbers.
My jcube module takes two arguments: a value or vec3 for the size, and
a justification vec3.
The justification vec3 controls alignment in each of the three axes.
For each axis, -1 puts the cube to the negative side of the origin, 0
centers it on the origin, and +1 puts it on the positive side of the origin.
Thus, e.g.:
jcube(10, j=[1,1,1]);
yields a standard cube in +XYZ.
jcube(10, j=[0,0,0]);
yields a cube that is centered on the origin.
jcube(10, j=[-1,1,0]);
yields a cube that is left of the origin (in -X), in +Y, and centered in Z:
Here's a simplified version of my module. (The real one is part of a
larger justify-anything library that isn't ready for prime time.)
// A justified cube
// dims Dimensions of the cube
// j [jx,jy,jz]:
// +1 toward-positive
// 0 center
// -1 toward-negative
module jcube(dims, j=[1,1,1]) {
dims = is_list(dims) ? dims : [dims, dims, dims];
function o(flag, dim) =
flag > 0 ? 0
: flag < 0 ? -dim
: -dim/2;
translate([o(j[0], dims[0]),
o(j[1], dims[1]),
o(j[2], dims[2])])
cube(dims);
}
One small piece of trickery: we say that you can't change the values of
variables, and this seems to violate that rule. It really doesn't,
because you're allowed to create new variables in inner scopes, and
the definition of those new variables can use the variables from the
outer scope. The argument "dims" is in one scope, and in an inner scope
the assignment creates a new variable "dims". I could have used a
different name, but this style seems less cluttered.
You might also consider a library like BOSL2
https://github.com/BelfrySCAD/BOSL2/wiki. BOSL2's cube()
https://github.com/BelfrySCAD/BOSL2/wiki/shapes3d.scad#functionmodule-cube
provides an equivalent in its "anchor" feature, and much much more.
Consider mine to be more of a first-principles demonstration.
Jordan Brown wrote:
On 8/3/2023 7:47 PM, mikeonenine@web.de wrote:
||
|What is a vec3 of justification values? A "translate([x,y,z])" in the
module, where x, y and z are 0 or the negative side length?|
First, by a vec3 I mean a vector/list/array of three numbers.
My jcube module takes two arguments: a value or vec3 for the size, and
a justification vec3.
The justification vec3 controls alignment in each of the three axes.
For each axis, -1 puts the cube to the negative side of the origin, 0
centers it on the origin, and +1 puts it on the positive side of the origin.
Thus, e.g.:
jcube(10, j=[1,1,1]);
yields a standard cube in +XYZ.
jcube(10, j=[0,0,0]);
yields a cube that is centered on the origin.
jcube(10, j=[-1,1,0]);
yields a cube that is left of the origin (in -X), in +Y, and centered in Z:
Here's a simplified version of my module. (The real one is part of a
larger justify-anything library that isn't ready for prime time.)
// A justified cube
// dims Dimensions of the cube
// j [jx,jy,jz]:
// +1 toward-positive
// 0 center
// -1 toward-negative
module jcube(dims, j=[1,1,1]) {
dims = is_list(dims) ? dims : [dims, dims, dims];
function o(flag, dim) =
flag > 0 ? 0
: flag < 0 ? -dim
: -dim/2;
translate([o(j[0], dims[0]),
o(j[1], dims[1]),
o(j[2], dims[2])])
cube(dims);
}
One small piece of trickery: we say that you can't change the values of
variables, and this seems to violate that rule. It really doesn't,
because you're allowed to create new variables in inner scopes, and
the definition of those new variables can use the variables from the
outer scope. The argument "dims" is in one scope, and in an inner scope
the assignment creates a new variable "dims". I could have used a
different name, but this style seems less cluttered.
You might also consider a library like BOSL2
https://github.com/BelfrySCAD/BOSL2/wiki. BOSL2's cube()
https://github.com/BelfrySCAD/BOSL2/wiki/shapes3d.scad#functionmodule-cube
provides an equivalent in its "anchor" feature, and much much more.
Consider mine to be more of a first-principles demonstration.
Oh dear, I wish I hadn't asked! It's neat, it works nicely, but it contains an exponential increase of stuff that I don't understand. I think I'll stick with your previous module. Then there is the question of more complex one-off shapes like the side cutouts in the planet gear carrier (above).
Center=false is of course needed for rotate_extrude and I recently did a T-piece with the crossbar center=true and the leg center=false so that it starts in the middle of the crossbar and can be lengthened in one direction only instead of going both ways.
What do you call a squircle with any number of sides? A polycle? a circlegon? My module (above) contains an error, which is why it is so difficult to get the orientation right. The corrected module is:
module polycle(n, R, r)
{
rotate([0,0,90/n])
polygon([
for(i = [0:5:355])
[R*sin(i)+r*cos((n-1)*i), R*cos(i)+r*sin((n-1)*i)],
]);
}
Where:
n = number of sides
R = pitch circle radius
r = half-height of lobes
(Of course, it won’t work in the carrier script now as it stands.)
On 8/4/2023 8:17 PM, mikeonenine@web.de wrote:
Oh dear, I wish I hadn't asked! It's neat, it works nicely, but it
contains an exponential increase of stuff that I don't understand.
I will be happy to explain anything you're having trouble with. Here's
a quick start...
|// A justified cube // dims Dimensions of the cube // j [jx,jy,jz]:
// +1 toward-positive // 0 center // -1 toward-negative // //
Default justification is [1,1,1], a normal +XYZ cube module
jcube(dims, j=[1,1,1]) { // If dims is a [x,y,z] list, use it, else
(if it's a plain // number) duplicate it three times to form a
[x,y,z]. dims = is_list(dims) ? dims : [dims, dims, dims]; // Given
a justification value and a dimension, this function // calculates
the offset required in that dimension. function o(flag, dim) = flag
0 ? 0 : flag < 0 ? -dim : -dim/2; // Create a cube, and translate
it appropriately in each of the three // dimensions. translate([
o(j[0], dims[0]), o(j[1], dims[1]), o(j[2], dims[2]) ]) cube(dims); }|
I think I'll stick with your previous module. Then there is the
question of more complex one-off shapes like the side cutouts in the
planet gear carrier (above).
I'm afraid I didn't look at your model in that much detail.
The same basic justification principle can be applied to other shapes -
and I have applied it to a few, like polygons, in some of my projects.
It's hard to apply in general, because you have to know the bounding box
of the object and current OpenSCAD doesn't have a way to find that for a
general object.
Center=false is of course needed for rotate_extrude
It's a little hard to see what center=false would mean for rotate_extrude.
Jordan Brown wrote:
I will be happy to explain anything you're having trouble with. Here's
a quick start...
|// A justified cube // dims Dimensions of the cube // j [jx,jy,jz]:
// +1 toward-positive // 0 center // -1 toward-negative // //
Default justification is [1,1,1], a normal +XYZ cube module
jcube(dims, j=[1,1,1]) { // If dims is a [x,y,z] list, use it, else
(if it's a plain // number) duplicate it three times to form a
[x,y,z]. dims = is_list(dims) ? dims : [dims, dims, dims]; // Given
a justification value and a dimension, this function // calculates
the offset required in that dimension. function o(flag, dim) = flag
0 ? 0 : flag < 0 ? -dim : -dim/2; // Create a cube, and translate
it appropriately in each of the three // dimensions. translate([
o(j[0], dims[0]), o(j[1], dims[1]), o(j[2], dims[2]) ]) cube(dims); }|
That looks interesting. I have started a “dictionary” and put it in there. I must try it out. But as you said, it's hard to apply in general, which I imagine would apply to the cutouts in my squircle carrier design, as they are not standard shapes … unless the principle can be applied to linear_extrude … hmmm.
I'm afraid I didn't look at your model in that much detail.
The cutouts are the green bits if you use the default colour scheme. If everything is center=true, it is easier to get them the same depth both back and front.
It's a little hard to see what center=false would mean for rotate_extrude.
Rotate_extrude doesn’t work if the square or whatever straddles the y-axis, which is the case if centre=true. The whole square has to be one side or the other, which is the case if centre=false. So in this case, the default value is useful. But on balance, I seem to use “true” more often than “false” and so would like to be able to select the default value for each project.
These don’t work, because the squares overlap the y-axis:
rotate_extrude()
square(10, center=true);
rotate_extrude()
offset(2)
square(10);