Jump to content

Plotting a point a known distance along a line segment


jay@sitetechnologies.io

Recommended Posts

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!

E5DB2A6F-B5D3-4EE0-B4CE-09FE9D7848F2.jpeg

Link to comment
Share on other sites

@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?

Link to comment
Share on other sites

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.

image.png.b06fd1849b76991943854c68f24e3aea.png

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)
)

 

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

image.png.b06fd1849b76991943854c68f24e3aea.png

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?

  • Like 1
Link to comment
Share on other sites

"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.

Link to comment
Share on other sites

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.

 

 

  • Like 2
Link to comment
Share on other sites

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.
 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 by pkenewell
  • Like 1
Link to comment
Share on other sites

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 by ronjonp
Link to comment
Share on other sites

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. 

  • Like 1
Link to comment
Share on other sites

@jay@sitetechnologies.io I had a typo in my spreadsheet.  Here it is corrected in your Excel file.

 

image.thumb.png.64af3cd14cd77c553860af3bc5028618.png

 

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

  • Like 1
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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...