Jump to content

resort polygon coordinates to NonIntersecting coordinates


Recommended Posts

Posted (edited)

Hi all, I have four coordinates for each polygon in excel, number of some polygons isn't sort and when I draw them in google earth or autocad by vba programming, interference occurs, can we resort them to NonIntersecting  coordinates?.: (number of points is not important)

 

364800422_Screenshot(1581).thumb.png.c5548aae45c628648d5a2dc1d5413fcf.png

 

 

1480713989_Screenshot(1582).png.19db6b3ef91b0b2c8eded7a506587344.png

Edited by amir0914
Posted

I know its to do with angles, but no idea something like the ccw of plines that's ok for 4 but what about a "H".

 

1-2 cw

2-3 cw

3-4 ccw stop

  • Like 1
Posted
13 hours ago, amir0914 said:

Hi all, I have four coordinates for each polygon in excel, number of some polygons isn't sort and when I draw them in google earth or autocad by vba programming, interference occurs, can we resort them to NonIntersecting  coordinates?.: (number of points is not important)

 

364800422_Screenshot(1581).thumb.png.c5548aae45c628648d5a2dc1d5413fcf.png

 

 

1480713989_Screenshot(1582).png.19db6b3ef91b0b2c8eded7a506587344.png

 

Hi Amir0914, just a question: how you will determinate if coords need to be sorted or not, and amount of points could be could be useful in order to sort in the correct way, and again how determinate the first point ? it will be always the first ? thank you.

  • Like 1
Posted (edited)
6 hours ago, PeterPan9720 said:

 

Hi Amir0914, just a question: how you will determinate if coords need to be sorted or not, and amount of points could be could be useful in order to sort in the correct way, and again how determinate the first point ? it will be always the first ? thank you.

Hi peter. thanks to reply, 

I don't exactly how to know it's sorted or not, but I transfer all the polygons to google earth or autocad by vba and check them manually, so that if every polygon will have intersected line, I will correct them on excel file. for the second question, it's not important to determine first or second point, because I don't need to number of point, I only need to draw a nonIntersecting  polygon without number.

 

 

 

 

 

Edited by amir0914
Posted

Maybe centre point then angle to each point sort points based on angle, ok for a polygon with no reverse points like a L.

 

amir0914 post some sample xls points. Really need to see the shapes your interested in.

Posted

my $0.02 

1. EXCEL select xy columns, insert graph (scatter) as preview

2. If the polygon is rectang or square? calculate area if crossing you get zero 

Posted
5 hours ago, BIGAL said:

Maybe centre point then angle to each point sort points based on angle, ok for a polygon with no reverse points like a L.

 

amir0914 post some sample xls points. Really need to see the shapes your interested in.

Hi bigal, I don't know how I can find angle in excel, but I attached sample excel file 

 

Sample.xlsm

Posted
4 hours ago, hanhphuc said:

my $0.02 

1. EXCEL select xy columns, insert graph (scatter) as preview

2. If the polygon is rectang or square? calculate area if crossing you get zero 

If I found that the polygon need to sort by scatter graph, but what's next? (for resort or correct of points)

Posted
8 hours ago, amir0914 said:

If I found that the polygon need to sort by scatter graph, but what's next? (for resort or correct of points)

 

Macro added. Click  B<>C or C<>D 

 

Sample-macro.xlsm

 

 

Posted

The attached macro-enable Excel file will sort 4 points such that the results will not have intersecting edges.

It computes the area of three different configurations and uses the configuration with the greatest area as the sorted solution.

BEFORE Execution

image.png.3e56b636ca6fa17b1d7de9a99222519b.png

AFTER Execution

image.png.a94a91faf2ef1b8a6faaaa815d7abc74.png

INTERSECTING LINES.xlsm

  • Like 1
Posted (edited)

That was great lrm, thank you so much.

The macro resolved my problem, but will the macro work if the points will be more than 4 points in the future? (for example 10 points). like this

 

Screenshot (1583).png

Edited by amir0914
Posted

You should post the xls for testing in future.

 

Any way so long as you always have a convex shape this should work. It looks at an internal angle of the points so no graph's etc required, H pattern will not work.

 

Use in excel cell F2 =(concatenate("point ",B2,",",C2) then copy down and copy and paste like sample F2-F11, As "close" is part of code so no need for last point. 

 

; pline around points
; By AlanH info@alanh.com.au
: June 2020

(vl-load-com)

(defun c:plpoints ( / ss pt pts x ent lst)
(setq ss (ssget (list (cons 0 "POINT"))))
(setq pt (getpoint "pick center point"))
(setq lst '())
(repeat (setq x (sslength ss))
(setq ent (ssname ss (setq x (- x 1))))
(setq pts (cdr (assoc 10 (entget ent))))
(setq lst (cons (list (angle pts pt) (list (car pts)(cadr pts))) lst))
)
(setq lst (vl-sort lst '(lambda (x y) (< (car x)(car y)))))
(entmakex (append (list  (cons 0 "LWPOLYLINE")
                         (cons 100 "AcDbEntity")
                         (cons 100 "AcDbPolyline")
                         (cons 90 (length lst))
                         (cons 70 1))
                   (mapcar (function (lambda (p) (cons 10 (nth 1 p)))) lst))
)
(princ)
)

(c:clpoints)

 

  • Like 1
Posted

 

@amir0914 No, my program is only intended to work for 4 points.

 

@BIGAL Pretty slick!!!

 

If the points that the OP is dealing with are all part of a convex hull then you could modify your code to define the center point as the centroid of the set of points eliminating the need for the user to specify a center point.

 

Posted (edited)

Like to leave something for the end user to add I did think about it but more code. Watch this space.

 

Yeah code updated.

Edited by BIGAL
Posted (edited)
15 hours ago, amir0914 said:

That was great lrm, thank you so much.

The macro resolved my problem, but will the macro work if the points will be more than 4 points in the future? (for example 10 points). like this

 

 

 

LISP try LM:ConvexHull

or 

ExcelForum -  VB site hosted by www.andypope.info has been reported as unsafe! 

 

1312594113_convexhull.thumb.gif.ebfcaaedbbfe1b2be68dcfd2d95a2adb.gif

 

 

Edited by hanhphuc
  • Like 1
Posted (edited)
6 hours ago, BIGAL said:

You should post the xls for testing in future.

 

Any way so long as you always have a convex shape this should work. It looks at an internal angle of the points so no graph's etc required, H pattern will not work.

 

Use in excel cell F2 =(concatenate("point ",B2,",",C2) then copy down and copy and paste like sample F2-F11, As "close" is part of code so no need for last point. 

 


; pline around points
; By AlanH info@alanh.com.au
: June 2020

(vl-load-com)

(defun c:plpoints ( / ss pt pts x ent lst)
(setq ss (ssget (list (cons 0 "POINT"))))
(setq pt (getpoint "pick center point"))
(setq lst '())
(repeat (setq x (sslength ss))
(setq ent (ssname ss (setq x (- x 1))))
(setq pts (cdr (assoc 10 (entget ent))))
(setq lst (cons (list (angle pts pt) (list (car pts)(cadr pts))) lst))
)
(setq lst (vl-sort lst '(lambda (x y) (< (car x)(car y)))))
(entmakex (append (list  (cons 0 "LWPOLYLINE")
                         (cons 100 "AcDbEntity")
                         (cons 100 "AcDbPolyline")
                         (cons 90 (length lst))
                         (cons 70 1))
                   (mapcar (function (lambda (p) (cons 10 (nth 1 p)))) lst))
)
(princ)
)

(c:clpoints)

 

 

That was really good idea,  I change it a bit to find center point by average points : (only on Regular shapes)

					; pline around points
					; By AlanH info@alanh.com.au
:
June
2020

(vl-load-com)

(defun c:plpoints (/ ss pt pts x ent lst)
  (setq ss (ssget (list (cons 0 "POINT"))))

  (setq ptlist nil)
  (repeat (setq x (sslength ss))
    (setq ent (ssname ss (setq x (- x 1))))
    (setq pts (cdr (assoc 10 (entget ent))))
    (setq ptlist (cons pts ptlist))
    (setq pt (average ptlist))
  )

;;;  (setq pt (getpoint "pick center point"))

  (setq lst '())

  (foreach a ptlist
    (setq
      lst (cons (list (angle a pt) (list (car a) (cadr a))) lst)
    )
  )

  (setq lst (vl-sort lst '(lambda (x y) (< (car x) (car y)))))
  (entmakex
    (append (list (cons 0 "LWPOLYLINE")
		  (cons 100 "AcDbEntity")
		  (cons 100 "AcDbPolyline")
		  (cons 90 (length lst))
		  (cons 70 1)
	    )
	    (mapcar (function (lambda (p) (cons 10 (nth 1 p)))) lst)
    )
  )
  (princ)
)

(c:clpoints)


(defun average (lst)
  (mapcar '(lambda (x) (/ x (length lst)))
	  (apply 'mapcar (cons '+ lst))
  )
)

 

Edited by amir0914
Posted (edited)
1 hour ago, hanhphuc said:

 

LISP try LM:ConvexHull

or 

ExcelForum -  VB site hosted by www.andypope.info has been reported as unsafe! 

 

1312594113_convexhull.thumb.gif.ebfcaaedbbfe1b2be68dcfd2d95a2adb.gif

 

Hi hanhphuc, it is awesome, can you attach the exact file that your testing on the attached image? I downloaded from  "www.andypope.info", but it's not  the same file and also changes the original coordinates.

 

Edited by amir0914
Posted
36 minutes ago, amir0914 said:

Hi hanhphuc, it is awesome, can you attach the exact file that your testing on the attached image? I downloaded from  "www.andypope.info", but it's not  the same file and also changes the original coordinates.

 

 

The author already commented nicely, so just omit sub m_AddPaddingPoints 



(Public Function CalculateHull () As Boolean

;<snippet>  

'
' Use the hull points as the set of value to check
' adding an extra set of points
'
               m_AddPaddingPoints
                blnAnimate = m_blnAnimate  

;<snippet>     

               

 

 


 
  • Like 1
Posted (edited)

I updated code in my post,  but the average defun is way better for points was trying to do the same using mapcar etc. Will save it for future reference.

 

There is a typo (c:clpoints) should be (c:plpoints) runs straighaway if you use appload, drag drop or a menu load.

 

 

Edited by BIGAL
  • Like 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...