Find the other point with distance and angle in LISP

Find the other point with distance and angle in LISP

Anonymous
Not applicable
3,154 Views
2 Replies
Message 1 of 3

Find the other point with distance and angle in LISP

Anonymous
Not applicable

Hello everyone,


I'm trying to do a function that calculates a point from a point of origin, an angle and a distance, and draw a line between the two points.
So, I know I can calculate the distance with something like "distance = sqrt ((x1 - x2) ^ 2 + (y1 - y2) ^ 2)" (it would not be that well in LISP, but to simplify it is something like this) or I could get the two points (pt1 and pt2) and do (list (distance pt1 pt2)) and could get in the angle this way: (list (angle pt1 pt2)). But taking into account that the information I'm going to get will only be a point, the angle and distance between that point and what I'm going to calculate, I wonder if I would have to use the "ready-made" functions I've already shown or I would have to do it some other way.

 

I'm starting in LISP and really are many things in one program and I'm trying to develop the best way possible.

0 Likes
3,155 Views
2 Replies
Replies (2)
Message 2 of 3

Kent1Cooper
Consultant
Consultant

That is exactly what the (polar) function does.

 

(command "_.line" YourPoint (polar YourPoint YourAngle YourDistance) "")

 

[do it with running object snap off, just in case].

Kent Cooper, AIA
0 Likes
Message 3 of 3

john.uhden
Mentor
Mentor

@Kent1Cooper's answer is correct and to the point (as usual).  But you need to spend a lot of time looking at the AutoLisp help to failiarize yourself with all the possible functions you can use to solve for your end result.

F'rinstance the list function creates a list; it doesn't report a list.  There's a distance function to return the numeric distance between two given points.  The idea with most AutoLisp functions is that they return a value that can be used in subsequent statements.

 

Let's say for example that you ave two points, p1 and p2, and you want to solve for a third point, p3, that is on line with p1 and p2 and is the same distance from p2 as is p1.

 

We can do it the long way...

(setq ang (angle p1 p2))

(setq d (distance p1 p2))

(setq p3 (polar p2 ang d))

 

But we can string together those calculations into a shorter form because AutoLisp is evaluated from the inside out...

(setq p3 (polar p2 (angle p1 p2)(distance p1 p2)))

 

Note that (distance p1 p2) is the same as (distance p2 p1),

but (angle p2 p1) is 180° opposite (angle p1 p2).

 

This is not meant to demean you in any way.  All of us started behind where you are now.  It's by that desire to learn that we have become more educated, and that others here contribute their time and knowledge to help us learn.

It's so much fun to see newcomers asking questions so that they can learn.  I trust that one day you will be contributing clever answers.

John F. Uhden

0 Likes