Author Topic: CHALLENGE : Rectangles  (Read 21577 times)

0 Members and 1 Guest are viewing this topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: CHALLENGE : Rectangles
« Reply #15 on: September 22, 2006, 05:07:02 AM »
Here's a teaser ...

I'll post my solution on later  ...

« Last Edit: September 23, 2006, 10:17:26 PM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: CHALLENGE : Rectangles
« Reply #16 on: September 22, 2006, 10:51:56 AM »
I took a shot at it. See crewed attempt below.

Limitations:
WCS only, Outer Rectangle parallel with X/Y
Side to be found < (/ height 2), I could overcome this with more code.


Method:
Draw a circle & check chord length where it intersects the outer rectangle.
 Keep adjusting radius until Chord length matches desired side.


<edit: Length =987.14773556>

Code: [Select]
(defun c:test (/ ang chord cir dis doc e1 e2 h p1 p2 p3 pc pc1 pc2 pc3 pc4 px rad
               side side2 space step tar w fuzz get_inter group_on3
              )


  ;;  test values
  (setq p1   '(-1000 1000 0) ; Lower Left Corner
        w    1000
        h    500
        side 200
        fuzz 0.0001 ; side match tolerance
  )


  ;;  get the intersect list, then return the closest point to pt
  (defun get_inter (ent1 ent2 pt / plist result)
    (setq plist
           (vl-catch-all-apply
             'vlax-safearray->list
             (list (vlax-variant-value (vla-intersectwith ent1 ent2 acextendnone)))
           )
    )
    (setq plist (group_on3 plist))
    (foreach x plist
      (cond
        ((null result)
         (setq result x)
        )
        ((> (distance pt result) (distance pt x))
         (setq result x)
        )
      )
    )
    result
  )

  (defun group_on3 (inplst / outlst tmp grp idx sub)
    (while inplst
      (setq outlst (cons (list (car inplst) (cadr inplst) (caddr inplst)) outlst))
      (setq inplst (cdddr inplst))
    )
    outlst
  )


  ;;======================================================================

  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (setq space
         (if (zerop (vla-get-activespace doc))
           (if (= (vla-get-mspace doc) :vlax-true)
             (vla-get-modelspace doc) ; active VP
             (vla-get-paperspace doc)
           )
           (vla-get-modelspace doc)
         )
  )

  ;;  draw limit lines
  (setq chord 0
        p2    (polar p1 0 w)
        p3    (polar p2 (/ pi 2) h)
        pc    (polar p1 (angle p1 p3) (/ (distance p1 p3) 2.))
  )
  (setq e1 (vla-addline space (vlax-3d-point p1) (vlax-3d-point p2)))
  (setq e2 (vla-addline space (vlax-3d-point p2) (vlax-3d-point p3)))
  (if (> h w)
    (setq tar e1)
    (setq tar e2)
  )

 
  ;;  get chord location to match side length
  (setq rad  (+ (distance pc (vlax-curve-getclosestpointto tar pc)) 0.1)
        step (- (distance pc p2) rad)
  )
  (while (progn
           (setq cir (vla-addcircle space (vlax-3d-point pc) rad))
           (setq pc1 (get_inter e1 cir p2)
                 pc2 (get_inter e2 cir p2)
           )
           (setq dis  (distance pc1 pc2)
                 step (/ step 2)
           )
           (vla-delete cir)
           (cond
             ((equal dis side fuzz)
              nil
             )
             ((> dis side)
              (setq rad (+ rad step))
             )
             (t
              (setq rad (- rad step))
             )
           )
         )
  )

  ;;  Draw the rectangle
  (setq e1 (vla-addline space (vlax-3d-point pc1) (vlax-3d-point pc2)))
  (setq px (vlax-curve-getclosestpointto e1 pc))
  (setq side2 (* (distance pc px) 2)
        ang   (angle px pc)
  )
  (setq pc3 (polar pc2 ang side2)
        pc4 (polar pc1 ang side2)
  )
  (vla-addline space (vlax-3d-point pc1) (vlax-3d-point pc4))
  (vla-addline space (vlax-3d-point pc2) (vlax-3d-point pc3))
  (vla-addline space (vlax-3d-point pc3) (vlax-3d-point pc4))

 
  (vlax-release-object e1)
  (vlax-release-object cir)
  (vlax-release-object space)
  (vlax-release-object doc)
  (princ)
)
« Last Edit: September 22, 2006, 05:35:06 PM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Swift

  • Swamp Rat
  • Posts: 596
Re: CHALLENGE : Rectangles
« Reply #17 on: September 22, 2006, 02:50:26 PM »
I'm uploading my solution to http://www.survey-this.com/KerryBrownRectangles.htm

I solved it using a mixture of least squares adjustment routines. The math isn't well noted but if anyone is interested I will try to explain it.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: CHALLENGE : Rectangles
« Reply #18 on: September 22, 2006, 03:14:46 PM »
I'm uploading my solution to http://www.survey-this.com/KerryBrownRectangles.htm

I solved it using a mixture of least squares adjustment routines. The math isn't well noted but if anyone is interested I will try to explain it.
I tried to see what you did, but all the pictures looked like they had broken links.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Swift

  • Swamp Rat
  • Posts: 596
Re: CHALLENGE : Rectangles
« Reply #19 on: September 22, 2006, 03:21:45 PM »
They work on my machine, give it another try.

Here is a sketch to accompany the math


T.Willey

  • Needs a day job
  • Posts: 5251
Re: CHALLENGE : Rectangles
« Reply #20 on: September 22, 2006, 03:33:27 PM »
Still doesn't work for me.  Maybe I'm special??  :-)

See attached.

Edit:  Removed picture as the problem got solved.
« Last Edit: September 22, 2006, 03:57:24 PM by T.Willey »
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Swift

  • Swamp Rat
  • Posts: 596
Re: CHALLENGE : Rectangles
« Reply #21 on: September 22, 2006, 03:37:02 PM »
Looks like you'll have to use explorer, it wont open in Firefox for me.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: CHALLENGE : Rectangles
« Reply #22 on: September 22, 2006, 03:56:15 PM »
Looks like you'll have to use explorer, it wont open in Firefox for me.
You are correct.  I right clicked on it, and used 'Open Link in IE Tab', and it worked with firefox.  Will look at it later today.  Thanks for posting it.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: CHALLENGE : Rectangles
« Reply #23 on: September 22, 2006, 05:02:32 PM »
I'm uploading my solution to http://www.survey-this.com/KerryBrownRectangles.htm

I solved it using a mixture of least squares adjustment routines. The math isn't well noted but if anyone is interested I will try to explain it.

Holy equations David !! ....

I knew I should have done more than 3 years high school ... :-)

There is a beauty to that, even if I don't understand it ..
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: CHALLENGE : Rectangles
« Reply #24 on: September 22, 2006, 05:07:14 PM »
... but it looks like we both have the same solution, out to 7 decimal places
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: CHALLENGE : Rectangles
« Reply #25 on: September 22, 2006, 05:51:06 PM »
Wow Swift quite a piece of work. Sorry to say I don't understand it. Maybe in my next life. :-)

I had to change my fuzz factor to get that close.

fuzz = 0.0001
Count = 23
Length =987.14773556

fuzz = 0.00001
Count = 26
Length =987.14774210
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: CHALLENGE : Rectangles
« Reply #26 on: September 22, 2006, 05:57:36 PM »
Nice construction technique Alan ..
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Swift

  • Swamp Rat
  • Posts: 596
Re: CHALLENGE : Rectangles
« Reply #27 on: September 22, 2006, 06:05:57 PM »
That stuff was brow beat into me over two semesters in college. At the time I thought it was a waste, of course, but I have found many uses for it over the years. I've used it for everything from closing survey loops to adjusting gps observations and like in this case fitting odd geometry.

I used the same method, different equations though, with Cornbread to write some neat coordinate transformation stuff. Sadly though I've never been able to get a routine in vb to work, but I have several c++ routines for this sort of thing.

If the forecast for a soggy weekend holds true I'll add some notes to that, I might even be able to squeeze an article out of it.




T.Willey

  • Needs a day job
  • Posts: 5251
Re: CHALLENGE : Rectangles
« Reply #28 on: September 22, 2006, 06:08:27 PM »
If the forecast for a soggy weekend holds true I'll add some notes to that, I might even be able to squeeze an article out of it.
That would be sweet, for us.  But I hope your weekend is nice, and are able to play outside.   :-D
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: CHALLENGE : Rectangles
« Reply #29 on: September 22, 2006, 06:17:19 PM »
Is it fast David ? There seems to be a lot of heavy duty exponent calcs being done.

... not that speed is really an issue !

Just rechecked my attempt .. it contains a significant quantity of exponent calcs as well ...
... no options when dealing with Pythagoras  :-)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.