jay@sitetechnologies.io Posted March 11, 2021 Posted March 11, 2021 I have several hundred of these occurrences where I have a line segment that starts at Pt.A (0,0) and ends at a known Pt.B (X,Y). (See illustration) Also known is the distance or length, L, along the line from the origin 0,0. I am trying to plot a point, Pt.C, at this location. I have tried doing the math in Excel but couldn't quite figure it out. I am wondering if there is a way to programmatically plot this point using either a .scr or LISP routine, or even draw a line that ends at the point. Any advice is appreciated! Quote
pkenewell Posted March 11, 2021 Posted March 11, 2021 @jay@sitetechnologies.io The basic function in Autolisp would be to use the following code within a program: (polar ptA (angle PtA PtB) L) However - In order to write something for you I need more information: 1) How are you getting your PtA and PtB? Selecting points? End points of a line? 2) How is L obtained? Length entered at command line? Constant length? Quote
lrm Posted March 11, 2021 Posted March 11, 2021 A general vector equation for finding the coordinates of a point a known distance between two points is: Pc = P1 + L * (P2 -P1) / (distance from p1 to p2) The scalar equations are: xc = x1 + L * (x2 - x1) / (distance from p1 to p2) yc = x1 + L * (y2 - y1) / (distance from p1 to p2) If you have the data in Excel and you would like to create the points there and then use a script to create the points in AutoCAD you could use the following. the expression for yc in cell G2 is: =B2+E2*(D2-B2)/SQRT((C2-A2)^2+(D2-B2^2)) and the expression in cell H2 to create the AutoCAD point command is: =CONCATENATE("_point ",F2,",",G2) You can copy the expression in cells H2 down to the clipboard then paste into AutoCAD to create the points. Alternatively you can use the following vlisp program to create the points interactively one point at a time. (defun c:ptAtDist (/ p1 p2 L d pc) ;creates a point at distance between two points (setq p1 (getpoint "\nSpecify first point.") p2 (getpoint "\nSpecify second point.") L (getreal "\nSpecify distance.") ) (setq d (distance p1 p2) pc (mapcar '+ p1 (mapcar '/ (mapcar '* (list L L L) (mapcar '- p2 p1)) (list d d d) ) ) ) (command "_point" "_non" pc) (princ) ) Quote
Steven P Posted March 11, 2021 Posted March 11, 2021 You might also look at Chainage Lisps, these often have a 'while' loop to add markers every nth distance, take that out and they should put a marker at the first distance. Guessing you can adjust it to select a line, and enter a distance. Problem I have had with them is if the line is drawn 'backwards' (from point x,y to 0,0) Quote
Steven P Posted March 11, 2021 Posted March 11, 2021 2 hours ago, lrm said: A general vector equation for finding the coordinates of a point a known distance between two points is: Pc = P1 + L * (P2 -P1) / (distance from p1 to p2) The scalar equations are: xc = x1 + L * (x2 - x1) / (distance from p1 to p2) yc = x1 + L * (y2 - y1) / (distance from p1 to p2) If you have the data in Excel and you would like to create the points there and then use a script to create the points in AutoCAD you could use the following. the expression for yc in cell G2 is: =B2+E2*(D2-B2)/SQRT((C2-A2)^2+(D2-B2^2)) and the expression in cell H2 to create the AutoCAD point command is: =CONCATENATE("_point ",F2,",",G2) You can copy the expression in cells H2 down to the clipboard then paste into AutoCAD to create the points. Alternatively you can use the following vlisp program to create the points interactively one point at a time. (defun c:ptAtDist (/ p1 p2 L d pc) ;creates a point at distance between two points (setq p1 (getpoint "\nSpecify first point.") p2 (getpoint "\nSpecify second point.") L (getreal "\nSpecify distance.") ) (setq d (distance p1 p2) pc (mapcar '+ p1 (mapcar '/ (mapcar '* (list L L L) (mapcar '- p2 p1)) (list d d d) ) ) ) (command "_point" "_non" pc) (princ) ) Since point A and B are connected by a line, you could just have "select line" and work out the points? 1 Quote
lrm Posted March 11, 2021 Posted March 11, 2021 "Since point A and B are connected by a line, you could just have "select line" and work out the points?" True but you would have to assume the line was drawn from A to B and not B to A. Quote
BIGAL Posted March 12, 2021 Posted March 12, 2021 Like Lrm its very simple pick a line from 1 end that becomes ptA something I have been doing for years. ; simple make a point at dist on a line ; By AlanH march 2021 (defun c:testpt ( / tp1 tpp1 p1 p2 p3 d1 d2 temp ang ) (SETQ TP1 (entsel "\nSelect Line near left end: ")) ; implies which way (setq tpp1 (entget (car tp1)) p1 (cdr (assoc 10 tpp1)) ; start point p2 (cdr (assoc 11 tpp1)) ; end point p3 (cadr tp1) ) (setq d1 (distance p1 p3) d2 (distance p2 p3) ) ; swap point direction for end closest (if (> d1 d2) (progn (setq temp p1) (setq p1 p2) (setq p2 temp) ) ) (setq ang (angle p1 p2)) (setq d1 (getreal "\nEnter distance from end ")) (setq pt (polar p1 ang d1)) (setvar 'pdmode 33) ; turn on point style (command "point" pt) ; create a point (princ) ; exit quietly ) A couple more options are pt offset sq from point, and pt along a pline as already mentioned. 2 Quote
jay@sitetechnologies.io Posted March 12, 2021 Author Posted March 12, 2021 On 3/11/2021 at 8:17 AM, pkenewell said: @jay@sitetechnologies.io The basic function in Autolisp would be to use the following code within a program: (polar ptA (angle PtA PtB) L) However - In order to write something for you I need more information: 1) How are you getting your PtA and PtB? Selecting points? End points of a line? 2) How is L obtained? Length entered at command line? Constant length? PtA will actually always be 0,0 PtB is a known coordinate from a list. Each PtB has a corresponding L value, also from a list/spreadsheet. Quote
jay@sitetechnologies.io Posted March 12, 2021 Author Posted March 12, 2021 23 hours ago, Steven P said: Since point A and B are connected by a line, you could just have "select line" and work out the points? Thanks for taking the time to put that spreadsheet together, but I am getting results that are not correct. Since all of my point A's are at 0,0, the length L is the same as a circle with radius L at base point 0,0. I plotted 40 or so of my Point A, Point B, and L (circle). The point in CAD does not match the points in Excel. Please take a look if you don't mind. Thanks. PlottingPointC.dwg SolvingPointC.xlsx Quote
pkenewell Posted March 12, 2021 Posted March 12, 2021 (edited) 4 hours ago, jay@sitetechnologies.io said: PtA will actually always be 0,0 PtB is a known coordinate from a list. Each PtB has a corresponding L value, also from a list/spreadsheet. Here is a basic function and test command. I am using an association list in the form of (list (cons PtB L)(Cons PtB L)...). I leave you to figure out how to gather the points/Length list. ;; pllst = Association list of Points and Lengths. Example: '(((1.0 1.0) . 0.435)((2.0 2.0) 1.267)((3.0 3.0) 2.723)) (defun Get_Lpoint_List (pllst / rlst) (vl-load-com) (if (and (= (type pllst) 'LIST) (vl-consp (car pllst))) (foreach pt pllst (setq rlst (cons (polar '(0.0 0.0) (angle '(0.0 0.0) (car pt)) (cdr pt)) rlst)) ) ) (reverse rlst) ) (defun C:testthis (/ lst) (setq lst (list (cons (list 1.0 1.0) 0.435)(Cons (list 2.0 2.0) 1.267)(cons (list 3.0 3.0) 2.723))) (foreach n (Get_Lpoint_List lst) (command "._Point" "_non" n) ) ) Edited March 12, 2021 by pkenewell 1 Quote
ronjonp Posted March 12, 2021 Posted March 12, 2021 (edited) If you don't need the math and your origin is always 0,0,0 using a temp circle with 'intersectwith will get you the point. (defun c:foo (/ c d e p) (cond ((and (setq e (car (entsel "\nPick your line: "))) (setq d (getdist '(0 0 0) "\nEnter distance: ")) (setq c (entmakex (list '(0 . "circle") '(10 0. 0. 0.) '(8 . "TEMPCIRCLE") (cons 40 d)))) (setq p (vlax-invoke (vlax-ename->vla-object c) 'intersectwith (vlax-ename->vla-object e) 0)) ) (repeat (/ (length p) 3) (entmakex (list '(0 . "point") (cons 10 (list (car p) (cadr p) (caddr p))) '(8 . "POINT"))) (setq p (cdddr p)) ) (entdel c) ) ) (princ) ) Edited March 12, 2021 by ronjonp Quote
BIGAL Posted March 12, 2021 Posted March 12, 2021 If want an excel solution could use a ratio answer have pta 0,0 & ptb x,y so work out length pta to ptb then desired length/ total length. Something about an old guy pythagoras. Now (ratio * x2) (ratio * y2) then add to 0,0 thats the new point co-ordinates. 1 Quote
lrm Posted March 12, 2021 Posted March 12, 2021 @jay@sitetechnologies.io I had a typo in my spreadsheet. Here it is corrected in your Excel file. A similar correction is required in H2 before you fill down. =C2+F2*(E2-C2)/SQRT((D2-B2)^2+(E2-C2)^2) You can copy and pasted the AutoCAD commands in column into the AutoCAD prompt llne to create the points. SolvingPointC.01.xlsx 1 Quote
lrm Posted March 12, 2021 Posted March 12, 2021 Correction, that last line of my post should have read: You can copy and paste the AutoCAD commands in column "I" into the AutoCAD prompt request to create the points. Quote
BIGAL Posted March 13, 2021 Posted March 13, 2021 Lrm you can edit your post any time you like, not like that other forum that gives you 30 minutes. Often a typo is fixed that way in code. Quote
jay@sitetechnologies.io Posted March 15, 2021 Author Posted March 15, 2021 Thanks everyone for the replies. everything was very helpful. Quote
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.