RepCad Posted June 9, 2020 Share Posted June 9, 2020 (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) Edited June 9, 2020 by amir0914 Quote Link to comment Share on other sites More sharing options...
BIGAL Posted June 9, 2020 Share Posted June 9, 2020 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 1 Quote Link to comment Share on other sites More sharing options...
PeterPan9720 Posted June 10, 2020 Share Posted June 10, 2020 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) 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. 1 Quote Link to comment Share on other sites More sharing options...
RepCad Posted June 10, 2020 Author Share Posted June 10, 2020 (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 June 10, 2020 by amir0914 Quote Link to comment Share on other sites More sharing options...
BIGAL Posted June 11, 2020 Share Posted June 11, 2020 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. Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted June 11, 2020 Share Posted June 11, 2020 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 Quote Link to comment Share on other sites More sharing options...
RepCad Posted June 11, 2020 Author Share Posted June 11, 2020 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 Quote Link to comment Share on other sites More sharing options...
RepCad Posted June 11, 2020 Author Share Posted June 11, 2020 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) Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted June 11, 2020 Share Posted June 11, 2020 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 Quote Link to comment Share on other sites More sharing options...
lrm Posted June 11, 2020 Share Posted June 11, 2020 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 AFTER Execution INTERSECTING LINES.xlsm 1 Quote Link to comment Share on other sites More sharing options...
BIGAL Posted June 12, 2020 Share Posted June 12, 2020 LRM that's pretty cool using the graph to show result added the make pline bit just copy and paste to Autocad J1-J6 INTERSECTING LINES (1).xlsm 1 Quote Link to comment Share on other sites More sharing options...
RepCad Posted June 12, 2020 Author Share Posted June 12, 2020 (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 : Edited June 12, 2020 by amir0914 Quote Link to comment Share on other sites More sharing options...
BIGAL Posted June 13, 2020 Share Posted June 13, 2020 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) 1 Quote Link to comment Share on other sites More sharing options...
lrm Posted June 13, 2020 Share Posted June 13, 2020 @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. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted June 13, 2020 Share Posted June 13, 2020 (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 June 13, 2020 by BIGAL Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted June 13, 2020 Share Posted June 13, 2020 (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! Edited June 13, 2020 by hanhphuc 1 Quote Link to comment Share on other sites More sharing options...
RepCad Posted June 13, 2020 Author Share Posted June 13, 2020 (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 June 13, 2020 by amir0914 Quote Link to comment Share on other sites More sharing options...
RepCad Posted June 13, 2020 Author Share Posted June 13, 2020 (edited) 1 hour ago, hanhphuc said: LISP try LM:ConvexHull or ExcelForum - VB site hosted by www.andypope.info has been reported as unsafe! 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 June 13, 2020 by amir0914 Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted June 13, 2020 Share Posted June 13, 2020 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> 1 Quote Link to comment Share on other sites More sharing options...
BIGAL Posted June 13, 2020 Share Posted June 13, 2020 (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 June 13, 2020 by BIGAL 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.