Author Topic: ==={Challenge}=== Broken Pieces  (Read 7445 times)

0 Members and 1 Guest are viewing this topic.

pBe

  • Bull Frog
  • Posts: 377
Re: ==={Challenge}=== Broken Pieces
« Reply #15 on: June 18, 2013, 05:55:27 AM »
Like i said "regular" jigsaw puzzles doesn't have "EDGE-LIKE" piece on the middle part of the board.
You are taking this challenge to another level :lmao: .

There too many common angles and UCS and all.
And that tile thingy? butted against each other? yeahh.. you know what i mean MR.

BTW: Are you going to modify your code to actually solve the jigsaw?

ribarm

  • Water Moccasin
  • Posts: 2226
  • Marko Ribar, architect
Re: ==={Challenge}=== Broken Pieces
« Reply #16 on: June 18, 2013, 06:53:35 AM »
Like i said "regular" jigsaw puzzles doesn't have "EDGE-LIKE" piece on the middle part of the board.
You are taking this challenge to another level :lmao: .

There too many common angles and UCS and all.
And that tile thingy? butted against each other? yeahh.. you know what i mean MR.

BTW: Are you going to modify your code to actually solve the jigsaw?

This puzzle is too complicated for my mind... I was just trying to dissect problem to basics (finding corners), but now as CAD isn't calculating correctly 4th corner with rotated UCS for checking upper-left piece, I am starting to loose patience... Still I am not good prepared for jigsaw challenge... If you can use my research, go ahead, you're welcome - this was my intention in the first place, but now I am seeing to many possibilities for this kind of task... And if I knew how to write jigsaw, still I think it wouldn't be totally applicable for all kind of situations... Still congratulate to all who even tries this challenge...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

pBe

  • Bull Frog
  • Posts: 377
Re: ==={Challenge}=== Broken Pieces
« Reply #17 on: June 18, 2013, 06:59:52 AM »
No worries Marko. just curious is all.


Thank you for your input MR.
Cheers


Lee Mac

  • Seagull
  • Posts: 12313
  • London, England
Re: ==={Challenge}=== Broken Pieces
« Reply #18 on: June 18, 2013, 07:20:36 AM »
Lee. I finally got the chance to try your code, I'm still at awe how were you able to write the code with very few lines. [how did you manage that?]

 :-)

I notice there are four pieces although connected to each other did not position itself correctly on the board. or is it just me.

Indeed, it is not a complete solution since I am only comparing the interior angles of pairs of pieces, and not groups of 3, 4, 5,...,n pieces. The ambiguity in the position of the last four pieces arises because I am comparing the outer angles of the edge pieces (i.e. testing for summation to pi radians, rather than 2pi), and several positions will pass this test.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1542
  • Moscow (Russia)
Re: ==={Challenge}=== Broken Pieces
« Reply #19 on: June 18, 2013, 11:49:00 AM »
my version:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ A A1 A2 B D L V V1)
  2.   (setq a1 (ssget)
  3.         l  (mapcar (function (lambda (b)
  4.                                (mapcar (function list)
  5.                                        (mapcar (function (lambda (a) (car b))) (cdr b))
  6.                                        (cdr b)
  7.                                        (cons (last b) (cdr b))
  8.                                )
  9.                              )
  10.                    )
  11.                    (mapcar (function (lambda (b)
  12.                                        (cons b
  13.                                              (vl-remove nil
  14.                                                         (mapcar (function (lambda (a)
  15.                                                                             (if (= (car a) 10)
  16.                                                                               (cdr a)
  17.                                                                             )
  18.                                                                           )
  19.                                                                 )
  20.                                                                 (entget b)
  21.                                                         )
  22.                                              )
  23.                                        )
  24.                                      )
  25.                            )
  26.                            (vl-remove-if (function listp) (mapcar (function cadr) (ssnamex a1)))
  27.                    )
  28.            )
  29.         a1 nil
  30.         a2 nil
  31.         a  (car l)
  32.         l  (cdr l)
  33.   )
  34.   (while (and a l)
  35.     (progn
  36.       (setq b (car a)
  37.             v (mapcar (function -) (caddr b) (cadr b))
  38.       )
  39.       (foreach c l
  40.         (if (setq d (car (vl-member-if
  41.                            (function (lambda (d)
  42.                                        (equal v (mapcar (function -) (cadr d) (caddr d)) 1e-6)
  43.                                      )
  44.                            )
  45.                            c
  46.                          )
  47.                     )
  48.             )
  49.           (progn
  50.             (setq a2 (car (vl-remove-if-not (function (lambda (a) (assoc (car d) a))) l))
  51.                   v1 (mapcar (function -) (caddr d) (cadr b))
  52.                   a1 (vl-remove d
  53.                                 (append a1
  54.                                         (mapcar (function
  55.                                                   (lambda (a)
  56.                                                     (list (car a) (mapcar (function -) (cadr a) v1) (mapcar (function -) (caddr a) v1))
  57.                                                   )
  58.                                                 )
  59.                                                 a2
  60.                                         )
  61.                                 )
  62.                      )
  63.             )
  64.             (vla-move (vlax-ename->vla-object (car d)) (vlax-3d-point (caddr d)) (vlax-3d-point (cadr b)))
  65.             (setq l (vl-remove a2 l))
  66.           )
  67.         )
  68.       )
  69.       (if a1
  70.         (setq a  (append (cdr a) a1)
  71.               a1 nil
  72.         )
  73.         (setq a (cdr a))
  74.       )
  75.     )
  76.   )
  77. )
蝸牛そろそろ登れ富士の山 /Kobayashi Issa/

ribarm

  • Water Moccasin
  • Posts: 2226
  • Marko Ribar, architect
Re: ==={Challenge}=== Broken Pieces
« Reply #20 on: June 18, 2013, 12:06:16 PM »
I've updated my codes - in my last version I used (ssdel) function consequently and didn't realize that I have to do (ssadd) after to preserve selection set as it was... This is why it hadn't highlighted 4th piece (upper-left)...

I apologize for this inconvenience...

Marko R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Water Moccasin
  • Posts: 2226
  • Marko Ribar, architect
Re: ==={Challenge}=== Broken Pieces
« Reply #21 on: June 18, 2013, 12:24:43 PM »
my version:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ A A1 A2 B D L V V1)
  2.   (setq a1 (ssget)
  3.         l  (mapcar (function (lambda (b)
  4.                                (mapcar (function list)
  5.                                        (mapcar (function (lambda (a) (car b))) (cdr b))
  6.                                        (cdr b)
  7.                                        (cons (last b) (cdr b))
  8.                                )
  9.                              )
  10.                    )
  11.                    (mapcar (function (lambda (b)
  12.                                        (cons b
  13.                                              (vl-remove nil
  14.                                                         (mapcar (function (lambda (a)
  15.                                                                             (if (= (car a) 10)
  16.                                                                               (cdr a)
  17.                                                                             )
  18.                                                                           )
  19.                                                                 )
  20.                                                                 (entget b)
  21.                                                         )
  22.                                              )
  23.                                        )
  24.                                      )
  25.                            )
  26.                            (vl-remove-if (function listp) (mapcar (function cadr) (ssnamex a1)))
  27.                    )
  28.            )
  29.         a1 nil
  30.         a2 nil
  31.         a  (car l)
  32.         l  (cdr l)
  33.   )
  34.   (while (and a l)
  35.     (progn
  36.       (setq b (car a)
  37.             v (mapcar (function -) (caddr b) (cadr b))
  38.       )
  39.       (foreach c l
  40.         (if (setq d (car (vl-member-if
  41.                            (function (lambda (d)
  42.                                        (equal v (mapcar (function -) (cadr d) (caddr d)) 1e-6)
  43.                                      )
  44.                            )
  45.                            c
  46.                          )
  47.                     )
  48.             )
  49.           (progn
  50.             (setq a2 (car (vl-remove-if-not (function (lambda (a) (assoc (car d) a))) l))
  51.                   v1 (mapcar (function -) (caddr d) (cadr b))
  52.                   a1 (vl-remove d
  53.                                 (append a1
  54.                                         (mapcar (function
  55.                                                   (lambda (a)
  56.                                                     (list (car a) (mapcar (function -) (cadr a) v1) (mapcar (function -) (caddr a) v1))
  57.                                                   )
  58.                                                 )
  59.                                                 a2
  60.                                         )
  61.                                 )
  62.                      )
  63.             )
  64.             (vla-move (vlax-ename->vla-object (car d)) (vlax-3d-point (caddr d)) (vlax-3d-point (cadr b)))
  65.             (setq l (vl-remove a2 l))
  66.           )
  67.         )
  68.       )
  69.       (if a1
  70.         (setq a  (append (cdr a) a1)
  71.               a1 nil
  72.         )
  73.         (setq a (cdr a))
  74.       )
  75.     )
  76.   )
  77. )

Wonderful, it works!!! In most cases it's truly correct...

Thanks, EEA...
 :-) :-) :-) :-) :-) :-) :-) :-) :-) :-) :-) :-) :-) :-) :-) :-) :-) :-)
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1542
  • Moscow (Russia)
Re: ==={Challenge}=== Broken Pieces
« Reply #22 on: June 18, 2013, 01:39:27 PM »
Wonderful, it works!!! In most cases it's truly correct...

Thanks, EEA...
 :-) :-) :-) :-) :-) :-) :-) :-) :-) :-) :-) :-) :-) :-) :-) :-) :-) :-)

Thank you!
蝸牛そろそろ登れ富士の山 /Kobayashi Issa/

Lee Mac

  • Seagull
  • Posts: 12313
  • London, England
Re: ==={Challenge}=== Broken Pieces
« Reply #23 on: June 18, 2013, 01:58:11 PM »
Matching edges instead of vertices - good method Evgeniy  :-)

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1542
  • Moscow (Russia)
Re: ==={Challenge}=== Broken Pieces
« Reply #24 on: June 18, 2013, 02:03:19 PM »
Matching edges instead of vertices - good method Evgeniy  :-)

Yes, if all the edges of different lengths
蝸牛そろそろ登れ富士の山 /Kobayashi Issa/

ribarm

  • Water Moccasin
  • Posts: 2226
  • Marko Ribar, architect
Re: ==={Challenge}=== Broken Pieces
« Reply #25 on: June 18, 2013, 03:02:46 PM »
And that tile thingy? butted against each other? yeahh.. you know what i mean MR.

So sel. sets were the problem with my codes...
Except this case pBe, at least and if it find wrong piece it won't break now...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

dgorsman

  • Water Moccasin
  • Posts: 2402
Re: ==={Challenge}=== Broken Pieces
« Reply #26 on: June 18, 2013, 03:31:03 PM »
Matching edges instead of vertices - good method Evgeniy  :-)

Yes, if all the edges of different lengths

That was my initial thought of attack as well.  Could probably extend that to handle adjoining edges, which would reduce the possibilities to a very low numbers.  If its pattern-broken like a jigsaw puzzle cutter I'm thinking it would be very difficult to get everything back together without some other qualifier.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

ribarm

  • Water Moccasin
  • Posts: 2226
  • Marko Ribar, architect
Re: ==={Challenge}=== Broken Pieces
« Reply #27 on: June 18, 2013, 06:05:14 PM »
My codes on page 1 finally updated...

Regards, M.R. :-) :-) :-)
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

LE3

  • Guest
Re: ==={Challenge}=== Broken Pieces
« Reply #28 on: June 18, 2013, 10:42:28 PM »
Code - C#: [Select]
  1. [CommandMethod("TOGETHER")]
  2. public void cmd_together()
  3. {
  4.     var e = AcadApp.DocumentManager.MdiActiveDocument.Editor;
  5.     var tv = new TypedValue[] { new TypedValue((int)DxfCode.Start, "LWPOLYLINE") };
  6.     var filter = new SelectionFilter(tv);
  7.     var options = new PromptSelectionOptions();
  8.     options.MessageForAdding = "\nAdd PolyLine(s) to selection";
  9.     options.MessageForRemoval = "\nRemove PolyLine(s) from selection";
  10.     options.AllowDuplicates = false;
  11.     options.RejectObjectsFromNonCurrentSpace = true;
  12.     var psr = e.GetSelection(options, filter);
  13.     if (psr.Status != PromptStatus.OK) return;
  14.     double delta = 0.0000001;
  15.     using (var tr = e.Document.Database.TransactionManager.StartTransaction())
  16.     {
  17.         var ids = psr.Value.GetObjectIds();
  18.         foreach (var id in ids)
  19.         {
  20.             var polyline = (Polyline)tr.GetObject(id, OpenMode.ForWrite, false);
  21.             for (int i = 0; i < polyline.NumberOfVertices; i++)
  22.             {
  23.                 var line = polyline.GetLineSegmentAt(i);
  24.                 var found = false;
  25.                 foreach (var _id in ids)
  26.                 {
  27.                     var _polyline = (Polyline)tr.GetObject(_id, OpenMode.ForWrite, false);
  28.                     if (_polyline == polyline) continue;
  29.                     for (int ii = 0; ii < _polyline.NumberOfVertices; ii++)
  30.                     {
  31.                         var _line = _polyline.GetLineSegmentAt(ii);
  32.                         if (Math.Abs(line.Length - _line.Length) < delta)
  33.                         {
  34.                             var m = Matrix3d.Displacement(line.MidPoint - _line.MidPoint);
  35.                             _polyline.TransformBy(m);
  36.                             found = true;
  37.                             break;
  38.                         }
  39.                     }
  40.                     if (found) break;
  41.                 }
  42.             }
  43.         }
  44.         tr.Commit();
  45.     }
  46. }
The above will put together the shapes.-

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: ==={Challenge}=== Broken Pieces
« Reply #29 on: June 18, 2013, 11:50:29 PM »
my version:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ A A1 A2 B D L V V1)
  2.   <...>
  3.  
  4. )

Smart bit of code Evgeniy :)
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--