My constructions involve, among other things cutting sheets of plywood into
odd shapes.
Now, I want to also generate a part list. For square bits, no problem.
However, for a polygon, it's hard to calculate how much I would need. Sure,
I could pretty easily do a couple of projections and hulls to get a square,
but I still wouldn't get the measurements in any meaningful format. It
doesn't have to be exact, the maximum size in each dimension would be plenty
enough for me to not buy too little plywood.
Is there any way of doing that in a generic way, ie, something like a
function that takes a 2D polygon and returns width and height?
--
Sent from: http://forum.openscad.org/
There is no way to get any polygon geometry data with OpenSCAD language
unless you have generated its vertex list.
An alternative is to compute the polygon bounding rectangles, export them
as DXF or SVG, and computing what you need with a Python program.
The bounding rectangle may be computed by:
// the extent of the children projection on x axis
module xExtent()
hull() translate([0,1/2])
projection() rotate([90,0,0])
linear_extrude(1) children();
// the bounding rectangle of children
module boundingRect()
offset(-1/2)
minkowski() {
xExtent() children();
rotate(-90) xExtent() rotate(90) children();
}
// a test shape
module shape() translate([2.5,0]){
rotate(0) square(10,center = true);
rotate(45) square(10,center = true);
}
color("red")
shape();
translate([0,0,0.5])
%boundingRect() shape();
2018-02-12 11:12 GMT-02:00 Troberg troberg.anders@gmail.com:
My constructions involve, among other things cutting sheets of plywood into
odd shapes.
Now, I want to also generate a part list. For square bits, no problem.
However, for a polygon, it's hard to calculate how much I would need. Sure,
I could pretty easily do a couple of projections and hulls to get a square,
but I still wouldn't get the measurements in any meaningful format. It
doesn't have to be exact, the maximum size in each dimension would be
plenty
enough for me to not buy too little plywood.
Is there any way of doing that in a generic way, ie, something like a
function that takes a 2D polygon and returns width and height?
--
Sent from: http://forum.openscad.org/
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
I'm considering handing the polygon coordinate array to a function, then use
min and max to get min and max values in X and Y and simply get the
difference, but without being able to loop the array in a good way, it's
hard to shuffle stuff so all X values are in one array and all Y values in
another. I strongly suspect that would be a very headache-inducing
function...
An alternative is to compute the polygon bounding rectangles, export them
as DXF or SVG, and computing what you need with a Python program.
Except that that would pretty much break everything else around it. This is
a special case, I don't want to break all the normal cases.
--
Sent from: http://forum.openscad.org/
...
, but without being able to loop the array in a good way, it's
hard to shuffle stuff so all X values are in one array and all Y values in
another. I strongly suspect that would be a very headache-inducing
function...
Do you mean that?
function polyBounds(p) =
[ max([for(pi=p) pi[0]]) - min([for(pi=p) pi[0]]) ,
max([for(pi=p) pi[1]]) - min([for(pi=p) pi[1]]) ];
On 12. feb. 2018 14:12, Troberg wrote:
My constructions involve, among other things cutting sheets of plywood into
odd shapes.
Now, I want to also generate a part list. For square bits, no problem.
However, for a polygon, it's hard to calculate how much I would need. Sure,
I could pretty easily do a couple of projections and hulls to get a square,
but I still wouldn't get the measurements in any meaningful format. It
doesn't have to be exact, the maximum size in each dimension would be plenty
enough for me to not buy too little plywood.
Is there any way of doing that in a generic way, ie, something like a
function that takes a 2D polygon and returns width and height?
You can't really do it With a functional language such as OpenSCAD, as
there is no way to query the points of a polygon.
In another language it could be done by incrementally rotating the
polygon and then compute the bounding box of the rotated polygon points.
The optimal rotation corresponds to the smallest bounding box area, and
the dimensions of the bounding box corresponds defines the smallest
usable plywood sheet.
Carsten Arnholm
Do you mean that?
Something like that, but I keep getting syntax error on it. Very neat,
though!
--
Sent from: http://forum.openscad.org/
In another language it could be done by incrementally rotating the
polygon and then compute the bounding box of the rotated polygon points.
The optimal rotation corresponds to the smallest bounding box area, and
the dimensions of the bounding box corresponds defines the smallest
usable plywood sheet.
It doesn't have to be the smallest box, I just want to make sure I have
enough material. Some waste is OK, and can be used in the next build. So,
some rough ballpark figure that isn't too small is good enough.
--
Sent from: http://forum.openscad.org/