# how can i create a polygon that would encompass all this shapes?

Posted by emaayan
 how can i create a polygon that would encompass all this shapes? February 11, 2018 03:01PM Registered: 1 year ago Posts: 16
consider the following file..

is there anyway i can somehow create a polygon based on the manArr variable, that would encompass all the cylinders, without cutting through them?

so far the only way i think of is doing somehow a recursive function, but opensCad's restrictions on functions to be one line is driving me insane..
 Re: how can i create a polygon that would encompass all this shapes? February 11, 2018 03:32PM Registered: 5 years ago Posts: 14,150
Is the hull() function any use to you?

Large delta printer [miscsolutions.wordpress.com], Robotdigg SCARA printer, Crane Quad and Ormerod

Disclosure: I design Duet electronics and work on RepRapFirmware, [duet3d.com].
 Re: how can i create a polygon that would encompass all this shapes? February 11, 2018 04:31PM Registered: 1 year ago Posts: 16
it certainly does , now if i could just offset, but i'm guessing i'm gonna have to re-do the function that creates the cells, to use circles and not cylinders so the hull would be 2d..
 Re: how can i create a polygon that would encompass all this shapes? February 11, 2018 10:27PM Registered: 4 years ago Posts: 904
OpenScad has an offset function: [en.wikibooks.org]

The Help menu links to a "Cheat Sheet", which is a great help for finding out what is available.
 Re: how can i create a polygon that would encompass all this shapes? February 12, 2018 01:54AM Registered: 4 years ago Posts: 556
Quote
emaayan
it certainly does , now if i could just offset, but i'm guessing i'm gonna have to re-do the function that creates the cells, to use circles and not cylinders so the hull would be 2d..

You could also use projection() to project the hull into a 2D-polygon.
 Re: how can i create a polygon that would encompass all this shapes? February 12, 2018 02:00AM Registered: 1 year ago Posts: 16
i have the cheet sheet bookmarked in my browser, doesn't mean i always understand it ...

isn't the projection involves creating external files first?
 Re: how can i create a polygon that would encompass all this shapes? February 12, 2018 08:09AM Registered: 4 years ago Posts: 556
Quote
emaayan
isn't the projection involves creating external files first?

No, it will project whatever object follows, so e.g. "projection()cylinder(r=10,h=5);" will create a circle.
 Re: how can i create a polygon that would encompass all this shapes? February 13, 2018 03:01AM Registered: 1 year ago Posts: 16
so this is my new use of hull and projection
 Re: how can i create a polygon that would encompass all this shapes? February 13, 2018 10:47AM Registered: 1 year ago Posts: 16
hi.. the hull method did helped, but it also helped to know what i want, in terms of terminology,

what i'm REALLY looking for is CONCAVE hull, i want the hull to be minimal , and not a Convex one, i've been trying to see if anyone wrote a library for it... but i'm not sure..

Quote
enif
Quote
emaayan
it certainly does , now if i could just offset, but i'm guessing i'm gonna have to re-do the function that creates the cells, to use circles and not cylinders so the hull would be 2d..

You could also use projection() to project the hull into a 2D-polygon.
 Re: how can i create a polygon that would encompass all this shapes? February 13, 2018 01:36PM Registered: 4 years ago Posts: 556
As far as I understand there is no such thing as a "concave hull", as this would degenerate essentially to the union with a tiny connection tree between the loose parts. But maybe what you could use is the union of the convex hulls of smaller subsets, e.g. of the straight rows of cylinders, in order to get a closer "shell" around the cells.
 Re: how can i create a polygon that would encompass all this shapes? February 13, 2018 02:14PM Registered: 1 year ago Posts: 16
you mean hull each shape on it's own instead of the whole thing?

how about doing it as a module, the hull would be created bu doing a hexagon, and subtract it from the real shapes:

translate([0,0,holderActuallHeight]){
drawHoles(manArr){

translate([0,0,0]){
if (hullIt){
rotate([0,0,30]){
circle(d=(cellDiameter*3/2),\$fn=6);
}
}else{

translate([0,0,-stripZ]){
cylinder(d=cellDiameter,h=holderHeight+0.3);
}

actuallstripWidth= stripWidth;
actuallStripLength=stripLength+0.001;
square([actuallStripLength,actuallstripWidth],center=true);

rotate(angle){
square([actuallStripLength,actuallstripWidth],center=true);
}

rotate(angle*2){
square([actuallStripLength,actuallstripWidth],center=true);
}
}
}

};

}

seems it was requested already [github.com]
 Re: how can i create a polygon that would encompass all this shapes? February 14, 2018 05:51AM Registered: 4 years ago Posts: 556
Yes, the idea of combining the shell from outer hexagons seems nice...

As for your code itself, I admit that I have not tried understand it completely. I do like the idea with the drawHoles() iterator. However,
do you know that if you use variables starting with \$ (e.g. \$col, \$row)they can be accessed by the children(). This would allow you to make a much leaner iterator and access e.g. the cell position and contents of the corresponding manArr entry inside the child code.
With drawHoles() being a simple iterator you could easily split the problem into components like outer shell, inner cavity, cell cylinders, etc.

The following is just to illustrate the idea:
```// cell configuration
n=-1; p=1;
simpleOne=[
[p,n,p]
,[p,n,p]
,[p,n,n]
,[p,n]
,[p,n]
,[p]
];

module batterycase(cells,dia=18,len=65,wall=10,wallz=4){

// cell position of cells[r][c]
function cellpos(r,c)=[(2*\$row+(\$col%2)),2*cos30*\$col,0];

// Local module to iterate through all cells
// Variables \$row, \$col are global, so they can be used in all children
module drawHoles(){
for(\$row=[0:len(cells)-1])
for(\$col=[0:len(cells[\$row])-1])
}

// Local module to draw a + or -
module pole(s)
{for(a=[0: (s>0?90:180):359])rotate(a)translate([0,-1,0])cube([4,2,1]);}

cos30 = cos(30);

difference(){
// outer shell
union()drawHoles()
cylinder(r=dia/2+wall,h=len+2*wallz,\$fn=6);
// inner cavity
union() translate([0,0,2*wallz])drawHoles()
rotate(30)cylinder(r=dia/2/cos30+1,h=len-2*wallz,\$fn=6);
// individual cell cylinders
drawHoles(){
// cell cavity
translate([0,0,-0.1]) cylinder(r=dia/2,h=len+2*wall+0.2);
// show polarity on top and bottom
%translate([0,0,2*wallz+len-1])pole(cells[\$row][\$col]);
%translate([0,0,-1])pole(-cells[\$row][\$col]);
// ... and whatever else is needed
}
}
}

batterycase(simpleOne);```

BTW, the idea with the alpha-shape as a kind of parametric "concave hull" is indeed interesting - thanks for mentioning it!
 Re: how can i create a polygon that would encompass all this shapes? February 14, 2018 08:37AM Registered: 1 year ago Posts: 16
actually someone just mentioned this to me, i was looking or something like this, after i saw [github.com] library which initially looked like doing a lof of this things i'm doing .. i knew it would make things simpler this way..

btw my recent changes seems to make scad behave ...weird, something i the rendering doesn't seem right. pressing F6 ,usually shows it ok after, but still...

my original plan was to upload all of this to thingiverse, but i don't think it has a ui. for setting the arrays.

all of this is a compromise, it would be sooo much cooler if instead if could just define a polygon and have it be filled optimally like in here: [e4bike.ru]

but i lack the algorithm chops do it ...so i took the structured way..
Sorry, only registered users may post in this forum.