Results 11 to 20 of 71
Thread: OpenScad Help Centre
-
11-30-2014, 06:58 AM #11
- 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.
-
11-30-2014, 12:25 PM #12
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.
-
11-30-2014, 12:31 PM #13
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
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 :-)
-
11-30-2014, 12:39 PM #14
- 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.
-
11-30-2014, 12:43 PM #15
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.
-
11-30-2014, 12:49 PM #16
- Join Date
- Jun 2014
- Location
- Burnley, UK
- Posts
- 1,662
Here is what I get.
-
11-30-2014, 12:58 PM #17
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.
-
11-30-2014, 01:05 PM #18
- Join Date
- Jun 2014
- Location
- Burnley, UK
- Posts
- 1,662
This is what I have in finned-rocket.scad taken from gedit.
$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 motorLast edited by Mjolinor; 11-30-2014 at 01:24 PM.
-
11-30-2014, 03:11 PM #19
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
-
12-01-2014, 06:07 AM #20
yep and below you can find the FULLY annotated script. Hopefully that should make everything clear. :-)
//Curious aardvark's fully annotated basic model rocket script - with added vitamin HULL !
$fn=100; //defines the number of facets for round or spherical shapes. 100 gives you the roundest things. I tend to put this at the top of all my scripts. If you want to speed up rendering drop it to 50 or 75. just remember to change it back to 100 before the final f6 render. Unless of course you want a more angular shape.
difference() { //removes cylinder from entire ducttaped model. Although this is at the start of the script, it was added last.
union() { //ducttapes the rocket body and fins together as one shape
cylinder (d=20,h=40); //creates the main cylinder of the rocket's body: diameter 20mm height 40mm
translate([0,0,40]) cylinder(d1=20, d2=1, h=20); //adds the pointy top to the rocket body. translate starts the cylinder 40mm up so it sits on top of the body. Height of point is 20mm. Base diameter is 20 and top diameter is 1mm to make the cone shape. Cones slope iorm the first diameter to the second. Inwards if the second diameter is smaller then the first and outwards if it's larger.
//creates first fin
hull() { //wraps a shell around the the two rectangles to create a tringular fin shape. the width of the rectangle creates the thickness of the fin
translate([-1,0,0]) cube([2,25,0.1]); //sticks a long thin rectangle out from the base of the rocket to create the long base of the fin
translate([-5,0,40]) cube([1.5,0.1,0.1]); //places a small rectangle at the top of the rocket to create the top of the fin
} // indicates the end of the hull command
//second fin - code was simply copied and pasted to make a second fin and a rotate commad added to, well rotate the fin.
rotate([0,0,120]) { //rotates second fin 120 degrees (3 fins: 360/3 = 120 degree rotation to get evenly spaced fins
hull() { //wraps shell round rectangles
translate([-1,0,0]) cube([2,25,0.1]); //bottom rectangle
translate([-5,0,40]) cube([1.5,0.1,0.1]); //top rectangle
} //end of hull command
} //end of rotate
//third fin - see above :-)
rotate([0,0,240]) { //rotated 240 degrees
hull() {
translate([-1,0,0]) cube([2,25,0.1]);
translate([-5,0,40]) cube([1.5,0.1,0.1]);
} //end of hull
} //end of rotate
} //end of union to stitch the whole model together
cylinder (d=16,h=38); // removes a smaller cylinder from the ducttaped (unioned) model for insertion of a rocket motor - I have no idea how big these actually are - this script is currently just for tutorial purposes. Removed cylinder is 16mm in diameter to give a wall thickness of 2mm. And 38mm in height to give a solid 2mm before the start of the cone. probably not actually necessary. But I'm a belt and braces kind of designer.
} //end of difference to remove hole for motor
Think of it as using childs building blocks. I stacked a cone on top of a hollow cylinder and then leant three triangles against it.
Future rocket scripts will demonstrate modules and loop commands and variables and scaling and resize - just not in that order :-)
Not to mention adding text to the rocket - I've got an easy way to change fonts used with writescad.
And as I learn more stuff (there are a whole bunch of commands I haven't used yet) I'll add more bits to it. Also bear in mind that while I can do arithmitic - I have bugger all higher maths (took the courses - just never really understood them).
So you can pretty much guarentee that my scripts will not have 'cos' or 'tan' or anything of that nature - as I have absolutely no idea what they are or how they work :-)
The beauty of openscad is that you can make the same model any number of ways. You really don't need to understand complicated maths. Otherwise I wouldn't be able to use it :-)
@Mjoilnir - what os and version of openscad are you using ?
One thing I would recommend to print out and keep to hand is the 'cheat' sheet.
http://www.openscad.org/cheatsheet/index.html
It helps keep the different syntax for the various commands clear.
I can also use this model to explain 'my' design process in very simple steps.
Probably should have done that first, right ?
Just thought an actual design would be a good place to start.
lolLast edited by curious aardvark; 12-01-2014 at 09:48 AM.
Ender 3v2 poor printing quality
10-28-2024, 09:08 AM in Tips, Tricks and Tech Help