Sorting of points in X and Y coordinates

Sorting of points in X and Y coordinates

avinash00002002
Collaborator Collaborator
1,102 Views
9 Replies
Message 1 of 10

Sorting of points in X and Y coordinates

avinash00002002
Collaborator
Collaborator

Hi

I want to sorting of X Coordinates and Y coordinates as per my drawing. Delete Duplicate X-coords and Y-coords. 

 

I have attached drawing with dimensions.

 

Any Idea to sorting.

 

Coordinates:

((449.67 551.029 0.0) (504.882 551.029 0.0) (572.687 551.029 0.0) (449.67 505.052 0.0) (504.882 505.052 0.0) (572.687 505.052 0.0) (449.67 457.624 0.0) (504.882 457.624 0.0) (572.687 457.624 0.0) (449.67 410.679 0.0) (504.882 410.679 0.0) (572.687 410.679 0.0) (633.777 505.052 0.0) (688.989 505.052 0.0) (756.794 505.052 0.0) (633.777 457.624 0.0) (688.989 457.624 0.0) (756.794 457.624 0.0))

 

Thanks,

 

Avinash

0 Likes
1,103 Views
9 Replies
Replies (9)
Message 2 of 10

ВeekeeCZ
Consultant
Consultant

You need to use the vl-sort function, obviously. HELP 

You cannot have a simpler task to learn it on.

So make an effort and do that by yourself.

0 Likes
Message 3 of 10

avinash00002002
Collaborator
Collaborator

Hi!

I have tried to remove duplicate by x-Coordinates. but not wokrs.

 

Code:

(Defun c:Kjl(/ pts1 l1)
      (setq cnt 0 kj2 nil)
  (setq pts1 pts)
  (repeat (length pts)
      (setq cnt1 1)
    (Repeat (length pts)
      (if (= (car (nth cnt pts)) (car (nth cnt1 pts)))
        (setq lt 1)
        (setq kj2 (append kj2 (list (nth cnt1 pts))))
      );if
      (princ (strcat "\n" (rtos cnt1 2 0)))
      (setq cnt1 (+ 1 cnt1))
    ) ;Repeat
    (setq cnt (+ 1 cnt))
  ) ;Repeat
) ;Defun
 
0 Likes
Message 4 of 10

ВeekeeCZ
Consultant
Consultant

If the list of coors you posted in the initial post is the result you wanted, then you don't need to remove anything.

Just sort all the points by X, save it, and sort it again by Y. 

0 Likes
Message 5 of 10

avinash00002002
Collaborator
Collaborator

yes, it is needs to be removing duplicate X and Y coordinates.

0 Likes
Message 6 of 10

ВeekeeCZ
Consultant
Consultant

The simplest way is to build a list of unique x-es I can think of.

 

(foreach point points
  (setq x (car point))
  (if (member x xuniques)
    (setq xuniques (cons x xuniques))))

 

0 Likes
Message 7 of 10

komondormrex
Mentor
Mentor

hey,

check the function

 

(defun parse_list (list_to_sort x_axle / index parsed_list parsed_sublist)
	(if x_axle (setq coordinate_1 'car coordinate_2 'cadr coordinate_3 'caar)
			   (setq coordinate_1 'cadr coordinate_2 'car coordinate_3 'cadar)
	)
	(setq list_to_sort (vl-sort list_to_sort '(lambda (point_1 point_2)
														(and (< ((eval coordinate_1) point_1)
															    ((eval coordinate_1) point_2))
														)
											   )
					   )
		  index 0
		  parsed_sublist (list (car list_to_sort))
	)
	(repeat (length list_to_sort)
		(cond
			(
				(equal ((eval coordinate_3) parsed_sublist)
				   	   ((eval coordinate_1) (nth (setq index (1+ index)) list_to_sort))
					   1e-3
				)
				 (setq parsed_sublist (append parsed_sublist (list (nth index list_to_sort))))
			)
			(
			   t
				    (setq parsed_list (append parsed_list
											 (list (vl-sort parsed_sublist
														  '(lambda (point_1 point_2)
														  		(and (< ((eval coordinate_2) point_1)
																	 	((eval coordinate_2) point_2)
																	 )
																)
														   )
												   )
											 )
									  )
				          parsed_sublist (list (nth index list_to_sort))
					)
			)
		)
	)
	(mapcar '(lambda (sublist) (if (= 1 (length sublist)) (car sublist) (last sublist))) parsed_list)
)

 

it sorts and parses a list ascending depending on the x_axle parameter. if x_axle is t then it sort a list by x coordinate, otherwise by y.  if there are several points with same x/y coordinate and different y/x coordinates then only point with greatest y/x coordinate will stay. 

 

like (parse_list your_list t)

corrected

0 Likes
Message 8 of 10

avinash00002002
Collaborator
Collaborator

Hi!

Thanks for your prompt reply,

 

Is there a way to retain only X-Min and yMax points.

 

Thanks,

 

Avinash

0 Likes
Message 9 of 10

komondormrex
Mentor
Mentor

hey,

you may get 'em this way

(setq x_sorted_list (parse_list your_point_list t))
(setq y_sorted_list (parse_list your_point_list nil))
(setq min_x_point (list (caar x_sorted_list) (cadar y_sorted_list)))
(setq max_y_point (list (car (last x_sorted_list)) (cadr (last y_sorted_list))))  
0 Likes
Message 10 of 10

Sea-Haven
Mentor
Mentor

I use this works on number only.

 

; sorts on 1st two items
(setq lst (vl-sort lst
	 '(lambda (a b)
	    (cond
	      ((< (car a) (car b)))
	      ((= (car a) (car b)) (< (cadr a) (cadr b)))
	    )
	  )
   )
)

 

0 Likes