Close



Page 2 of 8 FirstFirst 1234 ... LastLast
Results 11 to 20 of 72

Hybrid View

  1. #1
    Senior Engineer
    Join Date
    Jun 2014
    Location
    Burnley, UK
    Posts
    1,662
    Sphere r = 6 ; ?????????????????????

    Auto capital, the joys of copy and paste.

    Last edited by Mjolinor; 11-30-2014 at 07:10 AM.

  2. #2
    Staff Engineer old man emu's Avatar
    Join Date
    Oct 2013
    Location
    Narellan, New South Wales, Australia
    Posts
    912
    Quote Originally Posted by Mjolinor View Post
    Sphere r = 6 ; ????????????????????? Auto capital, the joys of copy and paste.
    Fixed that now for you Mj. Sorry, but after working on that post and fighting with Word until late in the night, I missed proof reading. Things would have been better if I could have uploaded a 45Kb *.doc file and not been limited to 19 Kb.

    What I did was to open OpenScad and copy and pasted a small section of the code for the chess piece (made sure it had all the punctuation marks used by OpenScad) then used <cut> to remove bits to see what would happen. I spent a lot of time trying to figure out why 20 * cos(30) and 30 + 20* sin (30) were used. That's just a way to come up with a number for a co-ordinate. More about that in another post.

    I think that you are like me. Give me someone else's big wall of code and I'm stopped, but if I have he chance to examine the bricks, I can see how they are laid together and then can make my my own wall.

    CA, Too much! Too much! My purpose was to explain the ultimate basics of the code for beginners. The very first line of your code has an unexplained term $fn=100. Having to read what I did to write my bit on punctuation, I came across that term and I understand what it means, but think about Mj. Does he? Please remember KISS at this stage.

    Old Man Emu

  3. #3
    Super Moderator curious aardvark's Avatar
    Join Date
    Jul 2014
    Posts
    8,818

    Few simple tips that became quick tutorial on the HULL command :-)

    Great idea emu :-)

    In the tips side of the equation.
    1) use diameter NOT radius. ie: cylinder(d=10,h=5);

    several reasons. 1) it's much easier to visualise if you don't have to keep doubling the radius in your head.
    2) makes calculations much easier when you don't have to double everything.
    Example: a sphere with a radius of 6mm is actually 12mm across. So why not just use d=12 and never have to worry about how big it is.

    2) the hull command.

    This is a brilliant command and answers a lot of questions. Like: how do i make a wedge ? Can i make non equalatrial triangles. And 'how on earth do I make an irregular shape without having to try and under stand the polygon command' ?

    Okay lets use a real world example of a model rocket.
    The cylinder is easy and the pointy top is just another cylinder with different starting and finishing diameters.

    $fn=100;
    cylinder (d=20,h=40);
    translate([0,0,40]) cylinder(d1=20, d2=1, h=20);

    This gives you the basic rocket trunk - I like round things to be round and we're not going to get complicated here, so facets = 100: is set as a global variable.


    Now to make fins you could make a thin cube, then make another cube the same size and rotate and translate it in a difference command to remove half the cube and leave a triangle. Or you could set a cylinder to have 3 facets and then stretch it. Both of which are unnecessarily complicated
    OR

    You can do this:

    //making rocket fin

    hull() {
    translate([-1,0,0]) cube([2,25,0.1]);

    translate([-1,0,40]) cube([1.5,0.1,0.1]);

    } //end of hull command


    So we're drawing a long thin cube that sticks out from the bottom of the rocket. Then we're drawing a small cube further up the rocket.
    Pretty useless so far. But then we tell opesncad to form a shape or HULL between the two cubes and viola, we have a fin.



    We can then duplicate and rotate this to make more fins:

    //second fin
    rotate([0,0,120]) {
    hull() {
    translate([-1,0,0]) cube([2,25,0.1]);
    translate([-1,0,40]) cube([1.5,0.1,0.1]);
    }
    } //end of rotate


    //third fin
    rotate([0,0,240]) {
    hull() {
    translate([-1,0,0]) cube([2,25,0.1]);
    translate([-1,0,40]) cube([1.5,0.1,0.1]);
    }
    } //end of rotate


    we now have: a solid rocket with 3 fins:


    All that's left is to remove a hole for the rocket motor.
    Now because I don't do elegant, I can't just remove a cylinder from the rocket centre. Because that would leave the fins behind in the hole.
    So what I'm going to do is stitch everything together with a union command (openscad's equivalent of duct tape)
    And then I can remove a hole for the motor from the entire rocket:

    Which gives the finished rocket:

    $fn=100;

    difference() { //removes cylinder from entire ducttaped model

    union() {
    cylinder (d=20,h=40);
    translate([0,0,40]) cylinder(d1=20, d2=1, h=20);

    hull() {
    translate([-1,0,0]) cube([2,25,0.1]);
    translate([-1,0,40]) cube([1.5,0.1,0.1]);
    }

    //second fin
    rotate([0,0,120]) {
    hull() {
    translate([-1,0,0]) cube([2,25,0.1]);
    translate([-1,0,40]) cube([1.5,0.1,0.1]);
    }
    } //end of rotate


    //third fin
    rotate([0,0,240]) {
    hull() {
    translate([-1,0,0]) cube([2,25,0.1]);
    translate([-1,0,40]) cube([1.5,0.1,0.1]);
    }
    } //end of rotate
    } //end of union to stitch the whole model together

    cylinder (d=16,h=38); //removes hole for rocket motor
    } //end of difference to remove hole for motor





    Now this is all well and good and gives a conventional rocket with straight fins.
    But say you want to give a little slant to your fins to spin the rocket.
    You could piss about with rotate and rotate the fins on another axis. Or you could simply move the top cube:

    hull() {
    translate([-1,0,0]) cube([2,25,0.1]);
    translate([-5,0,40]) cube([1.5,0.1,0.1]);
    }
    Change the fin code so that the top cube is moved an extra 4mm to the right and you end up with this:

    Last edited by curious aardvark; 11-30-2014 at 12:40 PM.

  4. #4
    Staff Engineer old man emu's Avatar
    Join Date
    Oct 2013
    Location
    Narellan, New South Wales, Australia
    Posts
    912
    CA,
    What I'm trying to do is illustrate the very basic things that have to be looked for when writing some code. That's why I paid more attention to brackets, braces, semi-colons and such. The cheat sheet is not very good at illustrating how things have to be written. http://www.openscad.org/cheatsheet/index.html

    Take the section presenting Special Variables down on the bottom right. It informs us that the group $f is the number of fragments. The comment in your code,
    $fn=100; //defines the number of facets for round or spherical shapes. 100 gives you the roundest thing. is nearly one hundred per cent but you have to tell people that without the semi-colon ";" it doesn't work. It's those seemingly trivial things that put up barriers for people without a programming background.

    While we are on it, nowhere does the manual tell you that the Transformations have to be coded before the object the operate upon.

    Another barrier I found tonight was with the Transformation color (apart from the misspelling). It is not clear from the cheat sheet that the name of the colour to be used has to be between double quotation marks. And further on the same Transformation, there is nothing to tell you that the opacity of the colour can be modified by adding a decimal number between 0 and 1. See what happens when you run this:

    // THE BASE
    // The base will be drawn with distances measured from the Origin (0,0,0)
    // I do not like the default colour. I am going to change it to blue using
    // color("..") and if the colour is too dark, I'll reduce the opacity by adding a
    // decimal value between 0 and 1. Don't forget the double quotation marks, but no semi-colon. color() needs something to act upon so it is written before the
    // thing it is operating on.

    color("lightblue", 0.4)
    cube([64,64,19]);

    OME
    Last edited by old man emu; 12-01-2014 at 04:30 PM.

  5. #5
    Super Moderator curious aardvark's Avatar
    Join Date
    Jul 2014
    Posts
    8,818

    rocket and HULL tips part the second



    Finished code:

    $fn=100;

    difference() { //removes cylinder from entire ducttaped model


    union() {
    cylinder (d=20,h=40);
    translate([0,0,40]) cylinder(d1=20, d2=1, h=20);


    hull() {
    translate([-1,0,0]) cube([2,25,0.1]);
    translate([-5,0,40]) cube([1.5,0.1,0.1]);
    }


    //second fin
    rotate([0,0,120]) {
    hull() {
    translate([-1,0,0]) cube([2,25,0.1]);
    translate([-5,0,40]) cube([1.5,0.1,0.1]);
    }
    } //end of rotate


    //third fin
    rotate([0,0,240]) {
    hull() {
    translate([-1,0,0]) cube([2,25,0.1]);
    translate([-5,0,40]) cube([1.5,0.1,0.1]);
    }
    } //end of rotate
    } //end of union to stitch the whole model together
    cylinder (d=16,h=38); //removes hole for rocket motor
    } //end of difference to remove hole for motor

    Now to make this more elegant we could do a number of things. Make the rocket fin a module. Add variables for rocket height, diameter, notor chamber size and fin offset.

    But that's not necessary if we just want one rocket once :-)

    You'll notice I add comments to the } brackets so that I have some idea what the bloody things are for.
    Good habit to get into.

    The hull command can be used to make pretty much any shape you like. Have a play :-)

  6. #6
    Senior Engineer
    Join Date
    Jun 2014
    Location
    Burnley, UK
    Posts
    1,662
    Like I said earlier, it's damned hard to learn. I don't get anything like what you have even just copying and pasting it.

  7. #7
    Super Moderator curious aardvark's Avatar
    Join Date
    Jul 2014
    Posts
    8,818
    I just copied and pasted the final script - works for me. Also here's the actual .scad file
    finned-rocket.scad

    As far as hard to learn. It really helps if you have good 3d visualisation. I can pretty much look at anything and break it down into shapes. Plus while I have absolutely no artistic ability when it comes to drawing stuff, I can visualise pretty much anything in my head and then use opesncad to make it.

    For me it's immensely easier to use than a mouse based cad package.

    We are all different :-)

    And once you learn to simply type the brackets automatically and write a few basic scripts - you'll be surprised how quickly you start to model pretty complicated things.

  8. #8
    Senior Engineer
    Join Date
    Jun 2014
    Location
    Burnley, UK
    Posts
    1,662
    Here is what I get.
    Attached Images Attached Images

  9. #9
    Staff Engineer old man emu's Avatar
    Join Date
    Oct 2013
    Location
    Narellan, New South Wales, Australia
    Posts
    912
    CA,
    I agree with you that color("colorname", [<0 n > 1 is as useless as a hip pocket in a singlet except under very rare circumstances. I just quoted it as an example of how the producers of the documentation jumped from Coding 101 to Coding 105, leaving those of us with learning difficulties floundering.

    What people like me need is more attention being paid to those things that programmers take for granted. As I have been working on this thread, and playing with OpenScad, I've picked up these basics, but it's been a couple of months since Roxy suggested that OpenScad was a better program than, say Rhino for the hobbyist. If these very, very basic facts had been presented to me way back then, I'd be creating the Millennium Falcon by now. I'm quickly finding out that OpenScad is easy enough to use. It will be better when I can see how to do in it what I can do in Rhino (which is not much, actually)

    OME

  10. #10
    Super Moderator curious aardvark's Avatar
    Join Date
    Jul 2014
    Posts
    8,818
    you missed the first part of the script - load the .scad file or copy and paste the final script.

    Okay another tip:

    Don't forget that openscad is text based - so you can use normal text tools.
    I used copy and paste in the above script.
    But say you haven't made fins a module (which i didn't), but want to change all three at once.
    Click edit and select Find and Replace.
    Then put -5 in the find box and -7 in the replace box. Hit all and f5.
    And the angle of all three fins changes.

    Admittedly this only works if you haven't used a -5 anywhere else.
    But it's surprising how useful it can be.

    replacecommandopenscad.jpg

    The script and tutorial posts have taken me just over a hour. Only about 10 minutes of that was writing the script.
    I could not have done this in a gui cad package in anything close to that time scale. Assuming I could actually get a cad package to do anything that's included in a tutorial, which given all the bloody versions there are of most cad packages, is unlikely.
    Last edited by curious aardvark; 11-30-2014 at 01:06 PM.

Page 2 of 8 FirstFirst 1234 ... LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •