I'm trying to work this problem out and I've lost my way. Any help ?
input is a list of lists of perimeters (originally from inkscape) like this:
shape = [
[[-5.493165,6.432500],[-5.493165,-6.476440],[-5.152585,-7.322380],[-4.317625,-7.673950],[-0.659175,-7.673950],
[1.373295,-7.391052],[2.922365,-6.542360],[3.952333,-5.191037],[4.295655,-3.378290],[4.139100,-2.309872],
[3.669435,-1.345820],[3.427735,-1.071160],[3.175055,-0.785520],[4.141845,-0.115350],[5.141605,1.235960],
[5.493165,2.818000],[5.199280,4.309393],[4.317625,5.553590],[3.249208,6.330878],[1.801755,6.948860],
[-1.010745,7.542120],[-3.537595,7.673950],[-4.010005,7.673950],[-4.317625,7.651950],[-5.152585,7.300390],
[-5.493165,6.432470]],
[[-3.153075,5.245970],[-1.285395,5.125130],[0.878905,4.707640],[1.933595,4.323120],[2.680665,3.828740],
[3.153075,2.818000],[2.889405,1.906130],[2.109375,1.257940],[1.109625,0.939330],[-0.109865,0.807500],
[-3.153075,0.807500],[-3.153075,5.245970]],
[[-3.153075,-1.576540],[-0.988765,-1.576540],[0.164795,-1.697380],[1.098635,-2.005000],
[1.741332,-2.573543],[1.955565,-3.378290],[1.527105,-4.608760],[0.678410,-5.097655],[-0.659175,-5.267940],
[-3.153075,-5.267940],[-3.153075,-1.576540]]
];
Its a capital B. (Outer perim and two inner holes).
The polygon statement needs this in one long list and three paths (last two
in correct winding order).
I'm trying to make a function to return that.
Currently jammed up on the simplest possible thing. Concat all the lists
together.
all_points = concat(shape); // does not work.
all_points = concat([for (i=[0:len(shape)-1]) shape[i]]); // nope
I'm reluctant to build a recursive - I thought it'd be easier than that...
Any suggestions...? I think I need sleep :(
--
View this message in context: http://forum.openscad.org/polygon-with-paths-from-Inkscape-list-tp13424.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
is this what you want?
shape =
[[-5.493165,6.432500],[-5.493165,-6.476440],[-5.152585,-7.322380],[-4.317625,-7.673950],[-0.659175,-7.673950],
[1.373295,-7.391052],[2.922365,-6.542360],[3.952333,-5.191037],[4.295655,-3.378290],[4.139100,-2.309872],
[3.669435,-1.345820],[3.427735,-1.071160],[3.175055,-0.785520],[4.141845,-0.115350],[5.141605,1.235960],
[5.493165,2.818000],[5.199280,4.309393],[4.317625,5.553590],[3.249208,6.330878],[1.801755,6.948860],
[-1.010745,7.542120],[-3.537595,7.673950],[-4.010005,7.673950],[-4.317625,7.651950],[-5.152585,7.300390],
[-5.493165,6.432470],
[-3.153075,5.245970],[-1.285395,5.125130],[0.878905,4.707640],[1.933595,4.323120],[2.680665,3.828740],
[3.153075,2.818000],[2.889405,1.906130],[2.109375,1.257940],[1.109625,0.939330],[-0.109865,0.807500],
[-3.153075,0.807500],[-3.153075,5.245970],
[-3.153075,-1.576540],[-0.988765,-1.576540],[0.164795,-1.697380],[1.098635,-2.005000],
[1.741332,-2.573543],[1.955565,-3.378290],[1.527105,-4.608760],[0.678410,-5.097655],[-0.659175,-5.267940],
[-3.153075,-5.267940],[-3.153075,-1.576540]]
;
polygon(points=shape);
Jerry
--
Extra Ham Operator: K7AZJ
Registered Linux User: 275424
Raspberry Pi and Arduino developer
The most exciting phrase to hear in science - the one that heralds new
discoveries - is not "Eureka!" but "That's funny...".- Isaac. Asimov
I
*f you give someone a program, you will frustrate them for a day; if you
teach them how to program, you will frustrate them for a lifetime. *-
Anonymous
If writing good code requires very little comments, then writing really
excellent code requires no comments at all!- Ken Thompson
I believe this is what you need:
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/List_Comprehensions#Flatten_a_nested_list
$ Runsun Pan, PhD
$ -- libs: doctest , faces ( git ), offliner ( git );
tips: hash( 1 , 2 ), sweep , var
$ -- Linux Mint 17.1 Rebecca x64 + OpenSCAD 2015.03.15/2015.04.01.nightly
--
View this message in context: http://forum.openscad.org/polygon-with-paths-from-Inkscape-list-tp13424p13426.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Thanks guys, yes flattening does of course do it perfectly.
Now I need to move to the next step and reindex the three paths. The picture
above shows why the three paths can't be simply appended and I must use the
alternative form of Polygon (with paths) to cut holes in a single polygon.
Cheers and thanks for the help. sigh.. flatten.. sigh...
--
View this message in context: http://forum.openscad.org/polygon-with-paths-from-Inkscape-list-tp13424p13427.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
end result - in case anyone's interested is the unoptimised following:
// used by composite_shape
function flatten(list) = [ for (a = list) for (b = a) b ];
function reindex(list, start) = [for (i=[start:start+len(list)-1]) i];
function new_start(list, index) = len(flatten( [for (i=[0 : index-1])
list[i]] )); // don't care about index=0
module composite_shape(polygon_list) {
if (len(flatten(polygon_list)) <= 2 * len(polygon_list)) // is it a nested
shape.
// no its a sinple polygon
polygon(polygon_list);
else { // its a nested shape
// append all the points in all the lists
// make paths sequences to add to polygon with paths syntax.
all_points = flatten(polygon_list);
all_paths = [for (i=[0:len(polygon_list)-1]) reindex(polygon_list[i], i==0
? 0 : new_start(polygon_list, i))];
polygon(all_points, all_paths);
}
}
--
View this message in context: http://forum.openscad.org/polygon-with-paths-from-Inkscape-list-tp13424p13428.html
Sent from the OpenSCAD mailing list archive at Nabble.com.