Nabble has removed Mailing-list integration.
Posts created here DO NOT GET SENT TO THE MAILING LIST.
Mailing-list emails DO NOT GET POSTED TO THE FORUM.
So basically the Forum is now out of date, we are looking into migrating the history.
Really liking the programmatic style of OpenSCAD.
But it does pose some challenges. If I make a cube: cube([x, y, z], false); Given thee points: p1 = [x1, y1, z1]; p2 = [x2, y2, z2]; p3 = [x3, y3, z3]; that define a plane. I'd like to chop the cube with that plane (everything above that plane, i.e. z > z_plane). Clearly one way to do this is is to create another cube, somewhat bigger perhaps, rotate it, translate it and then use it in a difference. The specifics are challenging. Has anyone any tips here or code already written? For example to define a cube with specified dimensions whose base contains the three points? That would be a gem! -- Sent from: http://forum.openscad.org/ _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
Off the top of my head, given p1, p2, p3, and a size s that is the size of the largest axis of the part to mask:
``` v1 = p2 - p1; v2 = p3 - p1; n = cross(v1,v2); n2 = n / norm(n); cp = (p1 + p2 + p3) / 3; axis = cross([0,0,1],n); ang = acos([0,0,1]*n2); // Works because n2 is unit length. difference() { YOUR_PART(); translate(cp) rotate(a=ang,v=axis) translate([0,0,-2*s]) cube(4*s,center=true); } ``` Or, in BOSL2: ``` plane = plane3pt(p1,p2,p3) half_of(v=plane_normal(plane), cp=mean([p1,p2,p3]), s=2*s) YOUR_PART(); ``` - Revar > On Apr 24, 2020, at 9:33 PM, ThumbOne via Discuss <[hidden email]> wrote: > > Really liking the programmatic style of OpenSCAD. > > But it does pose some challenges. > > If I make a cube: > > cube([x, y, z], false); > > Given thee points: > > p1 = [x1, y1, z1]; > p2 = [x2, y2, z2]; > p3 = [x3, y3, z3]; > > that define a plane. I'd like to chop the cube with that plane (everything > above that plane, i.e. z > z_plane). > > Clearly one way to do this is is to create another cube, somewhat bigger > perhaps, rotate it, translate it and then use it in a difference. > > The specifics are challenging. Has anyone any tips here or code already > written? > > For example to define a cube with specified dimensions whose base contains > the three points? That would be a gem! > > > > -- > Sent from: http://forum.openscad.org/ > > _______________________________________________ > OpenSCAD mailing list > [hidden email] > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
Modularized and tested:
``` module above_plane(p1,p2,p3,s=100) { v1 = p2 - p1; v2 = p3 - p1; n = cross(v1,v2); n2 = n / norm(n) * sign(n.z); cp = (p1 + p2 + p3) / 3; axis = cross([0,0,1],n2); dot = [0,0,1] * n2; ang = acos(dot>1? 1 : dot<-1? -1 : dot); // Fixes FP rounding errors. difference() { children(); translate(cp) rotate(a=ang,v=axis) translate([0,0,-2*s]) cube(4*s,center=true); } } p1 = [-100,-100,0]; p2 = [0,100,50]; p3 = [100,-100,0]; above_plane(p1,p2,p3) cylinder(h=100,d=100); ``` > On Apr 24, 2020, at 10:24 PM, Revar Desmera <[hidden email]> wrote: > > Off the top of my head, given p1, p2, p3, and a size s that is the size of the largest axis of the part to mask: > > ``` > v1 = p2 - p1; > v2 = p3 - p1; > n = cross(v1,v2); > n2 = n / norm(n); > cp = (p1 + p2 + p3) / 3; > axis = cross([0,0,1],n); > ang = acos([0,0,1]*n2); // Works because n2 is unit length. > difference() { > YOUR_PART(); > translate(cp) rotate(a=ang,v=axis) translate([0,0,-2*s]) cube(4*s,center=true); > } > ``` > > Or, in BOSL2: > ``` > plane = plane3pt(p1,p2,p3) > half_of(v=plane_normal(plane), cp=mean([p1,p2,p3]), s=2*s) YOUR_PART(); > ``` > > - Revar > > > >> On Apr 24, 2020, at 9:33 PM, ThumbOne via Discuss <[hidden email]> wrote: >> >> Really liking the programmatic style of OpenSCAD. >> >> But it does pose some challenges. >> >> If I make a cube: >> >> cube([x, y, z], false); >> >> Given thee points: >> >> p1 = [x1, y1, z1]; >> p2 = [x2, y2, z2]; >> p3 = [x3, y3, z3]; >> >> that define a plane. I'd like to chop the cube with that plane (everything >> above that plane, i.e. z > z_plane). >> >> Clearly one way to do this is is to create another cube, somewhat bigger >> perhaps, rotate it, translate it and then use it in a difference. >> >> The specifics are challenging. Has anyone any tips here or code already >> written? >> >> For example to define a cube with specified dimensions whose base contains >> the three points? That would be a gem! >> >> >> >> -- >> Sent from: http://forum.openscad.org/ >> >> _______________________________________________ >> OpenSCAD mailing list >> [hidden email] >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
In reply to this post by OpenSCAD mailing list-2
I would use rotFromTo bellow to rotate the cube from the vertical direction to the three point plane normal:
Em sáb., 25 de abr. de 2020 às 05:34, ThumbOne via Discuss <[hidden email]> escreveu: Really liking the programmatic style of OpenSCAD. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
Free forum by Nabble | Edit this page |