[OpenSCAD] FIlling gaps between complex hollow objects

Carsten Arnholm arnholm at arnholm.org
Tue Jan 2 15:39:03 EST 2018


On 02. jan. 2018 15:19, Troberg wrote:
> That I agree with. I find it endlessly frustrating that I can't just do
> something like:
> 
> sphere(d=100,name="thissphere");
> 
> and then later, after it's been moved around and all that do a:
> 
> translate([thissphere.x,thissphere.y,thissphere.z])
> cylinder(d=thissphere.d,1000);
> 
> Or, stuff like my parts list. Since variables are kind of wonked compared to
> other languages, I have to echo a line for each part, then copy the echo
> output to another program I wrote which parses it and sums things up.
> 
> I've been thinking a lot about encapsulating the 3D markup in some framework
> in some kind of "real script language", such as VBScript, JavaScript or
> Rexx, but I haven't got around to actually doing anything.

I guess this is the recurring talk about the functional language in 
OpenSCAD. The features you describe imply a procedural language. I have 
had similar ideas regarding use of a scripting language. Your example 
can be expressed as below using my AngelScript* implementation.

*AngelScript is a procedural language with strong types
http://www.angelcode.com/angelscript/sdk/docs/manual/doc_script.html
The @ notation refers to "object handles".

shape@ main_shape()
{
    solid@ sph = translate(200,300,400)*sphere(r:50);
    sphere@ s  = cast<sphere@>(sph);
    pos3d@ c   = s.box().center();
    return translate(c.x(),c.y(),c.z())*
           cylinder(r:s.radius(),h:1000) + s;
}

It may be possible to eliminate the second line to make it more compact, 
but this runs as shown now creating an explicit union of a cylinder and 
the given sphere 's', much like you explained.

The attached OpenSCAD file was generated from the above script.

Carsten Arnholm
-------------- next part --------------
// This file was created using AngelCAD (as_csg) v1.0-04
// Copyright(C) 2015-2018 Carsten Arnholm, http://arnholm.org/ 
// Open it with OpenSCAD for display or further processing 
$fn = 60;
$fa = 6.0;
$fs = 1.0;
group() {
	multmatrix([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]) {
		union() {
			multmatrix([[1,0,0,200],[0,1,0,300],[0,0,1,400],[0,0,0,1]]) {
				cylinder( r1=50, r2=50, h=1000, center=false );
			}
			multmatrix([[1,0,0,200],[0,1,0,300],[0,0,1,400],[0,0,0,1]]) {
				sphere( r=50 );
			}
		}
	}
}


More information about the Discuss mailing list