Wednesday, 15 February 2017

More on OpenSCAD

This is a bit more on OpenSCAD, using the Valentine's heart as an example. This time, the "nub" which constrains the movement - you can turn the heart 180 degrees. When in a heart shape the lids are locked together. When in a lozenge shape the lids won't open. That is because of a small nub each side.

We have some variables, nubd1, nubd2, nub which are the diameters and height of a conic shape. The $fn means the surface is quite smooth. I'll explain "w" later.

It looks like this...
We actually stick this on a surface, and it is a good idea to have a base in to the surface, especially if the surface may not be flat, as you'll see. So lets add a base and make it a module.

Now it looks like this...
So lets stick it on the side of the heart, like this...

We'll put one both sides, and have it go in to a "track" on the other side. This means these nubs have to be slightly offset else the simply hit each other. But how do we make the track?

Well, an obvious thing to do is use the rotate_extrude function, but that works on a 2D outline, not a 3D shape as we have, so we can use projection...

Which looks like

Now we can rotate it.

We can cut that in to the side of the heart using difference, but it is exactly the same size as the nub, and that is where "w" comes in - it is an extra width to add to the nub, meaning we can make a slightly wider track.

But we only want the track to be 180 degrees. Sadly rotate_extrude does not have an angle limit until a later version of OpenSCAD, so we can cut it in half using difference and a cube.

The edges end up rather harsh, and actually the nub will not manage a whole 180 degrees like that, so let's add a nub shaped hole at each end as well. The "right" argument is used to tell the module which side we are working on, as each side is slightly different.

If you are watching closely you will see I have used a different function nub() not nubshape()... Well, that is because I want the nub itself to be slightly different - I want it to be wider so it is stronger.

I want to stretch the nub within the track, rotate it a bit - but again, rotate_extrude does not have angle yet, so I have actually just made two hull sections with a few degrees rotation. It comes out like this...

And, of course, as I use nub() for ends of the track/hole as well it makes sure the track is the right length as well.

And that is just one of the small details in the code for the heart box...

No comments:

Post a Comment