Is there a better way this could have been done?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Is there a better way this could have been done?

jdawgaz
I have the following snippet.

$fn = 100;

legs() thing();

module legs()
{
  for (i = [0:2]) 
  {
    if (i == 0) 
      translate([sin(360*i/3)*18, cos(360*i/3)*18, 0 ])
       rotate([27.5,0,0]) children();
    if (i == 1) 
      translate([sin(360*i/3)*18, cos(360*i/3)*18, 0 ])
       rotate([-27.5,-27.5,0]) children();
    if (i == 2) 
      translate([sin(360*i/3)*18, cos(360*i/3)*18, 0 ])
       rotate([-27.5,27.5,0]) children();
    
  }
}

module thing()
{
  cylinder(d=4, h=20, center=true); 
  translate([0,0,-10]) sphere(r=3);
}


Other than filling a 3 element array of vectors of the rotate arguments.
Is there a better way to do what I wanted done?

Jerry


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

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


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Is there a better way this could have been done?

nophead
I think this does the same:

module legs()
{
  for (i = [0:2])
     rotate([0, 0, 360 * i / 3])
        translate([0, 18, 0])
            rotate([27.5, 0, 0])
                children();
}

I.e. just place the first leg and then rotate it to three positions.

On 2 November 2016 at 23:15, Jerry Davis <[hidden email]> wrote:
I have the following snippet.

$fn = 100;

legs() thing();

module legs()
{
  for (i = [0:2]) 
  {
    if (i == 0) 
      translate([sin(360*i/3)*18, cos(360*i/3)*18, 0 ])
       rotate([27.5,0,0]) children();
    if (i == 1) 
      translate([sin(360*i/3)*18, cos(360*i/3)*18, 0 ])
       rotate([-27.5,-27.5,0]) children();
    if (i == 2) 
      translate([sin(360*i/3)*18, cos(360*i/3)*18, 0 ])
       rotate([-27.5,27.5,0]) children();
    
  }
}

module thing()
{
  cylinder(d=4, h=20, center=true); 
  translate([0,0,-10]) sphere(r=3);
}


Other than filling a 3 element array of vectors of the rotate arguments.
Is there a better way to do what I wanted done?

Jerry


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

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


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org



_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Is there a better way this could have been done?

Ronaldo
Or if you want it parametric:

legs([0,18,0],[27.5,0]) thing();

module legs(p, rot)
{
  for (i = [0:120:240])  rotate(i) translate(p) rotate(rot) children();
}


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Is there a better way this could have been done?

herdima
In reply to this post by jdawgaz
Jerry, you could reduce the for-loop to this:
 
  for (i = [0:2])
  rotate([0, 0, i*120])
  translate([0, 18, 0 ])
  rotate([27.5, 0, 0])
  children();

Martin


Am 03.11.2016 um 00:15 schrieb Jerry Davis:
I have the following snippet.

$fn = 100;

legs() thing();

module legs()
{
  for (i = [0:2]) 
  {
    if (i == 0) 
      translate([sin(360*i/3)*18, cos(360*i/3)*18, 0 ])
       rotate([27.5,0,0]) children();
    if (i == 1) 
      translate([sin(360*i/3)*18, cos(360*i/3)*18, 0 ])
       rotate([-27.5,-27.5,0]) children();
    if (i == 2) 
      translate([sin(360*i/3)*18, cos(360*i/3)*18, 0 ])
       rotate([-27.5,27.5,0]) children();
    
  }
}

module thing()
{
  cylinder(d=4, h=20, center=true); 
  translate([0,0,-10]) sphere(r=3);
}


Other than filling a 3 element array of vectors of the rotate arguments.
Is there a better way to do what I wanted done?

Jerry


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

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



_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

    

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Is there a better way this could have been done?

jdawgaz
great. thanks for pointing me in the right direction.


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

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


On Wed, Nov 2, 2016 at 5:10 PM, Martin Herdieckerhoff <[hidden email]> wrote:
Jerry, you could reduce the for-loop to this:
 
  for (i = [0:2])
  rotate([0, 0, i*120])
  translate([0, 18, 0 ])
  rotate([27.5, 0, 0])
  children();

Martin



Am 03.11.2016 um 00:15 schrieb Jerry Davis:
I have the following snippet.

$fn = 100;

legs() thing();

module legs()
{
  for (i = [0:2]) 
  {
    if (i == 0) 
      translate([sin(360*i/3)*18, cos(360*i/3)*18, 0 ])
       rotate([27.5,0,0]) children();
    if (i == 1) 
      translate([sin(360*i/3)*18, cos(360*i/3)*18, 0 ])
       rotate([-27.5,-27.5,0]) children();
    if (i == 2) 
      translate([sin(360*i/3)*18, cos(360*i/3)*18, 0 ])
       rotate([-27.5,27.5,0]) children();
    
  }
}

module thing()
{
  cylinder(d=4, h=20, center=true); 
  translate([0,0,-10]) sphere(r=3);
}


Other than filling a 3 element array of vectors of the rotate arguments.
Is there a better way to do what I wanted done?

Jerry


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

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



_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

    

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org



_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org