Author Topic: Upper Left Corner  (Read 2922 times)

0 Members and 1 Guest are viewing this topic.

cmwade77

  • Swamp Rat
  • Posts: 1447
Upper Left Corner
« on: July 26, 2011, 06:50:53 PM »
Alright, I know I am probably just missing it in my searches and I know I should be able program it fairly easily, but I have been staring at code for the majority of the day today and I am drawing a blank as a result.
So, I am wondering if any of you out there have a routine that you could share to find where the upper left corner of a set of two coordinates (i.e Pt1 and Pt2) is at. I would greatly appreciate it.
« Last Edit: July 26, 2011, 06:59:27 PM by cmwade77 »

Lee Mac

  • Seagull
  • Posts: 12927
  • London, England
Re: Upper Left Corner
« Reply #1 on: July 26, 2011, 07:00:27 PM »
Code: [Select]
(apply 'mapcar (cons 'max (list p1 p2)))

cmwade77

  • Swamp Rat
  • Posts: 1447
Re: Upper Left Corner
« Reply #2 on: July 26, 2011, 07:01:15 PM »
Thank you, I was drawing a major blank, I know I have had something similar in my code, but I couldn't find it there either.

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Upper Left Corner
« Reply #3 on: July 26, 2011, 07:08:15 PM »
I think Lee's code will give you upper right corner.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12927
  • London, England
Re: Upper Left Corner
« Reply #4 on: July 26, 2011, 07:17:07 PM »
I think Lee's code will give you upper right corner.

Oops! yes it will! I should learn to read  :cry:

Not as elegant:

Code: [Select]
(list
  (min (car  p1) (car  p2))
  (max (cadr p1) (cadr p2))
  (caddr p1)
)
« Last Edit: July 26, 2011, 07:24:48 PM by Lee Mac »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Upper Left Corner
« Reply #5 on: July 26, 2011, 07:38:45 PM »
Another one
Code: [Select]
(list
  (apply 'min (mapcar 'car (list p1 p2)))
  (apply 'max (mapcar 'cadr (list p1 p2)))
)
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.

LE3

  • Guest
Re: Upper Left Corner
« Reply #6 on: July 26, 2011, 08:10:31 PM »
?
(setq p (list (car p1) (cadr p2) (caddr p1)))

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Upper Left Corner
« Reply #7 on: July 26, 2011, 09:54:38 PM »
Code: [Select]
(apply 'mapcar (cons 'max (list p1 p2)))

Code: [Select]
(apply 'mapcar (list 'max p1 p2))
Code: [Select]
(mapcar 'max p1 p2)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Upper Left Corner
« Reply #8 on: July 26, 2011, 10:22:45 PM »
OK, Upper Left  8-)
Code: [Select]
(list
  (car  (mapcar 'min p1 p2))
  (cadr (mapcar 'max p1 p2))
)
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.

Lee Mac

  • Seagull
  • Posts: 12927
  • London, England
Re: Upper Left Corner
« Reply #9 on: July 27, 2011, 06:48:08 AM »
Code: [Select]
(apply 'mapcar (cons 'max (list p1 p2)))

Code: [Select]
(apply 'mapcar (list 'max p1 p2))
Code: [Select]
(mapcar 'max p1 p2)

I like the thought progression!  :lol:

Lee Mac

  • Seagull
  • Posts: 12927
  • London, England
Re: Upper Left Corner
« Reply #10 on: July 27, 2011, 06:49:47 AM »
?
(setq p (list (car p1) (cadr p2) (caddr p1)))

Not if p1 has a greater x-value than p2, or similarly if p2 has a smaller y-value than p1...

Lee Mac

  • Seagull
  • Posts: 12927
  • London, England
Re: Upper Left Corner
« Reply #11 on: July 27, 2011, 07:35:45 AM »
Another variation...

Bottom Right & Upper Left:

Code: [Select]
(mapcar 'apply '(max min max) (mapcar 'list p1 p2))
(mapcar 'apply '(min max min) (mapcar 'list p1 p2))

All four:

Code: [Select]
(
  (lambda ( a )
    (mapcar '(lambda ( b ) (mapcar 'apply b a))
     '(
        (min min min)
        (max min max)
        (max max max)
        (min max min)
      )
    )
  )
  (mapcar 'list p1 p2)
)


SOFITO_SOFT

  • Guest
Re: Upper Left Corner
« Reply #12 on: July 27, 2011, 12:06:31 PM »
for a list of any number of points:
Code: [Select]
Command: ( setq lista ( list '( 10 -1 2 ) '( 34 -54 56 ) '( 34 55.6 56 )))
((10 -1 2) (34 -54 56) (34 55.6 56))
Command: ( list
(_>   ( list ( apply 'min ( mapcar 'car lista ) )
((_>          ( apply 'min ( mapcar 'cadr lista ) )
((_>   )
(_>   ( list ( apply 'max ( mapcar 'car lista ) )
((_>          ( apply 'max ( mapcar 'cadr lista ) )
((_>   )
(_> )
((10 -54.0) (34 55.6))
Greetings

Lee Mac

  • Seagull
  • Posts: 12927
  • London, England
Re: Upper Left Corner
« Reply #13 on: July 27, 2011, 12:33:49 PM »
For an arbitrary number of points I usually use:

Code: [Select]
(mapcar '(lambda ( a ) (apply 'mapcar (cons a <pointlist>))) '(min max))