Author Topic: Make a pline rectang points with start point lower left.  (Read 544 times)

0 Members and 1 Guest are viewing this topic.

BIGAL

  • Swamp Rat
  • Posts: 1097
  • 40 + years of using Autocad
Make a pline rectang points with start point lower left.
« on: November 16, 2022, 12:15:49 AM »
If you look at rectangs there are various answers to the 1st point of the vertices. The obvious is wether its CCW or CW that I can handle, a rectang can be copied, rotated or mirrored moving the 1st vertice point from lower left, yes I know bounding box would help I am worried the task will though throw non ortho rectangs into the mix at a later stage. 

Same rectang
(setq lst1 '((3240.0 1074.0) (3440.0 1074.0) (3440.0 1174.0) (3240.0 1174.0)))
(setq lst2 '((3704.0 1074.0) (3504.0 1074.0) (3504.0 1174.0) (3704.0 1174.0))) ; mirror y
(setq lst3 '((3240.0 1290.0) (3440.0 1290.0) (3440.0 1190.0) (3240.0 1190.0))) ; Mirror x
(setq lst4 '((3540.0 1470.0) (3540.0 1270.0) (3440.0 1270.0) (3440.0 1470.0))) ; Rotate 90

I need to get always the left side and top for dimensioning hence point order, use pt1-pt2, pt2-pt3 etc was hoping for a rotate points type function.
A man who never made a mistake never made anything

kdub

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 1509
  • class keyThumper<T>:ILazy<T>
Re: Make a pline rectang points with start point lower left.
« Reply #1 on: November 16, 2022, 01:44:04 AM »
Hi BIGAL,

Perhaps try something based on these.

Code - Auto/Visual Lisp: [Select]
  1. ;;;------------------------------------------------------------------
  2. ;;;------------------------------------------------------------------
  3. ;;;
  4. ;;; min max X Y Z
  5.  
  6. (defun kdub:ptxy (pt) (list (car pt) (cadr pt)))
  7. (defun kdub:ptx (pt) (car pt))
  8. (defun kdub:pty (pt) (cadr pt))
  9. (defun kdub:ptz (pt) (caddr pt))
  10.  
  11. (defun kdub:minx (pointlist)
  12.         (apply (function min) (mapcar (function car) pointlist))
  13. )
  14. (defun kdub:miny (pointlist)
  15.         (apply (function min) (mapcar (function cadr) pointlist))
  16. )
  17. (defun kdub:minz (pointlist)
  18.         (apply (function min) (mapcar (function caddr) pointlist))
  19. )
  20.  
  21. (defun kdub:maxx (pointlist)
  22.         (apply (function max) (mapcar (function car) pointlist))
  23. )
  24. (defun kdub:maxy (pointlist)
  25.         (apply (function max) (mapcar (function cadr) pointlist))
  26. )
  27. (defun kdub:maxz (pointlist)
  28.         (apply (function max) (mapcar (function caddr) pointlist))
  29. )
  30.  
  31. ;;; min XY max XY
  32. (defun kdub:minxy       (pointlist)
  33.         (list (kdub:minx pointlist) (kdub:miny pointlist))
  34. )
  35. (defun kdub:maxxy       (pointlist)
  36.         (list (kdub:maxx pointlist) (kdub:maxy pointlist))
  37. )
  38.  
  39. ;;; min XYZ max XYZ
  40. (defun kdub:minxyz (pointlist)
  41.         (list   (kdub:minx pointlist)
  42.                                 (kdub:miny pointlist)
  43.                                 (kdub:minz pointlist)
  44.         )
  45. )
  46. (defun kdub:maxxyz (pointlist)
  47.         (list   (kdub:maxx pointlist)
  48.                                 (kdub:maxy pointlist)
  49.                                 (kdub:maxz pointlist)
  50.         )
  51. )
  52.  
  53. ;;;--------------------------------------------------------------------
  54.  


Then :

Code - Auto/Visual Lisp: [Select]
  1. (SETQ TR (kdub:maxxy LST1))
  2. (SETQ LL (kdub:minxy LST1))
  3. (SETQ TL (list (kdub:ptx LL) (kdub:pty TR)))

Code: [Select]
(3440.0 1174.0)
(3240.0 1074.0)
(3240.0 1174.0)


added:
didn't know you used metric ?

added again:
DUH! you're a bit South of my old stomping ground.

Regards,

« Last Edit: November 16, 2022, 03:04:02 AM by kdub »
called Kerry in my other life

Sometimes the question is more important than the answer.

I don't really work crazy hours . . I just live at UTC + 13.00
#ridesober

kdub

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 1509
  • class keyThumper<T>:ILazy<T>
Re: Make a pline rectang points with start point lower left.
« Reply #2 on: November 16, 2022, 02:42:31 AM »
This is where the minX, minY etc  functions come into use.

Just takes a few logic traps to determine your dimension points  and rotations :)

called Kerry in my other life

Sometimes the question is more important than the answer.

I don't really work crazy hours . . I just live at UTC + 13.00
#ridesober

kdub

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 1509
  • class keyThumper<T>:ILazy<T>
Re: Make a pline rectang points with start point lower left.
« Reply #3 on: November 16, 2022, 02:55:09 AM »
FWIW , these functions can be used on any sized collection

Code - Auto/Visual Lisp: [Select]
  1. (setq lst5 '((3240.0 1074.0) (3440.0 1074.0) (100.0 500.0) (3240.0 1174.0) (2100.0 3500.0)) )
  2.  
  3. (kdub:minx lst5) ;=> 100
  4. (kdub:miny lst5) ;=> 500
  5. (kdub:maxx lst5) ;=> 3440
  6. (kdub:maxy lst5) ;=> 3500
  7.  
  8.  

added:
Just realised this was in a challenge forum.
Sorry about that :)
« Last Edit: November 16, 2022, 03:06:07 AM by kdub »
called Kerry in my other life

Sometimes the question is more important than the answer.

I don't really work crazy hours . . I just live at UTC + 13.00
#ridesober

dexus

  • Newt
  • Posts: 85
Re: Make a pline rectang points with start point lower left.
« Reply #4 on: November 16, 2022, 03:27:28 AM »
How about something like this.
I find the corner item with a sort function, and then just rotate until it is the first item. The coordinates should be in the correct order that way.
Code - Auto/Visual Lisp: [Select]
  1. (defun rotate-rectange (lst / corner)
  2.   (setq corner ; find left most corner with a sort
  3.     (car
  4.       (vl-sort lst
  5.         (function
  6.           (lambda (a b)
  7.             (if (equal (car a) (car b) 1e-4)
  8.               (< (cadr a) (cadr b))
  9.               (< (car a) (car b))
  10.             )
  11.           )
  12.         )
  13.       )
  14.     )
  15.   )
  16.   (while (/= (car lst) corner) ; rotate until corner is the first item
  17.     (setq lst (append (cdr lst) (list (car lst))))
  18.   )
  19.   lst ; return lst
  20. )
  21.  
  22. (rotate-rectange '((3240.0 1074.0) (3440.0 1074.0) (3440.0 1174.0) (3240.0 1174.0)))

BIGAL

  • Swamp Rat
  • Posts: 1097
  • 40 + years of using Autocad
Re: Make a pline rectang points with start point lower left.
« Reply #5 on: November 16, 2022, 05:24:14 PM »
Thank you dexus that was the idea I had to rotate the points. I will test some more, I had a quick go and will add the CW or CCW check 1st then get co-ordinates. As that may be influencing result but looks promising.
A man who never made a mistake never made anything