How to find all four sides of a polygon

How to find all four sides of a polygon

avinash00002002
Collaborator Collaborator
523 Views
6 Replies
Message 1 of 7

How to find all four sides of a polygon

avinash00002002
Collaborator
Collaborator

Hi!

How to find Nos. of points on given Polygonal object in Right, Left, Top and Bottom sides individually.

 

Thanks,

 

Avinash

0 Likes
524 Views
6 Replies
Replies (6)
Message 2 of 7

ВeekeeCZ
Consultant
Consultant

It's so simple that you are the one who was elected to do the work. Seriously, with just a little risk that you will learn something new.

Message 3 of 7

hak_vz
Advisor
Advisor

@ВeekeeCZ  @CodeDing 

This is really simple task.

@avinash00002002  still plays on a card that there is a ..... who'll write him a code again and again.

Here is my last post to his request, but code is not complete.

 

(defun c:nos( / pick_poly take pointlist2d rad_to_deg e eo top_left top_right bottom_left bottom_right cp i coords n ang)
	(defun pick_poly (msg)
		(setq e (car(entsel msg)))
		(if (and (not e) (= (getvar 'Errno) 7)) (pick_poly msg) e)
	)
	(defun take (amount lst / ret)(repeat amount (setq ret (cons (car lst) (take (1- amount) (cdr lst))))))
	(defun pointlist2d (lst / ret) (while lst (setq	ret (cons (take 2 lst) ret) lst (cddr lst))) (reverse ret))
	(defun rad_to_deg (rad)(* 180.0 (/ rad pi)))
	(setq 
		e (pick_poly "\nSelect polyline") 
		eo (vlax-ename->vla-object e)
		top_left 0
		top_right 0
		bottom_left 0
		bottom_right 0
		cp '(0 0)
		i -1
	)			
	(cond 
		((= (vlax-get eo 'Objectname) "AcDbPolyline")
			(setq coords (pointlist2d (vlax-get eo 'Coordinates)) n (length coords))
			(while (< (setq i (1+ i)) n) (setq cp (mapcar '+ cp (nth i coords))))
			(setq cp (mapcar '/ cp (list n n)) i -1)
			(while (< (setq i (1+ i)) n)
				(setq ang (rad_to_deg (angle cp (nth i coords))))
				(cond 
					((and (> ang 0) (< ang 90)) (setq top_right (1+ top_right)))
					((and (> ang 90) (< ang 180)) (setq top_left (1+ top_left)))
					((and (> ang 180) (< ang 270)) (setq bottom_left (1+ bottom_left)))
					((> ang 270) (setq bottom_right (1+ bottom_right)))
				)
			)
		; finish your program using commands princ strcat and itoa
		
		
		)
	)
	(princ)	
)

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 4 of 7

ВeekeeCZ
Consultant
Consultant

Interesting. I thought that I would case the vertices by xmin, xmax, ymin, ymax. Possibly with some fuzz.

0 Likes
Message 5 of 7

Kent1Cooper
Consultant
Consultant

@avinash00002002 wrote:

How to find Nos. of points on given Polygonal object in Right, Left, Top and Bottom sides individually.

....


What kind of output or result would you be looking for?  A list of lists of the two points at each end of those four edges?  An external file of some kind?  Text somehow in the drawing?  Do the diagonal edges in your sample drawing not count, and you want only the orthogonal ones?  Are there always orthogonal edges along the right/left/top/bottom, or might the whole thing sometimes be rotated at some other kind of angle?  Etc., etc.

Kent Cooper, AIA
Message 6 of 7

Kent1Cooper
Consultant
Consultant

@ВeekeeCZ wrote:

.... I would case the vertices by xmin, xmax, ymin, ymax. Possibly with some fuzz.


In their sample drawing, the combination of xmin and ymin, and that of xmax and ymax, if based on either the bounding box or vertex coordinates, are not vertex locations on the Polyline at all.  This kind of thing is why I asked what kind of result they're looking for, whether the diagonals are relevant, etc.

Kent Cooper, AIA
0 Likes
Message 7 of 7

ВeekeeCZ
Consultant
Consultant

@Kent1Cooper wrote:

@ВeekeeCZ wrote:

.... I would case the vertices by xmin, xmax, ymin, ymax. Possibly with some fuzz.


In their sample drawing, the combination of xmin and ymin, and that of xmax and ymax, if based on either the bounding box or vertex coordinates, are not vertex locations on the Polyline at all.  This kind of thing is why I asked what kind of result they're looking for, whether the diagonals are relevant, etc.


 

Agree, but I did not talk about combinations, nor about the bounding box. 

 

Top are all vertices with ymax

Right are all vertices with xmax and so on.

 

... just a quick assumption from the given shape. 

0 Likes