# Jan 26, 2014

• Roger Clark
Hi I'm a complete noob to OpenJSCad but am quite familiar with OpenSCad.

Anyway, can someone explain to me why I can't use 2D primitives like Circle with solidFromSlices

e.g. This demo generates a polygon inside the callback

var thing = flatBottom.solidFromSlices({
numslices: height
,callback: function(t) {
var coef = t;
var h = height * t;
return CSG.Polygon.createFromPoints([
[-radius, -radius, h],
[radius, -radius, h],
[radius * coef, radius, h],
[-radius * coef, radius, h]
]).rotate([0,0,0], [0,0,1], 0);
}
});

and it works fine

but I can't replace the

CSG.Polygon.createFromPoints([
[-radius, -radius, h],
[radius, -radius, h],
[radius * coef, radius, h],
[-radius * coef, radius, h]
]).rotate([0,0,0], [0,0,1], 0);

with
CAG.circle({center: [0,0], radius: 20, resolution: 50});

well, if I do, I don't get anything in the render

I actually want to dynamically create each slice based on an algorithm, but I prefer to understand the basics before attempting anything complex

• Roger Clark
Thanks Eduard for the link to the voronoi sphere

I've been looking at stuff like http://toxiclibs.org/2011/12/metworks-workshop-facade/
and also Radiolarians
e.g.
http://i.materialise.com/gallery/radiolarian-lamp

which can be generated proceduarlly

• Roger Clark's profile photo
Roger Clark
Thanks Eduard

Sorry about the typo on CAG.Circle rather than CSG.Circle

OK about slices not all needing to be in the same XY (etc) plane.

Re: Difference 2 shapes created by solidFromSlices

I was just coming to that conclusion myself

Currently I'm still trying to work out the correct tools for the job, as I want to create organic looking shapes, so was hoping to build them from procedural generated shapes, which includes having holes in them.

I was going to use OpenSCAD, but it doesnt let you get at the mesh and also doesn't do smoothing AFIK.

I've also looked at "Processing" the Java based IDE system that has a lot of 3D libraries.

But I'm still not sure which system is most applicable.

In terms of using OpenJSCad I think I'll have ago at unioning some slices (of objects with holes in them)

Thanks

Roger

• Roger Clark
Thanks Eduard

What I'd actually like to do is create a polygon with a hollow center, i.e tube in cross section.

Then create an object by lofting the tube down a path, which is basically what solidfromslices does.

However I'm not entirely sure how to create the slices like this.

I was initially hoping I could do it by taking a large circle and subtracting a small circle from inside it, to form the tube like cross section, but solidfromslices doesn't seem to accept a ploygon other than one made of distinct points e.g. using CSG.Polygon.createFromPoints

I'm going to download the source code for openjscad and look at the class heirarchy to work out why solidfromslices accepts a poly created with CSG.Polygon.createFromPoints and not from CSG.Circle

Perhaps there is a CSG.Circle.getPolygon etc, however I've not come across any API docs that list all the methods on all objects
Do you know if full API docs exist ??

Thanks

Roger

• Roger Clark
Thanks Eduard

I took another look in my code and there was a bug in the for loop that generated the points.

It now works OK.

Its just a hacked version of the "three to four" example (I've pasted the code below)

What I was hoping to do was to generate much more complex slices, based no normal 2D primitives, and use union and subtraction etc,
but as even the basic circle, doesn't seem to work, its going to be a load of extra coding if I have to do everything at the vertex level in the code, (and beyond my math's ability

// title: Three to four (sides)
// author: Eduard Bespalov
// license: MIT License
// description: testing solidFromSlices()

function getParameterDefinitions() {
return [
{ name: 'radius', caption: 'Radius:', type: 'float', default: 10 },
{ name: 'height', caption: 'Height:', type: 'float', default: 35 },
{ name: 'twist', caption: 'Twist:', type: 'int', default: 90}
];
}

function main(params) {
var thing = thingTwisted(params.radius, params.height, params.twist);
return thing;
}

function thingTwisted(radius, height, twistangle) {
twistangle = twistangle || 0;

``````    var flatBottom = CSG.Polygon.createFromPoints([
[-radius, -radius, 0],
[radius, -radius, 0],
[radius, radius, 0]
]);

var glob=3;// hack to see if we can change the number of points per slice
var thing = flatBottom.solidFromSlices({
numslices: height
,callback: function(t) {
var coef = t;
var h = height * t;

var circ = [];
var circ2 = [];
for(var i=0;i<2*Math.PI;i+=Math.PI/Math.floor(glob))
{
circ.push([Math.sin(i)*10,Math.cos(i)*10,h]);
circ2.push([Math.sin(i)*9,Math.cos(i)*9,h]);

}
glob+=1;//0.5;
/* NOT USED
var retval1=CSG.Polygon.createFromPoints([
[-radius, -radius, h],
[radius, -radius, h],
[radius * coef, radius, h],
[-radius * coef, radius, h]
]);
*/

retval = CSG.Polygon.createFromPoints( circ);

//DOESNT WORK --  retval = CAG.circle({center: [0,0], radius: 3, resolution: 32}).translate([0,0,h]);// Doesnt work

return retval;
}
``````

});
return thing;
}

• Roger Clark
Thanks Derrick,

It works if I generate the polygon of a circle in code e.g using sin and cos.

I've not looked at the class hierarchy but I presumed that circle was a type of polygon, so I couldn't see why it wouldn't work, but perhaps its not.

I was also hoping that each slice didn't need to have the same number of vertices, but if I change the number of vertices in each slice, it doesn't work either

To be honest, it looks like openscad isn't suited for what I'm trying to achieve, and I may try Processing 3D instead