Hello friends;
How can I calculate the distance between two points?
Thanks in advance to the helpful friend.
Solved! Go to Solution.
Solved by Kent1Cooper. Go to Solution.
You have to break the points apart. When you collect the data from your points, they will come in woth 4 values in the list, first is the dxf code, the other 3 are x, y, and z
You can take parts of that list using the cadr and caddr and cadddr functions to collect the x,y, and z. If you dont need z then you can leave that part out. You can then plug those values into the distance equation and output the result.
Christopher T. Cowgill, P.E.
AutoCAD Certified Professional
Civil 3D Certified Professional
Civil 3D 2022 on Windows 10
Please select the Accept as Solution button if my post solves your issue or answers your question.
The points are already reserved. K3 X,Y and K4 Because the point coordinates have already been given.
There must be action on the text.
The DIST command will tell you, including the Z component of the distance if the two points are not at the same elevation.
In AutoLisp terms, there's the (distance) function. Assuming your K3 and K4 are points saved as variables, this will tell you:
(distance K3 K4)
Also in AutoLisp terms if you want to actually do the calculation, again assuming K3 & K4 as point variables, and in XY distance only, your formula would look like this:
(sqrt (+ (expt (- (car K3) (car K4)) 2) (expt (- (cadr K3) (cadr K4)) 2)))
Look up the functions involved in the >AutoLisp Reference<.
No. Not this way. that is, not through the Point.
Action must be taken through writing.
My goal is to select these articles and get the length as a message.
@k005 wrote:
....Action must be taken through writing. My goal is to select these articles and get the length as a message.
By "these articles" do you mean the four Text objects with the big numbers? That can be done, if you can correctly select them in the right order. It would involve (atof) functions applied to their text content to get the numerical values that you would use in place of the (car) and (cadr) functions in my formula.
EDIT: I find that the (atof) function probably reduces the accuracy [it apparently won't go to enough decimal places], and I have doubts about the effects of returned values in scientific notation [again about limitation on decimal places], but see whether this, in very simplest terms, is good enough for you:
(defun C:WHATEVER ()
(setq
X1 (atof (cdr (assoc 1 (entget (car (entsel "\nSelect Text with X coordinate of point 1: "))))))
Y1 (atof (cdr (assoc 1 (entget (car (entsel "\n...with Y coordinate of point 1: "))))))
X2 (atof (cdr (assoc 1 (entget (car (entsel "\n...with X coordinate of point 2: "))))))
Y2 (atof (cdr (assoc 1 (entget (car (entsel "\n...with Y coordinate of point 2: "))))))
)
(prompt
(strcat
"\nDistance between points 1 & 2 is "
(rtos (sqrt (+ (expt (- X1 X2) 2) (expt (- Y1 Y2) 2))) 2 4)
"."
)
)
)
It gave a value the same to four decimal places [5.3146] as what AutoCAD reports as the length of a Line I drew using your coordinates [5.31461885].
Thank you. Ok. If there is a situation regarding Z, I can design it from these codes.
@Kent1Cooper wrote:
.... In AutoLisp terms, there's the (distance) function. ....
... with which you could replace that Pythagorean calculation with this:
(rtos (distance (list X1 Y1) (list X2 Y2)) 2 4)
Can't find what you're looking for? Ask the community or share your knowledge.