discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

General approach/technique/code for using OpenSCAD as a solver?

AM
Adrian Mariano
Thu, Oct 31, 2024 6:55 PM

I am a little puzzled about the claim on the reddit post about there being
a “large gap” with find_root. The tolerance is 1e-15 on the solution which
should be good enough for anything. No example of a gap is given.

I also note that the real_roots function can solve quartics of you want to
do it that way.

On Thu, Oct 31, 2024 at 13:08 William F. Adams via Discuss <
discuss@lists.openscad.org> wrote:

Elegantly done!

I hope you don't mind that I posted it (with attribution) to:

https://old.reddit.com/r/openscad/comments/1gf3y69/length_and_angle_of_diagonal_beam_in_a_specific/luoo5ar/

As noted there, a big problem with approaching this angularly is that even
a quite small angle can result in a quite large deviation.

William

On Wednesday, October 30, 2024 at 04:36:32 PM EDT, Adrian Mariano via
Discuss discuss@lists.openscad.org wrote:

Here's a direct solution to the problem using a function solver, which is
really the right way to do this kind of problem:

include<BOSL2/std.scad>

width = 8;
height = 12;
beamwidth=3;

// Length of beam so that it achieves the desired width at specified
angle
function length(theta) = (width-beamwidth*sin(theta))/cos(theta);

// Height of beam at angle theta with the length chosen to match target
width
function height(theta) = length(theta) * sin(theta) + beamwidth*cos(theta);

ang = root_find(function (theta) height(theta) - height, 1, 89);

echo(ang);

rect([width,height]);
zrot(90-ang)color("red")rect([beamwidth, length(ang)]);

On Wed, Oct 30, 2024 at 1:58 PM John David via Discuss <
discuss@lists.openscad.org> wrote:

A question to the general list.  Is "blockscad3d.com" a known/trusted

URL?

On Wed, Oct 30, 2024 at 1:07 PM William F. Adams via Discuss <

and I was able to puzzle out a recursive version pretty easily:

https://www.blockscad3d.com/community/projects/1845977

click on "Create my own" and then "Render"

The if check might need to be updated, but it seemed to work for all

the values I tested with.

William


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

I am a little puzzled about the claim on the reddit post about there being a “large gap” with find_root. The tolerance is 1e-15 on the solution which should be good enough for anything. No example of a gap is given. I also note that the real_roots function can solve quartics of you want to do it that way. On Thu, Oct 31, 2024 at 13:08 William F. Adams via Discuss < discuss@lists.openscad.org> wrote: > Elegantly done! > > I hope you don't mind that I posted it (with attribution) to: > > > https://old.reddit.com/r/openscad/comments/1gf3y69/length_and_angle_of_diagonal_beam_in_a_specific/luoo5ar/ > > As noted there, a big problem with approaching this angularly is that even > a quite small angle can result in a quite large deviation. > > William > > > > > > On Wednesday, October 30, 2024 at 04:36:32 PM EDT, Adrian Mariano via > Discuss <discuss@lists.openscad.org> wrote: > > > > > > Here's a direct solution to the problem using a function solver, which is > really the right way to do this kind of problem: > > include<BOSL2/std.scad> > > width = 8; > height = 12; > beamwidth=3; > > // Length of beam so that it achieves the desired width at specified > angle > function length(theta) = (width-beamwidth*sin(theta))/cos(theta); > > // Height of beam at angle theta with the length chosen to match target > width > function height(theta) = length(theta) * sin(theta) + beamwidth*cos(theta); > > ang = root_find(function (theta) height(theta) - height, 1, 89); > > echo(ang); > > rect([width,height]); > zrot(90-ang)color("red")rect([beamwidth, length(ang)]); > > On Wed, Oct 30, 2024 at 1:58 PM John David via Discuss < > discuss@lists.openscad.org> wrote: > > A question to the general list. Is "blockscad3d.com" a known/trusted > URL? > > > > On Wed, Oct 30, 2024 at 1:07 PM William F. Adams via Discuss < > discuss@lists.openscad.org> wrote: > >> and I was able to puzzle out a recursive version pretty easily: > >> > >> https://www.blockscad3d.com/community/projects/1845977 > >> > >> click on "Create my own" and then "Render" > >> > >> The if check might need to be updated, but it seemed to work for all > the values I tested with. > >> > >> William > >> _______________________________________________ > >> OpenSCAD mailing list > >> To unsubscribe send an email to discuss-leave@lists.openscad.org > >> > >> > > _______________________________________________ > > OpenSCAD mailing list > > To unsubscribe send an email to discuss-leave@lists.openscad.org > > > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
SP
Sanjeev Prabhakar
Fri, Nov 1, 2024 9:24 AM

Hi William,
I am little late to this
What is the question here?
You want to calculate angle the tilted beam makes with the ground, such
that the tilted beam touches and rests on both the vertical beams?

On Wed, 30 Oct, 2024, 7:26 am William F. Adams via Discuss, <
discuss@lists.openscad.org> wrote:

One of the really cool things about METAFONT/METAPOST is that one can
assign some variables and have the program solve an equation.

I tried to do something along those lines at:

https://forum.makerforums.info/t/using-openscad-in-lieu-of-a-geometric-solver/91726

and sort of hacked together some workable code:

//!OpenSCAD

beamwidth = 10;
beamheight = 100;
beamthickness = 1;
beamspacing = 40;

module beam(bw, bh, bt) {
cube([bw, bh, bt], center=false);
}

union(){
beam(beamwidth, beamheight, beamthickness);
translate([(beamspacing + beamwidth), 0, 0]){
beam(beamwidth, beamheight, beamthickness);
}
for (i = [1 : abs(1) : 90]) {
if (beamheight >= sin(i) * beamwidth + (beamspacing - cos(i) *
beamwidth) / tan(i) && beamheight * 0.9 <= sin((i + 1)) * beamwidth +
(beamspacing - cos((i + 1)) * beamwidth) / tan((i + 1))) {
translate([((beamspacing + beamwidth) - cos(i) * beamwidth), 0, i]){
rotate([0, 0, i]){
beam(beamwidth, beamheight, beamthickness);
}
}
}
}
}

would there be some elegant way to ensure that only one instance is
found/returned?

I guess if I was using OpenPythonSCAD I could have broken out of the loop,
but then I wouldn't've been able to use BlockSCAD for coding:

https://www.blockscad3d.com/community/projects/1845977

William


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

Hi William, I am little late to this What is the question here? You want to calculate angle the tilted beam makes with the ground, such that the tilted beam touches and rests on both the vertical beams? On Wed, 30 Oct, 2024, 7:26 am William F. Adams via Discuss, < discuss@lists.openscad.org> wrote: > One of the really cool things about METAFONT/METAPOST is that one can > assign some variables and have the program solve an equation. > > I tried to do something along those lines at: > > > https://forum.makerforums.info/t/using-openscad-in-lieu-of-a-geometric-solver/91726 > > and sort of hacked together some workable code: > > //!OpenSCAD > > beamwidth = 10; > beamheight = 100; > beamthickness = 1; > beamspacing = 40; > > module beam(bw, bh, bt) { > cube([bw, bh, bt], center=false); > } > > union(){ > beam(beamwidth, beamheight, beamthickness); > translate([(beamspacing + beamwidth), 0, 0]){ > beam(beamwidth, beamheight, beamthickness); > } > for (i = [1 : abs(1) : 90]) { > if (beamheight >= sin(i) * beamwidth + (beamspacing - cos(i) * > beamwidth) / tan(i) && beamheight * 0.9 <= sin((i + 1)) * beamwidth + > (beamspacing - cos((i + 1)) * beamwidth) / tan((i + 1))) { > translate([((beamspacing + beamwidth) - cos(i) * beamwidth), 0, i]){ > rotate([0, 0, i]){ > beam(beamwidth, beamheight, beamthickness); > } > } > } > } > } > > > would there be some elegant way to ensure that only one instance is > found/returned? > > I guess if I was using OpenPythonSCAD I could have broken out of the loop, > but then I wouldn't've been able to use BlockSCAD for coding: > > https://www.blockscad3d.com/community/projects/1845977 > > William > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
SP
Sanjeev Prabhakar
Sat, Nov 2, 2024 10:57 AM

you can do this by solving equation through python

I have made a small video to demo this

https://youtu.be/KxWh-EkoUqA

On Wed, 30 Oct 2024 at 07:26, William F. Adams via Discuss <
discuss@lists.openscad.org> wrote:

One of the really cool things about METAFONT/METAPOST is that one can
assign some variables and have the program solve an equation.

I tried to do something along those lines at:

https://forum.makerforums.info/t/using-openscad-in-lieu-of-a-geometric-solver/91726

and sort of hacked together some workable code:

//!OpenSCAD

beamwidth = 10;
beamheight = 100;
beamthickness = 1;
beamspacing = 40;

module beam(bw, bh, bt) {
cube([bw, bh, bt], center=false);
}

union(){
beam(beamwidth, beamheight, beamthickness);
translate([(beamspacing + beamwidth), 0, 0]){
beam(beamwidth, beamheight, beamthickness);
}
for (i = [1 : abs(1) : 90]) {
if (beamheight >= sin(i) * beamwidth + (beamspacing - cos(i) *
beamwidth) / tan(i) && beamheight * 0.9 <= sin((i + 1)) * beamwidth +
(beamspacing - cos((i + 1)) * beamwidth) / tan((i + 1))) {
translate([((beamspacing + beamwidth) - cos(i) * beamwidth), 0, i]){
rotate([0, 0, i]){
beam(beamwidth, beamheight, beamthickness);
}
}
}
}
}

would there be some elegant way to ensure that only one instance is
found/returned?

I guess if I was using OpenPythonSCAD I could have broken out of the loop,
but then I wouldn't've been able to use BlockSCAD for coding:

https://www.blockscad3d.com/community/projects/1845977

William


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

you can do this by solving equation through python I have made a small video to demo this https://youtu.be/KxWh-EkoUqA On Wed, 30 Oct 2024 at 07:26, William F. Adams via Discuss < discuss@lists.openscad.org> wrote: > One of the really cool things about METAFONT/METAPOST is that one can > assign some variables and have the program solve an equation. > > I tried to do something along those lines at: > > > https://forum.makerforums.info/t/using-openscad-in-lieu-of-a-geometric-solver/91726 > > and sort of hacked together some workable code: > > //!OpenSCAD > > beamwidth = 10; > beamheight = 100; > beamthickness = 1; > beamspacing = 40; > > module beam(bw, bh, bt) { > cube([bw, bh, bt], center=false); > } > > union(){ > beam(beamwidth, beamheight, beamthickness); > translate([(beamspacing + beamwidth), 0, 0]){ > beam(beamwidth, beamheight, beamthickness); > } > for (i = [1 : abs(1) : 90]) { > if (beamheight >= sin(i) * beamwidth + (beamspacing - cos(i) * > beamwidth) / tan(i) && beamheight * 0.9 <= sin((i + 1)) * beamwidth + > (beamspacing - cos((i + 1)) * beamwidth) / tan((i + 1))) { > translate([((beamspacing + beamwidth) - cos(i) * beamwidth), 0, i]){ > rotate([0, 0, i]){ > beam(beamwidth, beamheight, beamthickness); > } > } > } > } > } > > > would there be some elegant way to ensure that only one instance is > found/returned? > > I guess if I was using OpenPythonSCAD I could have broken out of the loop, > but then I wouldn't've been able to use BlockSCAD for coding: > > https://www.blockscad3d.com/community/projects/1845977 > > William > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >