Author Topic: Grid point list conversion  (Read 910 times)

0 Members and 1 Guest are viewing this topic.

Grrr1337

  • Swamp Rat
  • Posts: 735
Grid point list conversion
« on: September 11, 2020, 03:17:32 PM »
Hey guys,
Haven't been mapping lists for a while and now I'm banging my head on this one -

The following matrix list represents the grid point coordinates in the attached image:
Code: [Select]
'(
  ("1-1" "1-2" "1-3" "1-4" "1-5" "1-6" "1-7")
  ("2-1" "2-2" "2-3" "2-4" "2-5" "2-6" "2-7")
  ("3-1" "3-2" "3-3" "3-4" "3-5" "3-6" "3-7")
  ("4-1" "4-2" "4-3" "4-4" "4-5" "4-6" "4-7")
)

I need some help in writing a subfoo to convert it like so:
Code: [Select]
'(
  ("1-1" "1-2" "2-1" "2-2")
  ("1-2" "1-3" "2-2" "2-3")
  ("1-3" "1-4" "2-3" "2-4")
  ("1-4" "1-5" "2-4" "2-5")
  ("1-5" "1-6" "2-5" "2-6")
  ("1-6" "1-7" "2-6" "2-7")
  ("2-1" "2-2" "3-1" "3-2")
  ("2-2" "2-3" "3-2" "3-3")
  ("2-3" "2-4" "3-3" "3-4")
  ("2-4" "2-5" "3-4" "3-5")
  ("2-5" "2-6" "3-5" "3-6")
  ("2-6" "2-7" "3-6" "3-7")
  ("3-1" "3-2" "4-1" "4-2")
  ("3-2" "3-3" "4-2" "4-3")
  ("3-3" "3-4" "4-3" "4-4")
  ("3-4" "3-5" "4-4" "4-5")
  ("3-5" "3-6" "4-5" "4-6")
  ("3-6" "3-7" "4-6" "4-7")
)

The items in the new list represent the rectangular sectors of the whole grid.

(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)

MP

  • Seagull
  • Posts: 17686
  • Have thousands of dwgs to process? Contact me.
Re: Grid point list conversion
« Reply #1 on: September 11, 2020, 04:31:26 PM »
tired brain ... quick & dirty ... no hand holding ... assumes non jagged nested lists ... forgive me if it doesn't achieve what you want but it's been so long since I played ...

Code: [Select]
(defun subfoo ( lst / r a b c d )
    (repeat (1- (length lst))
        (repeat (1- (length (car (mapcar 'set '(a b) lst))))
            (setq r (cons (append (mapcar 'set '(c d) a) (mapcar 'set '(c d) b)) r))
            (mapcar 'set '(a b) (mapcar 'cdr (list a b)))
        )
        (setq lst (cdr lst))
    )
    (reverse r)
)

(subfoo yourlist)

(   ("1-1" "1-2" "2-1" "2-2")
    ("1-2" "1-3" "2-2" "2-3")
    ("1-3" "1-4" "2-3" "2-4")
    ("1-4" "1-5" "2-4" "2-5")
    ("1-5" "1-6" "2-5" "2-6")
    ("1-6" "1-7" "2-6" "2-7")
    ("2-1" "2-2" "3-1" "3-2")
    ("2-2" "2-3" "3-2" "3-3")
    ("2-3" "2-4" "3-3" "3-4")
    ("2-4" "2-5" "3-4" "3-5")
    ("2-5" "2-6" "3-5" "3-6")
    ("2-6" "2-7" "3-6" "3-7")
    ("3-1" "3-2" "4-1" "4-2")
    ("3-2" "3-3" "4-2" "4-3")
    ("3-3" "3-4" "4-3" "4-4")
    ("3-4" "3-5" "4-4" "4-5")
    ("3-5" "3-6" "4-5" "4-6")
    ("3-6" "3-7" "4-6" "4-7")
)


Engineering Technologist CAD Specialist Programmer Analyst
Design Drafting Document Control Automation.
cadanalyst@fastmail.com https://cadanalyst.slack.com http://linkedin.com/in/cadanalyst

ribarm

  • Water Moccasin
  • Posts: 2383
  • Marko Ribar, architect
Re: Grid point list conversion
« Reply #2 on: September 11, 2020, 04:53:21 PM »
Well, MP was faster and more elegant, but here is mine...

Code: [Select]
(defun c:recunfoldmatrix ( / matrix-n-m rec n m )

  (defun matrix-n-m ( n m / nn mm itm row mat )
    (setq nn 0)
    (repeat n
      (setq nn (1+ nn) mm 0)
      (repeat m
        (setq mm (1+ mm))
        (setq itm (strcat (itoa nn) "-" (itoa mm)))
        (setq row (cons itm row))
      )
      (setq mat (cons (reverse row) mat) row nil)
    )
    (reverse mat)
  )

  (defun rec ( mat / k itm1 itm2 kk lst )
    (setq k -1)
    (repeat (length mat)
      (setq k (1+ k))
      (setq itm1
        (vl-remove-if-not '(lambda ( x ) (= (length x) 2))
          (mapcar '(lambda ( x ) (setq kk (if (null kk) 2 (1+ kk))) (vl-remove-if-not '(lambda ( y ) (< (- kk 3) (vl-position y (nth k mat)) kk)) (nth k mat))) (nth k mat))
        )
      )
      (setq kk nil)
      (setq itm2
        (vl-remove-if-not '(lambda ( x ) (= (length x) 2))
          (mapcar '(lambda ( x ) (setq kk (if (null kk) 2 (1+ kk))) (vl-remove-if-not '(lambda ( y ) (< (- kk 3) (vl-position y (nth (1+ k) mat)) kk)) (nth (1+ k) mat))) (nth (1+ k) mat))
        )
      )
      (setq kk nil)
      (setq itm (mapcar '(lambda ( a b ) (append a b)) itm1 itm2))
      (setq lst (cons itm lst))
    )
    (apply 'append (reverse lst))
  )

  (initget 7)
  (setq n (getint "\nSpecify number of rows of matrix : "))
  (initget 7)
  (setq m (getint "\nSpecify number of columns of matrix : "))
  (princ "\n")
  (prin1 (rec (matrix-n-m n m)))
  (princ)
)

;|
Command: RECUNFOLDMATRIX

Specify number of rows of matrix : 4

Specify number of columns of matrix : 7

(("1-1" "1-2" "2-1" "2-2") ("1-2" "1-3" "2-2" "2-3") ("1-3" "1-4" "2-3" "2-4") ("1-4" "1-5" "2-4" "2-5") ("1-5" "1-6" "2-5" "2-6") ("1-6" "1-7" "2-6" "2-7") ("2-1" "2-2" "3-1" "3-2") ("2-2" "2-3" "3-2" "3-3") ("2-3" "2-4" "3-3" "3-4") ("2-4" "2-5" "3-4" "3-5") ("2-5" "2-6" "3-5" "3-6") ("2-6" "2-7" "3-6" "3-7") ("3-1" "3-2" "4-1" "4-2") ("3-2" "3-3" "4-2" "4-3") ("3-3" "3-4" "4-3" "4-4") ("3-4" "3-5" "4-4" "4-5") ("3-5" "3-6" "4-5" "4-6") ("3-6" "3-7" "4-6" "4-7"))
|;
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

VovKa

  • Swamp Rat
  • Posts: 1272
  • Ukraine
Re: Grid point list conversion
« Reply #3 on: September 11, 2020, 05:24:37 PM »
Code: [Select]
(defun f (lst)
  (setq lst (mapcar (function (lambda (e) (mapcar 'list e (cdr e)))) lst))
  (apply 'append (mapcar (function (lambda (e1 e2) (mapcar 'append e1 e2))) lst (cdr lst)))
)

MP

  • Seagull
  • Posts: 17686
  • Have thousands of dwgs to process? Contact me.
Re: Grid point list conversion
« Reply #4 on: September 11, 2020, 05:24:58 PM »
Won't last long -- once VovKa and Lee post it will look like it was written by Clumsy Carp ...  :-D
Engineering Technologist CAD Specialist Programmer Analyst
Design Drafting Document Control Automation.
cadanalyst@fastmail.com https://cadanalyst.slack.com http://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17686
  • Have thousands of dwgs to process? Contact me.
Re: Grid point list conversion
« Reply #5 on: September 11, 2020, 05:26:09 PM »
OMG check out the posting times of the last 2 posts.  :lol:
Engineering Technologist CAD Specialist Programmer Analyst
Design Drafting Document Control Automation.
cadanalyst@fastmail.com https://cadanalyst.slack.com http://linkedin.com/in/cadanalyst

ronjonp

  • Needs a day job
  • Posts: 7168
Re: Grid point list conversion
« Reply #6 on: September 11, 2020, 05:26:20 PM »
Here's another for fun :)
Code - Auto/Visual Lisp: [Select]
  1. (defun _rjpfoo (l / a b r)
  2.   (while (cadr l)
  3.     (setq a (car l)
  4.           b (cadr l)
  5.           l (cdr l)
  6.     )
  7.     (while (cadr a)
  8.       (setq r (cons (list (car a) (cadr a) (car b) (cadr b)) r)
  9.             a (cdr a)
  10.             b (cdr b)
  11.       )
  12.     )
  13.   )
  14.   (reverse r)
  15. )

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

MP

  • Seagull
  • Posts: 17686
  • Have thousands of dwgs to process? Contact me.
Re: Grid point list conversion
« Reply #7 on: September 11, 2020, 05:32:15 PM »
indeed - great participation all around - especially given it's a Friday afternoon (in the Americas) - fun thread !
Engineering Technologist CAD Specialist Programmer Analyst
Design Drafting Document Control Automation.
cadanalyst@fastmail.com https://cadanalyst.slack.com http://linkedin.com/in/cadanalyst

VovKa

  • Swamp Rat
  • Posts: 1272
  • Ukraine
Re: Grid point list conversion
« Reply #8 on: September 11, 2020, 05:38:18 PM »
especially given it's a Friday afternoon (in the Americas)
and even more especially it's half past midnight in Ukraine
omg what am i doing here :)

MP

  • Seagull
  • Posts: 17686
  • Have thousands of dwgs to process? Contact me.
Re: Grid point list conversion
« Reply #9 on: September 11, 2020, 05:42:50 PM »
omg what am i doing here :)

lol, nerdosis terminosis  :-D
Engineering Technologist CAD Specialist Programmer Analyst
Design Drafting Document Control Automation.
cadanalyst@fastmail.com https://cadanalyst.slack.com http://linkedin.com/in/cadanalyst

VovKa

  • Swamp Rat
  • Posts: 1272
  • Ukraine
Re: Grid point list conversion
« Reply #10 on: September 11, 2020, 05:47:52 PM »
nerdosis terminosis
wow, google just returned nil  :wideeyed2:

MP

  • Seagull
  • Posts: 17686
  • Have thousands of dwgs to process? Contact me.
Re: Grid point list conversion
« Reply #11 on: September 11, 2020, 05:49:54 PM »
Made up disease name: one who has a terminal case of being a nerd. 0.o
Engineering Technologist CAD Specialist Programmer Analyst
Design Drafting Document Control Automation.
cadanalyst@fastmail.com https://cadanalyst.slack.com http://linkedin.com/in/cadanalyst

VovKa

  • Swamp Rat
  • Posts: 1272
  • Ukraine
Re: Grid point list conversion
« Reply #12 on: September 11, 2020, 06:05:43 PM »
one day we could speak a little Latin
just like good old patricians ;)

Stefan

  • Bull Frog
  • Posts: 238
Re: Grid point list conversion
« Reply #13 on: September 11, 2020, 07:10:49 PM »
Code - Auto/Visual Lisp: [Select]
  1. (defun square (lst)
  2.     (mapcar
  3.      '(lambda (a b)
  4.         (mapcar 'list a (cdr a) b (cdr b))
  5.       )
  6.       lst
  7.       (cdr lst)
  8.     )
  9.   )
  10. )

bruno_vdh

  • Mosquito
  • Posts: 3
Re: Grid point list conversion
« Reply #14 on: September 11, 2020, 08:39:18 PM »
Hi,
In the same spirit as the solution given by stephan ...
Code - Auto/Visual Lisp: [Select]
  1. (defun f (l)
  2.   (if (cdr l)
  3.     (append (mapcar 'list (car l) (cdar l) (cadr l) (cdadr l))
  4.             (f (cdr l)))))
« Last Edit: September 11, 2020, 08:44:35 PM by bruno_vdh »