Trying to construct a rectangle inside a rectangle

Discussion in 'AutoCAD' started by Alan Henderson @ A'cad Solutions, Jan 7, 2005.

  1. Alan Henderson @ A'cad Solutions

    David Kozina Guest

    Let me back up one step and say that I am ASSUMING that ugly beast of an
    equation can be solved for b
    ;)
     
    David Kozina, Jan 11, 2005
    #21
  2. Alan Henderson @ A'cad Solutions

    David Kozina Guest

    Rewriting that equation in terms of b...
    f(b) = 4b^4 - 4yb^3 + (x^2 + y^2 - 4w^2)b^2 + 2w^2yb + w^2(w^2 - x^2)

    Remember that x,y, & w are known (constant distances), so if
    there is a solution, we also know that the following must be true:

    0 < x
    0 < y
    0 < w <= (whichever is greater, x or y) (correct?)

    Finally the range of b is:
    0 < b <= w

    Can we assume that if a solution exists it will be unique? I think it must
    be.
    If so, then the graph of Y = f(b) over the range (0,w]
    must cross (or touch) the X-Axis (0) at some point (our solution)

    If it crosses the X-Axis, then the Y value of one range endpoint of the
    curve ought to be positive and the other negative.
    In this case, a linear slope (m) could be calculated from the curve
    endpoints and an estimated solution could then be interpolated from the
    result and perhaps refined further...
    LINE:
    Y = mX + B
    B = f(0)
    m = (f(w) - f(0))/w
    Y = 0 at w = -B/m <= First estimate

    Calculate f(-B/m) for new curve segment endpoint.
    OR calculate the curve at two endpoints b = -B/2m and b = (w + B/m)/2
    IOW, two points each halfway from the original endpoints to our estimate.
    Then recalculate slopes, etc to create a second estimate... and so on.

    If it only touches the X-Axis, then the slope of the curve at that point
    must be 0 (horizontal).
    Slope of original equation at any point will be its first derivative:

    f'(b) = 16b^3 - 12yb^2 + 2(x^2 + y^2 - 4w^2)b + 2w^2y

    Where f'(b) = 0 the slope is 0. I assume you could interpolate things as
    above and refine further.

    Fun stuff...
    (Joe's routine is probably faster. :)

    Best regards,
    David Kozina
     
    David Kozina, Jan 12, 2005
    #22
  3. David:
    That's very likely the same fourth-order polynomial my son came up with,
    mentioned in my Monday posting (I don't have it here to compare, but it had
    a comparable number of terms, with all those different powers up to 4 on
    your b term). He didn't think it was reducible to b = something only in
    terms of w x & y. But if there are other whizzes out there who might be
    able to do something with it....
     
    Kent Cooper, AIA, Jan 12, 2005
    #23
  4. Alan Henderson @ A'cad Solutions

    Joe Burke Guest

    David,

    I guess it would be fun, if I had the faintest idea what you and Kent are talking
    about. :)

    Let's assume, as you suggested, the solution you are thinking about still requires
    interpolation. I suspect that would be faster than my method of physically rotating
    rays, finding intersection points, and comparing distances a couple thousand times.

    You may be faced with what I was looking at. I didn't see a way to short code the
    thing in order to predict how it might turn out.

    Regards
    Joe Burke

     
    Joe Burke, Jan 12, 2005
    #24
  5. Alan Henderson @ A'cad Solutions

    BTO Guest

    hi, this problem was solved by Boutora Kamal,
    in thread "un rectangle impossible à dessiner ?" 25/07/2004
    news://news.planetar.net/autocad.general

    ;;; Programme pour le calcul d'un rectangle inscrit dans un autre
    ;;; connaissant la diagonale du 'petit' triangle
    ;;; Boutora kamal
    ;;;
    ;;; lancer la commande icare.

    (defun c:icare (/ p1 p2 di ctr r xh yh xd yd h l binf bsup found dcalc oldos
    oce dmax)

    (setq oce (getvar "cmdecho"))
    (setvar "cmdecho" 0)
    (setq oldos (getvar "osmode"))
    (if (and (setq p1 (getpoint "\nCoin 1 du rectangle"))
    (setq p2 (getpoint p1 "\nCoin 2 du rectangle"))
    (setq di (getdist "\nDiagonale du rectangle à inscrire"))
    )
    (progn
    (setvar "osmode" 0)
    (setq ctr (list (/ (+ (car p1) (car p2)) 2.0) (/ (+ (cadr p1) (cadr
    p2)) 2.0))
    l (abs (- (car p2) (car p1)))
    h (abs (- (cadr p2) (cadr p1)))
    )

    ;;; Conditions de départ pour une recherche dichotomique.
    (setq binf (/ (max h l) 2.0)
    bsup (distance ctr p1)
    )
    (setq found nil)
    (setq xd (+ (car ctr) (/ l 2.0)))
    (setq yh (+ (cadr ctr) (/ h 2.0)))
    (setq yd (+ (cadr ctr) (sqrt (- (* binf binf) (* 0.25 l l)))))
    (setq xh (+ (car ctr) (sqrt (- (* binf binf) (* 0.25 h h)))))
    (setq dmax (distance (list xh yh) (list xd yd)))
    (if (<= dmax di)
    (progn
    (princ (strcat "\nLa largeur maximale du rectangle est de " (rtos dmax
    2 4)))
    (setq binf bsup)
    )
    )

    (while (and (null found) (> (abs (- bsup binf)) 1E-6))

    ;;; Calcul du point d'intersection du cercle de centre ctr et de rayon r
    ;;; Avec l'angle en haut à droite du grand rectangle.
    ;;;
    (setq r (/ (+ bsup binf) 2.0))
    (setq xd (+ (car ctr) (/ l 2.0)))
    (setq yh (+ (cadr ctr) (/ h 2.0)))
    (setq yd (+ (cadr ctr) (sqrt (- (* r r) (* 0.25 l l)))))
    (setq xh (+ (car ctr) (sqrt (- (* r r) (* 0.25 h h)))))
    (setq dcalc (distance (list xh yh) (list xd yd)))

    ;;; Modification des bornes pour la recherche trigonométrique.
    (if (EQUAL dcalc di 1E-5)
    (setq found 't)
    (progn
    (if (< dcalc di)
    (setq bsup r)
    (setq binf r)
    )
    )
    )
    )
    (if found
    (progn
    (command "_pline"
    (list
    (+ (car ctr) (/ l 2.0))
    (+ (cadr ctr) (sqrt (- (* r r) (* 0.25 l l))))

    )
    (list

    (+ (car ctr) (sqrt (- (* r r) (* 0.25 h h))))
    (+ (cadr ctr) (/ h 2.0))

    )
    (list
    (- (car ctr) (/ l 2.0))
    (- (cadr ctr) (sqrt (- (* r r) (* 0.25 l l))))
    )
    (list
    (- (car ctr) (sqrt (- (* r r) (* 0.25 h h))))
    (- (cadr ctr) (/ h 2.0))

    )
    "_close"
    )
    )
    (princ "\nRien trouvé désolé pour vous !!!")
    )
    )
    )
    (setvar "osmode" oldos)
    (setvar "cmdecho" oce)
    (princ)
    )
     
    BTO, Jan 20, 2005
    #25
  6. Alan Henderson @ A'cad Solutions

    BillZ Guest

    BTO,
    Nice to have a mathematical solution.

    Thanks.

    Too bad it doesn't work if the width of the inside rectangle is specified to be 1/2 or more of the outside rectangle width.

    Bill
     
    BillZ, Jan 20, 2005
    #26
  7. Having had only one year of French, about 30 years ago, I'm not sure what's
    happening everywhere here, without plowing through all the code to figure
    out exactly what steps it's taking. But it looks like another
    trial-and-error approach, because of:
    which looks like repeatedly comparing to a very small distance, rather than
    calculating an absolute answer.

    [I also wonder whether it's usable for the original post's purposes, because
    of:
    which looks like it's asking for the diagonal, rather than the width, of the
    inner rectangle.]

    I'm still [pipe-]dreaming of a purely mathematical solution....

    Kent Cooper, AIA


    ----- Original Message -----
    From: "BTO"
     
    Kent Cooper, AIA, Jan 20, 2005
    #27
  8. Alan Henderson @ A'cad Solutions

    BillZ Guest

    I also wonder whether it's usable for the original post's purposes, because
    of:
    which looks like it's asking for the diagonal, rather than the width, of the
    inner rectangle.]<<<

    Yes, You pick the LL & UR corners and then give a width of the end of inside rectangle desired.
    If you put in 1/2 or more of the outside rectangle end width, the message says "can't find, feels bad" or something like that.
    I'm 1/2 French but never learned the language. :)
    I'm still [pipe-]dreaming of a purely mathematical solution....<<

    Me too.

    Bill
     
    BillZ, Jan 20, 2005
    #28
  9. BTO,
    Thanks for finding this routine. It actually produces the results I was
    wanted with the interior angles of the inner rectangle at 90 degrees. I'm
    working on something else right now, so it will be a week or so before I can
    follow the math. Thanks to all who looked into this problem.
    Alan
     
    Alan Henderson @ A'cad Solutions, Jan 20, 2005
    #29
  10. Based on the common interest of this, I passed the problem to MathCad
    discussion Forum.
    There has come out two solutions since now ( 30.1.2005).
    Interested persons can join the Collaboratory at www.mathcad.com and check
    them.

    It is there on the Puzzles & Games section under the name SquareInsideSquare
    ( wrong name actually ).

    Regards Matti
     
    Matti Pitkänen, Jan 30, 2005
    #30
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.