discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Fit an rectangle into another rectangle

NH
nop head
Thu, Mar 25, 2021 5:08 PM

I gave the equation to Wolfram to solve. It did but answer is horrible:
https://www.wolframalpha.com/input/?i=solve+sqrt%28w%5E2+-x%5E2%29%2Fx+%3D+%28a-x%29+%2F+%28b+-+sqrt%28w%5E2+-x%5E2%29%29

On Thu, 25 Mar 2021 at 17:08, Ray West raywest@raywest.com wrote:

When you've solved that, then consider a room, say 14ft by 12ft, and you
need to cut a scaffold plank, 1 foot wide, with square ends, so that it
fits exactly diagonally across the corners, as a platform for artexing the
ceiling, say. What length plank is required?  (The four corners of the
plank touch the walls). Has to be a formula, no iterative process/drawing
allowed.
On 25/03/2021 09:26, bassklampfe wrote:

Task is to fit a rectangle with given width 'w' into another rectangle
with given size 'a' x 'b', so that all four edges of inner rectangle
touches the outer rectangle ( at [x,0],[0,y],[a-x,b],[a,b-y] ). Now I need
a formula to calculate x and y from given a,b,w

I have made an animation, which illustrates the problem.
(OpenSCAD script below)

If 'x' is known, solution is simple to calculate 'y' and 'w'. (see
fit_for_given_x(x) )
Now I need a function fit_for_given_w(w) to calculate 'x' and 'y'

// Animation: FPS=5 STEPS=100

a=13;
b=15;

module fit_for_given_x(x)
{
y=b-(b/2+sqrt(xx+bb/4-ax));
w=sqrt(x
x+y*y);

 inner_rect=[[x,0],[0,y],[a-x,b],[a,b-y]];
 color("blue")linear_extrude(0.01)polygon(points=inner_rect);
 color("black")translate([x,0,0])linear_extrude(0.02)text(str("x=",x),size=1,halign="center",valign="top");
 color("black")translate([0,y,0])linear_extrude(0.02)text(str("y=",y),size=1,halign="right",valign="center");
 color("black")translate([x/2,y/2,0])linear_extrude(0.02)text(str("w=",w),size=1,halign="left",valign="bottom");

}

if(is_num($t))
{
if($t>0)if($t<1)
{
fit_for_given_x(a*$t);
}
}

color("black")translate([a/2,b,0])linear_extrude(0.02)text(str("a=",a),size=1,halign="center",valign="bottom");
color("black")translate([a,b/2,0])linear_extrude(0.02)text(str("b=",b),size=1,halign="left",valign="center");

outer_rect=[[0,0],[0,b],[a,b],[a,0]];
color("yellow")linear_extrude(0.001)polygon(points=outer_rect);


Sent from the OpenSCAD mailing list archive http://forum.openscad.org/
at Nabble.com.


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 gave the equation to Wolfram to solve. It did but answer is horrible: https://www.wolframalpha.com/input/?i=solve+sqrt%28w%5E2+-x%5E2%29%2Fx+%3D+%28a-x%29+%2F+%28b+-+sqrt%28w%5E2+-x%5E2%29%29 On Thu, 25 Mar 2021 at 17:08, Ray West <raywest@raywest.com> wrote: > When you've solved that, then consider a room, say 14ft by 12ft, and you > need to cut a scaffold plank, 1 foot wide, with square ends, so that it > fits exactly diagonally across the corners, as a platform for artexing the > ceiling, say. What length plank is required? (The four corners of the > plank touch the walls). Has to be a formula, no iterative process/drawing > allowed. > On 25/03/2021 09:26, bassklampfe wrote: > > Task is to fit a rectangle with given width 'w' into another rectangle > with given size 'a' x 'b', so that all four edges of inner rectangle > touches the outer rectangle ( at [x,0],[0,y],[a-x,b],[a,b-y] ). Now I need > a formula to calculate x and y from given a,b,w > > > > I have made an animation, which illustrates the problem. > (OpenSCAD script below) > > If 'x' is known, solution is simple to calculate 'y' and 'w'. (see > fit_for_given_x(x) ) > Now I need a function fit_for_given_w(w) to calculate 'x' and 'y' > > > // Animation: FPS=5 STEPS=100 > > a=13; > b=15; > > module fit_for_given_x(x) > { > y=b-(b/2+sqrt(x*x+b*b/4-a*x)); > w=sqrt(x*x+y*y); > > inner_rect=[[x,0],[0,y],[a-x,b],[a,b-y]]; > color("blue")linear_extrude(0.01)polygon(points=inner_rect); > color("black")translate([x,0,0])linear_extrude(0.02)text(str("x=",x),size=1,halign="center",valign="top"); > color("black")translate([0,y,0])linear_extrude(0.02)text(str("y=",y),size=1,halign="right",valign="center"); > color("black")translate([x/2,y/2,0])linear_extrude(0.02)text(str("w=",w),size=1,halign="left",valign="bottom"); > } > > if(is_num($t)) > { > if($t>0)if($t<1) > { > fit_for_given_x(a*$t); > } > } > > color("black")translate([a/2,b,0])linear_extrude(0.02)text(str("a=",a),size=1,halign="center",valign="bottom"); > color("black")translate([a,b/2,0])linear_extrude(0.02)text(str("b=",b),size=1,halign="left",valign="center"); > > outer_rect=[[0,0],[0,b],[a,b],[a,0]]; > color("yellow")linear_extrude(0.001)polygon(points=outer_rect); > > > ------------------------------ > Sent from the OpenSCAD mailing list archive <http://forum.openscad.org/> > at Nabble.com. > > _______________________________________________ > 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 >
JW
Jan Wieck
Thu, Mar 25, 2021 5:22 PM

No offense, but this whole thing starts feeling like we are doing
somebody's homework here.

Regards, Jan

On 3/25/21 1:08 PM, nop head wrote:

I gave the equation to Wolfram to solve. It did but answer is horrible:
https://www.wolframalpha.com/input/?i=solve+sqrt%28w%5E2+-x%5E2%29%2Fx+%3D+%28a-x%29+%2F+%28b+-+sqrt%28w%5E2+-x%5E2%29%29
https://www.wolframalpha.com/input/?i=solve+sqrt%28w%5E2+-x%5E2%29%2Fx+%3D+%28a-x%29+%2F+%28b+-+sqrt%28w%5E2+-x%5E2%29%29

On Thu, 25 Mar 2021 at 17:08, Ray West <raywest@raywest.com
mailto:raywest@raywest.com> wrote:

 When you've solved that, then consider a room, say 14ft by 12ft, and
 you need to cut a scaffold plank, 1 foot wide, with square ends, so
 that it fits exactly diagonally across the corners, as a platform
 for artexing the ceiling, say. What length plank is required?  (The
 four corners of the plank touch the walls). Has to be a formula, no
 iterative process/drawing allowed.

 On 25/03/2021 09:26, bassklampfe wrote:
 Task is to fit a rectangle with given width 'w' into another
 rectangle with given size 'a' x 'b', so that all four edges of
 inner rectangle touches the outer rectangle ( at
 [x,0],[0,y],[a-x,b],[a,b-y] ). Now I need a formula to calculate x
 and y from given a,b,w



 I have made an animation, which illustrates the problem.
 (OpenSCAD script below)

 If 'x' is known, solution is simple to calculate 'y' and 'w'. (see
 fit_for_given_x(x) )
 Now I need a function fit_for_given_w(w) to calculate 'x' and 'y'


 // Animation: FPS=5 STEPS=100

 a=13;
 b=15;

 module fit_for_given_x(x)
 {
      y=b-(b/2+sqrt(x*x+b*b/4-a*x));
      w=sqrt(x*x+y*y);
     
      inner_rect=[[x,0],[0,y],[a-x,b],[a,b-y]];
      color("blue")linear_extrude(0.01)polygon(points=inner_rect);
      color("black")translate([x,0,0])linear_extrude(0.02)text(str("x=",x),size=1,halign="center",valign="top");
      color("black")translate([0,y,0])linear_extrude(0.02)text(str("y=",y),size=1,halign="right",valign="center");
      color("black")translate([x/2,y/2,0])linear_extrude(0.02)text(str("w=",w),size=1,halign="left",valign="bottom");
 }

 if(is_num($t))
 {
      if($t>0)if($t<1)
      {
          fit_for_given_x(a*$t);
      }
 }

 color("black")translate([a/2,b,0])linear_extrude(0.02)text(str("a=",a),size=1,halign="center",valign="bottom");
 color("black")translate([a,b/2,0])linear_extrude(0.02)text(str("b=",b),size=1,halign="left",valign="center");
         
 outer_rect=[[0,0],[0,b],[a,b],[a,0]];
 color("yellow")linear_extrude(0.001)polygon(points=outer_rect);

 ------------------------------------------------------------------------
 Sent from the OpenSCAD mailing list archive
 <http://forum.openscad.org/> at Nabble.com.

 _______________________________________________
 OpenSCAD mailing list
 To unsubscribe send an email todiscuss-leave@lists.openscad.org  <mailto:discuss-leave@lists.openscad.org>
 _______________________________________________
 OpenSCAD mailing list
 To unsubscribe send an email to discuss-leave@lists.openscad.org
 <mailto:discuss-leave@lists.openscad.org>

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

--
Jan Wieck
Principle Database Engineer
Amazon Web Services

No offense, but this whole thing starts feeling like we are doing somebody's homework here. Regards, Jan On 3/25/21 1:08 PM, nop head wrote: > I gave the equation to Wolfram to solve. It did but answer is horrible: > https://www.wolframalpha.com/input/?i=solve+sqrt%28w%5E2+-x%5E2%29%2Fx+%3D+%28a-x%29+%2F+%28b+-+sqrt%28w%5E2+-x%5E2%29%29 > <https://www.wolframalpha.com/input/?i=solve+sqrt%28w%5E2+-x%5E2%29%2Fx+%3D+%28a-x%29+%2F+%28b+-+sqrt%28w%5E2+-x%5E2%29%29> > > > On Thu, 25 Mar 2021 at 17:08, Ray West <raywest@raywest.com > <mailto:raywest@raywest.com>> wrote: > > When you've solved that, then consider a room, say 14ft by 12ft, and > you need to cut a scaffold plank, 1 foot wide, with square ends, so > that it fits exactly diagonally across the corners, as a platform > for artexing the ceiling, say. What length plank is required?  (The > four corners of the plank touch the walls). Has to be a formula, no > iterative process/drawing allowed. > > On 25/03/2021 09:26, bassklampfe wrote: >> Task is to fit a rectangle with given width 'w' into another >> rectangle with given size 'a' x 'b', so that all four edges of >> inner rectangle touches the outer rectangle ( at >> [x,0],[0,y],[a-x,b],[a,b-y] ). Now I need a formula to calculate x >> and y from given a,b,w >> >> >> >> I have made an animation, which illustrates the problem. >> (OpenSCAD script below) >> >> If 'x' is known, solution is simple to calculate 'y' and 'w'. (see >> fit_for_given_x(x) ) >> Now I need a function fit_for_given_w(w) to calculate 'x' and 'y' >> >> >> // Animation: FPS=5 STEPS=100 >> >> a=13; >> b=15; >> >> module fit_for_given_x(x) >> { >> y=b-(b/2+sqrt(x*x+b*b/4-a*x)); >> w=sqrt(x*x+y*y); >> >> inner_rect=[[x,0],[0,y],[a-x,b],[a,b-y]]; >> color("blue")linear_extrude(0.01)polygon(points=inner_rect); >> color("black")translate([x,0,0])linear_extrude(0.02)text(str("x=",x),size=1,halign="center",valign="top"); >> color("black")translate([0,y,0])linear_extrude(0.02)text(str("y=",y),size=1,halign="right",valign="center"); >> color("black")translate([x/2,y/2,0])linear_extrude(0.02)text(str("w=",w),size=1,halign="left",valign="bottom"); >> } >> >> if(is_num($t)) >> { >> if($t>0)if($t<1) >> { >> fit_for_given_x(a*$t); >> } >> } >> >> color("black")translate([a/2,b,0])linear_extrude(0.02)text(str("a=",a),size=1,halign="center",valign="bottom"); >> color("black")translate([a,b/2,0])linear_extrude(0.02)text(str("b=",b),size=1,halign="left",valign="center"); >> >> outer_rect=[[0,0],[0,b],[a,b],[a,0]]; >> color("yellow")linear_extrude(0.001)polygon(points=outer_rect); >> >> ------------------------------------------------------------------------ >> Sent from the OpenSCAD mailing list archive >> <http://forum.openscad.org/> at Nabble.com. >> >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email todiscuss-leave@lists.openscad.org <mailto:discuss-leave@lists.openscad.org> > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org > <mailto:discuss-leave@lists.openscad.org> > > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org > -- Jan Wieck Principle Database Engineer Amazon Web Services
JB
Jordan Brown
Thu, Mar 25, 2021 5:31 PM

I stopped and threw away my work when I saw that you had gotten to the
same "two equations and two unknowns" that I started with.  I didn't yet
have a simple expression, but where I stopped I had fairly
straightforward case of the quadratic function.  I was pretty sure it
was uglier than it needed to be, but didn't feel like spending more time
simplifying - and it seemed likely that somebody else would do it easier
and faster.  It was maybe half a line of text long at that point.  I'm
pretty confident that the math salad that Wolfram came up with is
unnecessary.

I stopped and threw away my work when I saw that you had gotten to the same "two equations and two unknowns" that I started with.  I didn't yet have a simple expression, but where I stopped I had fairly straightforward case of the quadratic function.  I was pretty sure it was uglier than it needed to be, but didn't feel like spending more time simplifying - and it seemed likely that somebody else would do it easier and faster.  It was maybe half a line of text long at that point.  I'm pretty confident that the math salad that Wolfram came up with is unnecessary.
B
bassklampfe
Thu, Mar 25, 2021 6:18 PM

nophead wrote

Your input seems better input as what I got for
(w² − x²)^(0.5) = − ( − b + (b² + 4(x² − ax))^(0.5))/2
at https://www.dcode.fr/equation-solver

I will try, if the solution from wolframalpha is correct thanks

--
Sent from: http://forum.openscad.org/

nophead wrote > I gave the equation to Wolfram to solve. It did but answer is horrible: > https://www.wolframalpha.com/input/?i=solve+sqrt%28w%5E2+-x%5E2%29%2Fx+%3D+%28a-x%29+%2F+%28b+-+sqrt%28w%5E2+-x%5E2%29%29 Your input seems better input as what I got for (w² − x²)^(0.5) = − ( − b + (b² + 4(x² − ax))^(0.5))/2 at https://www.dcode.fr/equation-solver I will try, if the solution from wolframalpha is correct thanks -- Sent from: http://forum.openscad.org/
B
bassklampfe
Thu, Mar 25, 2021 6:28 PM

MostlyHarmless wrote

No offense, but this whole thing starts feeling like we are doing
somebody's homework here.

I can tell you, you are not.

Solution of this problem is one missing part to build steel constructions
like
http://forum.openscad.org/file/t2988/peine-profiles-example.png
without mechanical errors and in the final step to build full customizable
railway steel bridges in OpenSCAD.

When all things are completed, I will happily share the result with you.

--
Sent from: http://forum.openscad.org/

MostlyHarmless wrote > No offense, but this whole thing starts feeling like we are doing > somebody's homework here. I can tell you, you are not. Solution of this problem is one missing part to build steel constructions like <http://forum.openscad.org/file/t2988/peine-profiles-example.png> without mechanical errors and in the final step to build full customizable railway steel bridges in OpenSCAD. When all things are completed, I will happily share the result with you. -- Sent from: http://forum.openscad.org/
B
bassklampfe
Thu, Mar 25, 2021 6:40 PM

nophead wrote

I'm not scared by the answer, as long as it is correct – which still has to
be prooved.

But isn't it this, why we use computers? To do calculations, which feels
like horror to some people

--
Sent from: http://forum.openscad.org/

nophead wrote > I gave the equation to Wolfram to solve. It did but answer is horrible: > https://www.wolframalpha.com/input/?i=solve+sqrt%28w%5E2+-x%5E2%29%2Fx+%3D+%28a-x%29+%2F+%28b+-+sqrt%28w%5E2+-x%5E2%29%29 I'm not scared by the answer, as long as it is correct – which still has to be prooved. But isn't it this, why we use computers? To do calculations, which feels like horror to some people -- Sent from: http://forum.openscad.org/
JW
Jan Wieck
Thu, Mar 25, 2021 6:54 PM

On 3/25/21 2:28 PM, bassklampfe wrote:

 MostlyHarmless wrote
 No offense, but this whole thing starts feeling like we are doing
 somebody's homework here.

I can tell you, you are not.

Solution of this problem is one missing part to build steel
constructions like

without mechanical errors and in the final step to build full
customizable railway steel bridges in OpenSCAD.

As said, no offense. I'm just around the interwebs since the late 80's
(yeah, it was email and netnews over UUCP back then), so I have seen
this sort of math problem without explaining a practical purpose once or
twice before ;)

My gut feeling is that it requires taking the angles into account. The
inner rectangle has a certain rotation that produces 4 right triangles,
which all have identical angles. I'll have to think about it a bit
longer, but maybe that will give us the 3rd equation to eliminate one of
the variables.

Regards, Jan

When all things are completed, I will happily share the result with you.


Sent from the OpenSCAD mailing list archive http://forum.openscad.org/
at Nabble.com.


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

--
Jan Wieck
Principle Database Engineer
Amazon Web Services

On 3/25/21 2:28 PM, bassklampfe wrote: > MostlyHarmless wrote > No offense, but this whole thing starts feeling like we are doing > somebody's homework here. > > I can tell you, you are not. > > Solution of this problem is one missing part to build steel > constructions like > > without mechanical errors and in the final step to build full > customizable railway steel bridges in OpenSCAD. As said, no offense. I'm just around the interwebs since the late 80's (yeah, it was email and netnews over UUCP back then), so I have seen this sort of math problem without explaining a practical purpose once or twice before ;) My gut feeling is that it requires taking the angles into account. The inner rectangle has a certain rotation that produces 4 right triangles, which all have identical angles. I'll have to think about it a bit longer, but maybe that will give us the 3rd equation to eliminate one of the variables. Regards, Jan > > When all things are completed, I will happily share the result with you. > > > > ------------------------------------------------------------------------ > Sent from the OpenSCAD mailing list archive <http://forum.openscad.org/> > at Nabble.com. > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org > -- Jan Wieck Principle Database Engineer Amazon Web Services
KT
Kevin Toppenberg
Thu, Mar 25, 2021 8:35 PM

Nop head was on the right path.  But he left the a,b,w as variables for
Wolfram.  It doesn't complete within the allotted time, so fails to
simplify.  I tried specifying the example input variables of A=13, B=15
and W=9.16, which allows the algorithm to simplify earlier.  Now it solves
for x=8.57 (and also some imaginary solutions).

https://www.wolframalpha.com/input/?i=solve+sqrt%28w%5E2+-x%5E2%29%2Fx+%3D+%28a-x%29+%2F+%28b+-+sqrt%28w%5E2+-x%5E2%29%29%2Cw%3D9.16%2Ca%3D13%2Cb%3D15

The original request was for a formula to set up Fn(a,b,w) returning x.  I
am not able to solve the problem the way Wolfram did.  It appears to use 2
simultaneous equations (see the two lines on the graph).  Nop head
specified those.

Interesting problem that seems like it out to be easy, but seem to actually
be computationally complex.

Kevin

On Thu, Mar 25, 2021 at 1:10 PM nop head nop.head@gmail.com wrote:

I gave the equation to Wolfram to solve. It did but answer is horrible:
https://www.wolframalpha.com/input/?i=solve+sqrt%28w%5E2+-x%5E2%29%2Fx+%3D+%28a-x%29+%2F+%28b+-+sqrt%28w%5E2+-x%5E2%29%29

On Thu, 25 Mar 2021 at 17:08, Ray West raywest@raywest.com wrote:

When you've solved that, then consider a room, say 14ft by 12ft, and you
need to cut a scaffold plank, 1 foot wide, with square ends, so that it
fits exactly diagonally across the corners, as a platform for artexing the
ceiling, say. What length plank is required?  (The four corners of the
plank touch the walls). Has to be a formula, no iterative process/drawing
allowed.
On 25/03/2021 09:26, bassklampfe wrote:

Task is to fit a rectangle with given width 'w' into another rectangle
with given size 'a' x 'b', so that all four edges of inner rectangle
touches the outer rectangle ( at [x,0],[0,y],[a-x,b],[a,b-y] ). Now I need
a formula to calculate x and y from given a,b,w

I have made an animation, which illustrates the problem.
(OpenSCAD script below)

If 'x' is known, solution is simple to calculate 'y' and 'w'. (see
fit_for_given_x(x) )
Now I need a function fit_for_given_w(w) to calculate 'x' and 'y'

// Animation: FPS=5 STEPS=100

a=13;
b=15;

module fit_for_given_x(x)
{
y=b-(b/2+sqrt(xx+bb/4-ax));
w=sqrt(x
x+y*y);

 inner_rect=[[x,0],[0,y],[a-x,b],[a,b-y]];
 color("blue")linear_extrude(0.01)polygon(points=inner_rect);
 color("black")translate([x,0,0])linear_extrude(0.02)text(str("x=",x),size=1,halign="center",valign="top");
 color("black")translate([0,y,0])linear_extrude(0.02)text(str("y=",y),size=1,halign="right",valign="center");
 color("black")translate([x/2,y/2,0])linear_extrude(0.02)text(str("w=",w),size=1,halign="left",valign="bottom");

}

if(is_num($t))
{
if($t>0)if($t<1)
{
fit_for_given_x(a*$t);
}
}

color("black")translate([a/2,b,0])linear_extrude(0.02)text(str("a=",a),size=1,halign="center",valign="bottom");
color("black")translate([a,b/2,0])linear_extrude(0.02)text(str("b=",b),size=1,halign="left",valign="center");

outer_rect=[[0,0],[0,b],[a,b],[a,0]];
color("yellow")linear_extrude(0.001)polygon(points=outer_rect);


Sent from the OpenSCAD mailing list archive http://forum.openscad.org/
at Nabble.com.


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

Nop head was on the right path. But he left the a,b,w as variables for Wolfram. It doesn't complete within the allotted time, so fails to simplify. I tried specifying the example input variables of A=13, B=15 and W=9.16, which allows the algorithm to simplify earlier. Now it solves for x=8.57 (and also some imaginary solutions). https://www.wolframalpha.com/input/?i=solve+sqrt%28w%5E2+-x%5E2%29%2Fx+%3D+%28a-x%29+%2F+%28b+-+sqrt%28w%5E2+-x%5E2%29%29%2Cw%3D9.16%2Ca%3D13%2Cb%3D15 The original request was for a formula to set up Fn(a,b,w) returning x. I am not able to solve the problem the way Wolfram did. It appears to use 2 simultaneous equations (see the two lines on the graph). Nop head specified those. Interesting problem that seems like it out to be easy, but seem to actually be computationally complex. Kevin On Thu, Mar 25, 2021 at 1:10 PM nop head <nop.head@gmail.com> wrote: > I gave the equation to Wolfram to solve. It did but answer is horrible: > https://www.wolframalpha.com/input/?i=solve+sqrt%28w%5E2+-x%5E2%29%2Fx+%3D+%28a-x%29+%2F+%28b+-+sqrt%28w%5E2+-x%5E2%29%29 > > > On Thu, 25 Mar 2021 at 17:08, Ray West <raywest@raywest.com> wrote: > >> When you've solved that, then consider a room, say 14ft by 12ft, and you >> need to cut a scaffold plank, 1 foot wide, with square ends, so that it >> fits exactly diagonally across the corners, as a platform for artexing the >> ceiling, say. What length plank is required? (The four corners of the >> plank touch the walls). Has to be a formula, no iterative process/drawing >> allowed. >> On 25/03/2021 09:26, bassklampfe wrote: >> >> Task is to fit a rectangle with given width 'w' into another rectangle >> with given size 'a' x 'b', so that all four edges of inner rectangle >> touches the outer rectangle ( at [x,0],[0,y],[a-x,b],[a,b-y] ). Now I need >> a formula to calculate x and y from given a,b,w >> >> >> >> I have made an animation, which illustrates the problem. >> (OpenSCAD script below) >> >> If 'x' is known, solution is simple to calculate 'y' and 'w'. (see >> fit_for_given_x(x) ) >> Now I need a function fit_for_given_w(w) to calculate 'x' and 'y' >> >> >> // Animation: FPS=5 STEPS=100 >> >> a=13; >> b=15; >> >> module fit_for_given_x(x) >> { >> y=b-(b/2+sqrt(x*x+b*b/4-a*x)); >> w=sqrt(x*x+y*y); >> >> inner_rect=[[x,0],[0,y],[a-x,b],[a,b-y]]; >> color("blue")linear_extrude(0.01)polygon(points=inner_rect); >> color("black")translate([x,0,0])linear_extrude(0.02)text(str("x=",x),size=1,halign="center",valign="top"); >> color("black")translate([0,y,0])linear_extrude(0.02)text(str("y=",y),size=1,halign="right",valign="center"); >> color("black")translate([x/2,y/2,0])linear_extrude(0.02)text(str("w=",w),size=1,halign="left",valign="bottom"); >> } >> >> if(is_num($t)) >> { >> if($t>0)if($t<1) >> { >> fit_for_given_x(a*$t); >> } >> } >> >> color("black")translate([a/2,b,0])linear_extrude(0.02)text(str("a=",a),size=1,halign="center",valign="bottom"); >> color("black")translate([a,b/2,0])linear_extrude(0.02)text(str("b=",b),size=1,halign="left",valign="center"); >> >> outer_rect=[[0,0],[0,b],[a,b],[a,0]]; >> color("yellow")linear_extrude(0.001)polygon(points=outer_rect); >> >> >> ------------------------------ >> Sent from the OpenSCAD mailing list archive <http://forum.openscad.org/> >> at Nabble.com. >> >> _______________________________________________ >> 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 >
A
adrianv
Thu, Mar 25, 2021 9:55 PM

Maybe there's a clever way to solve this using trig, but I'm not seeing
it---and the similarity relationship really seems like the fundamental
defining property.

Solving a quartic isn't a big deal.  But solving one symbolically like
Wolfram Alpha does is completely pointless.  The quartic formula is a
horrible mess.  Give up on the idea of having a formula, and definitely
don't try to use the mess from Worlfram Alpha.  You need to solve the
equation numerically.  BOSL2 has a polynomial root finder that will do the
job.

https://github.com/revarbat/BOSL2/wiki/math.scad#function-real_roots

include<BOSL2/std.scad>

a=13;
b=15;
w=9;

function getx(a,b,w) =
let(
options = real_roots([4,-4a, aa+bb-4ww, 2wwa,
pow(w,4)-bbw*w]),
posopt = [for (x=options) if (x>0) x]
)
assert(len(posopt)==1)
posopt[0];

x=getx(a,b,w);
y=b-(b/2+sqrt(xx+bb/4-a*x));
echo(x=x,y=y);
echo(sqrt(sqr(x)+sqr(y)));
inner = [[x,0], [0, y], [a-x,b], [a,b-y]];

linear_extrude(height=1)square([a,b]);
color("red")linear_extrude(height=1.1)polygon(inner);

http://forum.openscad.org/file/t2477/rect.png

kdtop wrote

Nop head was on the right path.  But he left the a,b,w as variables for
Wolfram.  It doesn't complete within the allotted time, so fails to
simplify.  I tried specifying the example input variables of A=13, B=15
and W=9.16, which allows the algorithm to simplify earlier.  Now it solves
for x=8.57 (and also some imaginary solutions).

https://www.wolframalpha.com/input/?i=solve+sqrt%28w%5E2+-x%5E2%29%2Fx+%3D+%28a-x%29+%2F+%28b+-+sqrt%28w%5E2+-x%5E2%29%29%2Cw%3D9.16%2Ca%3D13%2Cb%3D15

The original request was for a formula to set up Fn(a,b,w) returning x.  I
am not able to solve the problem the way Wolfram did.  It appears to use 2
simultaneous equations (see the two lines on the graph).  Nop head
specified those.

Interesting problem that seems like it out to be easy, but seem to
actually
be computationally complex.

Kevin

On Thu, Mar 25, 2021 at 1:10 PM nop head <

nop.head@

> wrote:

I gave the equation to Wolfram to solve. It did but answer is horrible:
https://www.wolframalpha.com/input/?i=solve+sqrt%28w%5E2+-x%5E2%29%2Fx+%3D+%28a-x%29+%2F+%28b+-+sqrt%28w%5E2+-x%5E2%29%29

On Thu, 25 Mar 2021 at 17:08, Ray West <

raywest@

> wrote:

When you've solved that, then consider a room, say 14ft by 12ft, and you
need to cut a scaffold plank, 1 foot wide, with square ends, so that it
fits exactly diagonally across the corners, as a platform for artexing
the
ceiling, say. What length plank is required?  (The four corners of the
plank touch the walls). Has to be a formula, no iterative
process/drawing
allowed.
On 25/03/2021 09:26, bassklampfe wrote:

Task is to fit a rectangle with given width 'w' into another rectangle
with given size 'a' x 'b', so that all four edges of inner rectangle
touches the outer rectangle ( at [x,0],[0,y],[a-x,b],[a,b-y] ). Now I
need
a formula to calculate x and y from given a,b,w

I have made an animation, which illustrates the problem.
(OpenSCAD script below)

If 'x' is known, solution is simple to calculate 'y' and 'w'. (see
fit_for_given_x(x) )
Now I need a function fit_for_given_w(w) to calculate 'x' and 'y'

// Animation: FPS=5 STEPS=100

a=13;
b=15;

module fit_for_given_x(x)
{
y=b-(b/2+sqrt(xx+bb/4-ax));
w=sqrt(x
x+y*y);

 inner_rect=[[x,0],[0,y],[a-x,b],[a,b-y]];
 color("blue")linear_extrude(0.01)polygon(points=inner_rect);

color("black")translate([x,0,0])linear_extrude(0.02)text(str("x=",x),size=1,halign="center",valign="top");

color("black")translate([0,y,0])linear_extrude(0.02)text(str("y=",y),size=1,halign="right",valign="center");

color("black")translate([x/2,y/2,0])linear_extrude(0.02)text(str("w=",w),size=1,halign="left",valign="bottom");
}

if(is_num($t))
{
if($t>0)if($t<1)
{
fit_for_given_x(a*$t);
}
}

color("black")translate([a/2,b,0])linear_extrude(0.02)text(str("a=",a),size=1,halign="center",valign="bottom");
color("black")translate([a,b/2,0])linear_extrude(0.02)text(str("b=",b),size=1,halign="left",valign="center");

outer_rect=[[0,0],[0,b],[a,b],[a,0]];
color("yellow")linear_extrude(0.001)polygon(points=outer_rect);


Sent from the OpenSCAD mailing list archive
<http://forum.openscad.org/>
at Nabble.com.


OpenSCAD mailing list
To unsubscribe send an email to

discuss-leave@.openscad


OpenSCAD mailing list
To unsubscribe send an email to

discuss-leave@.openscad


OpenSCAD mailing list
To unsubscribe send an email to

discuss-leave@.openscad


OpenSCAD mailing list
To unsubscribe send an email to

discuss-leave@.openscad

Maybe there's a clever way to solve this using trig, but I'm not seeing it---and the similarity relationship really seems like the fundamental defining property. Solving a quartic isn't a big deal. But solving one *symbolically* like Wolfram Alpha does is completely pointless. The quartic formula is a horrible mess. Give up on the idea of having a formula, and definitely don't try to use the mess from Worlfram Alpha. You need to solve the equation numerically. BOSL2 has a polynomial root finder that will do the job. https://github.com/revarbat/BOSL2/wiki/math.scad#function-real_roots include<BOSL2/std.scad> a=13; b=15; w=9; function getx(a,b,w) = let( options = real_roots([4,-4*a, a*a+b*b-4*w*w, 2*w*w*a, pow(w,4)-b*b*w*w]), posopt = [for (x=options) if (x>0) x] ) assert(len(posopt)==1) posopt[0]; x=getx(a,b,w); y=b-(b/2+sqrt(x*x+b*b/4-a*x)); echo(x=x,y=y); echo(sqrt(sqr(x)+sqr(y))); inner = [[x,0], [0, y], [a-x,b], [a,b-y]]; linear_extrude(height=1)square([a,b]); color("red")linear_extrude(height=1.1)polygon(inner); <http://forum.openscad.org/file/t2477/rect.png> kdtop wrote > Nop head was on the right path. But he left the a,b,w as variables for > Wolfram. It doesn't complete within the allotted time, so fails to > simplify. I tried specifying the example input variables of A=13, B=15 > and W=9.16, which allows the algorithm to simplify earlier. Now it solves > for x=8.57 (and also some imaginary solutions). > > https://www.wolframalpha.com/input/?i=solve+sqrt%28w%5E2+-x%5E2%29%2Fx+%3D+%28a-x%29+%2F+%28b+-+sqrt%28w%5E2+-x%5E2%29%29%2Cw%3D9.16%2Ca%3D13%2Cb%3D15 > > The original request was for a formula to set up Fn(a,b,w) returning x. I > am not able to solve the problem the way Wolfram did. It appears to use 2 > simultaneous equations (see the two lines on the graph). Nop head > specified those. > > Interesting problem that seems like it out to be easy, but seem to > actually > be computationally complex. > > Kevin > > > On Thu, Mar 25, 2021 at 1:10 PM nop head &lt; > nop.head@ > &gt; wrote: > >> I gave the equation to Wolfram to solve. It did but answer is horrible: >> https://www.wolframalpha.com/input/?i=solve+sqrt%28w%5E2+-x%5E2%29%2Fx+%3D+%28a-x%29+%2F+%28b+-+sqrt%28w%5E2+-x%5E2%29%29 >> >> >> On Thu, 25 Mar 2021 at 17:08, Ray West &lt; > raywest@ > &gt; wrote: >> >>> When you've solved that, then consider a room, say 14ft by 12ft, and you >>> need to cut a scaffold plank, 1 foot wide, with square ends, so that it >>> fits exactly diagonally across the corners, as a platform for artexing >>> the >>> ceiling, say. What length plank is required? (The four corners of the >>> plank touch the walls). Has to be a formula, no iterative >>> process/drawing >>> allowed. >>> On 25/03/2021 09:26, bassklampfe wrote: >>> >>> Task is to fit a rectangle with given width 'w' into another rectangle >>> with given size 'a' x 'b', so that all four edges of inner rectangle >>> touches the outer rectangle ( at [x,0],[0,y],[a-x,b],[a,b-y] ). Now I >>> need >>> a formula to calculate x and y from given a,b,w >>> >>> >>> >>> I have made an animation, which illustrates the problem. >>> (OpenSCAD script below) >>> >>> If 'x' is known, solution is simple to calculate 'y' and 'w'. (see >>> fit_for_given_x(x) ) >>> Now I need a function fit_for_given_w(w) to calculate 'x' and 'y' >>> >>> >>> // Animation: FPS=5 STEPS=100 >>> >>> a=13; >>> b=15; >>> >>> module fit_for_given_x(x) >>> { >>> y=b-(b/2+sqrt(x*x+b*b/4-a*x)); >>> w=sqrt(x*x+y*y); >>> >>> inner_rect=[[x,0],[0,y],[a-x,b],[a,b-y]]; >>> color("blue")linear_extrude(0.01)polygon(points=inner_rect); >>> >>> color("black")translate([x,0,0])linear_extrude(0.02)text(str("x=",x),size=1,halign="center",valign="top"); >>> >>> color("black")translate([0,y,0])linear_extrude(0.02)text(str("y=",y),size=1,halign="right",valign="center"); >>> >>> color("black")translate([x/2,y/2,0])linear_extrude(0.02)text(str("w=",w),size=1,halign="left",valign="bottom"); >>> } >>> >>> if(is_num($t)) >>> { >>> if($t>0)if($t<1) >>> { >>> fit_for_given_x(a*$t); >>> } >>> } >>> >>> color("black")translate([a/2,b,0])linear_extrude(0.02)text(str("a=",a),size=1,halign="center",valign="bottom"); >>> color("black")translate([a,b/2,0])linear_extrude(0.02)text(str("b=",b),size=1,halign="left",valign="center"); >>> >>> outer_rect=[[0,0],[0,b],[a,b],[a,0]]; >>> color("yellow")linear_extrude(0.001)polygon(points=outer_rect); >>> >>> >>> ------------------------------ >>> Sent from the OpenSCAD mailing list archive >>> &lt;http://forum.openscad.org/&gt; >>> at Nabble.com. >>> >>> _______________________________________________ >>> OpenSCAD mailing list >>> To unsubscribe send an email to > discuss-leave@.openscad >>> >>> _______________________________________________ >>> OpenSCAD mailing list >>> To unsubscribe send an email to > discuss-leave@.openscad >>> >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email to > discuss-leave@.openscad >> > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to > discuss-leave@.openscad -- Sent from: http://forum.openscad.org/
T
Troberg
Sat, Mar 27, 2021 6:59 AM

nophead wrote

When you described it as "horrible", I expected something more along the
lines of "a bit awkward", but horrible does not give that solution justice.
This goes beyond horrible, and into pure terror...

--
Sent from: http://forum.openscad.org/

nophead wrote > I gave the equation to Wolfram to solve. It did but answer is horrible: > https://www.wolframalpha.com/input/?i=solve+sqrt%28w%5E2+-x%5E2%29%2Fx+%3D+%28a-x%29+%2F+%28b+-+sqrt%28w%5E2+-x%5E2%29%29 When you described it as "horrible", I expected something more along the lines of "a bit awkward", but horrible does not give that solution justice. This goes beyond horrible, and into pure terror... -- Sent from: http://forum.openscad.org/