discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

SHM

M
mikeonenine@web.de
Sat, Aug 15, 2020 1:41 AM

Hi,

I am a newbie to CAD but have always found it fascinating. I recently got myself OpenScad to show a novel mechanism animated in 3D.

Part of the mechanism moves back and forth with SHM, which I have achieved by juggling with a combination of 3 command pairs of translate and rotate, but surely there is a much more elegant way of doing it.

Surely it can be done in one line with translate, $t, sin or cos and an i=360 somewhere, but how? It doesn't seem to figure in the internet and tutorials.

This is how I did it:

translate([0,0,0])
rotate([0,0,$t*-360])
translate([0,50,0])
rotate([0,0,-146+$t720])
translate([0,-50,0])
rotate([0,0,73+$t
-360])

color("blue")

{
difference()
{
translate([-200,-30,0])
cube([400,60,20]);

hull ()
{

translate([105,0,-1])
cylinder(h=22, r=17);
translate([-105,0,-1])
cylinder(h=22, r=17);
}}}

That works, but can anyone clean it up?

DM
Doug Moen
Sat, Aug 15, 2020 3:32 AM

Something like this maybe?

translate([sin($t*1000)*100,0,0])
color("blue")
{
difference()
{
translate([-200,-30,0])
cube([400,60,20]);

hull ()
{
translate([105,0,-1])
cylinder(h=22, r=17);
translate([-105,0,-1])
cylinder(h=22, r=17);
}}}

On Sat, Aug 15, 2020, at 1:41 AM, mikeonenine@web.de wrote:

Hi,

I am a newbie to CAD but have always found it fascinating. I recently got myself OpenScad to show a novel mechanism animated in 3D.

Part of the mechanism moves back and forth with SHM, which I have achieved by juggling with a combination of 3 command pairs of translate and rotate, but surely there is a much more elegant way of doing it.

Surely it can be done in one line with translate, $t, sin or cos and an i=360 somewhere, but how? It doesn't seem to figure in the internet and tutorials.

This is how I did it:

translate([0,0,0])
rotate([0,0,$t*-360])
translate([0,50,0])
rotate([0,0,-146+$t720])
translate([0,-50,0])
rotate([0,0,73+$t
-360])
color("blue")
{
difference()
{
translate([-200,-30,0])
cube([400,60,20]);

hull ()
{
translate([105,0,-1])
cylinder(h=22, r=17);
translate([-105,0,-1])
cylinder(h=22, r=17);
}}}

That works, but can anyone clean it up?


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

Something like this maybe? translate([sin($t*1000)*100,0,0]) color("blue") { difference() { translate([-200,-30,0]) cube([400,60,20]); hull () { translate([105,0,-1]) cylinder(h=22, r=17); translate([-105,0,-1]) cylinder(h=22, r=17); }}} On Sat, Aug 15, 2020, at 1:41 AM, mikeonenine@web.de wrote: > Hi, > > I am a newbie to CAD but have always found it fascinating. I recently got myself OpenScad to show a novel mechanism animated in 3D. > > Part of the mechanism moves back and forth with SHM, which I have achieved by juggling with a combination of 3 command pairs of translate and rotate, but surely there is a much more elegant way of doing it. > > Surely it can be done in one line with translate, $t, sin or cos and an i=360 somewhere, but how? It doesn't seem to figure in the internet and tutorials. > > This is how I did it: > > translate([0,0,0]) > rotate([0,0,$t*-360]) > translate([0,50,0]) > rotate([0,0,-146+$t*720]) > translate([0,-50,0]) > rotate([0,0,73+$t*-360]) > color("blue") > { > difference() > { > translate([-200,-30,0]) > cube([400,60,20]); > > hull () > { > translate([105,0,-1]) > cylinder(h=22, r=17); > translate([-105,0,-1]) > cylinder(h=22, r=17); > }}} > > That works, but can anyone clean it up? > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
C
Caddiy
Sat, Aug 15, 2020 5:40 AM

Thanx Doug - that looks a lot better and is easier to handle!

Just perfect with a little tweaking:

rotate([0,0,-73])
translate([sin($t*360)*105,0,0])

But odd that clockwise rotation is negative?

Something like this maybe?

translate([sin($t*1000)*100,0,0])
color("blue")
{
difference()
{
translate([-200,-30,0])
cube([400,60,20]);

hull ()
{
translate([105,0,-1])
cylinder(h=22, r=17);
translate([-105,0,-1])
cylinder(h=22, r=17);
}}}

--
Sent from: http://forum.openscad.org/

Thanx Doug - that looks a lot better and is easier to handle! Just perfect with a little tweaking: rotate([0,0,-73]) translate([sin($t*360)*105,0,0]) But odd that clockwise rotation is negative? Something like this maybe? translate([sin($t*1000)*100,0,0]) color("blue") { difference() { translate([-200,-30,0]) cube([400,60,20]); hull () { translate([105,0,-1]) cylinder(h=22, r=17); translate([-105,0,-1]) cylinder(h=22, r=17); }}} -- Sent from: http://forum.openscad.org/
M
MichaelAtOz
Sat, Aug 15, 2020 6:38 AM

Caddiy wrote

But odd that clockwise rotation is negative?

Right-Hand-Rule
http://forum.openscad.org/file/t359/220px-Right-hand_grip_rule.png


OpenSCAD Admin - email* me if you need anything,  or if I've done something stupid...

  • on the Forum, click on my MichaelAtOz label, there is a link to email me.

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.

--
Sent from: http://forum.openscad.org/

Caddiy wrote > But odd that clockwise rotation is negative? Right-Hand-Rule <http://forum.openscad.org/file/t359/220px-Right-hand_grip_rule.png> ----- OpenSCAD Admin - email* me if you need anything, or if I've done something stupid... * on the Forum, click on my MichaelAtOz label, there is a link to email me. 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. -- Sent from: http://forum.openscad.org/