calculate a point between two other points

calculate a point between two other points

Anonymous
Not applicable
340 Views
62 Replies
Message 1 of 63

calculate a point between two other points

Anonymous
Not applicable
Hello group,

Using LISP, how would one calc a point (p3), between two other points (p1
and p2), a given distance (dist) from p1?
Example:

p1 = (2.0 2.5 0.0)
p2 = (6.5 2.2 1.0)
dist = 1.5
p3 = ?

I'm sure there is a simple formula, however, I failed 3rd grade math five
times.
--
Eric S. eschneider@jensenprecast.com
0 Likes
341 Views
62 Replies
Replies (62)
Message 2 of 63

Anonymous
Not applicable
(polar p1 (angle p1 p2) d)

--
Attitudes are contagious. Is yours worth catching?
http://www.acadx.com

"Eric Schneider" wrote in message
news:CEE5E0063099941F31A459F2A130DFD6@in.WebX.SaUCah8kaAW...
> Hello group,
>
> Using LISP, how would one calc a point (p3), between two other points (p1
> and p2), a given distance (dist) from p1?
> Example:
>
> p1 = (2.0 2.5 0.0)
> p2 = (6.5 2.2 1.0)
> dist = 1.5
> p3 = ?
>
> I'm sure there is a simple formula, however, I failed 3rd grade math five
> times.
> --
> Eric S. eschneider@jensenprecast.com
>
0 Likes
Message 3 of 63

Anonymous
Not applicable
Don't feel bad Eric, it's not really *math* in this case (reduced to
giggling on the floor...)

--
R. Robert Bell, MCSE
Xtending the Power
www.acadx.com

"Frank Oquendo" wrote in message
news:17C804620D8B5BFA92D3993CF9AC8371@in.WebX.SaUCah8kaAW...
| (polar p1 (angle p1 p2) d)
|
| --
| Attitudes are contagious. Is yours worth catching?
| http://www.acadx.com
|
| "Eric Schneider" wrote in message
| news:CEE5E0063099941F31A459F2A130DFD6@in.WebX.SaUCah8kaAW...
| > Hello group,
| >
| > Using LISP, how would one calc a point (p3), between two other points
(p1
| > and p2), a given distance (dist) from p1?
| > Example:
| >
| > p1 = (2.0 2.5 0.0)
| > p2 = (6.5 2.2 1.0)
| > dist = 1.5
| > p3 = ?
| >
| > I'm sure there is a simple formula, however, I failed 3rd grade math
five
| > times.
| > --
| > Eric S. eschneider@jensenprecast.com
| >
|
0 Likes
Message 4 of 63

Anonymous
Not applicable
So without using the (polar) function, what is the formula for Eric's
objective? (he said as his gauntlet cascaded to the floor...)

Cliff

R. Robert Bell wrote in message
news:1D358B650846B6463EEED3017A46CF93@in.WebX.SaUCah8kaAW...
| Don't feel bad Eric, it's not really *math* in this case (reduced to
| giggling on the floor...)
|
| --
| R. Robert Bell, MCSE
| Xtending the Power
| www.acadx.com
|
| "Frank Oquendo" wrote in message
| news:17C804620D8B5BFA92D3993CF9AC8371@in.WebX.SaUCah8kaAW...
| | (polar p1 (angle p1 p2) d)
| |
| | --
| | Attitudes are contagious. Is yours worth catching?
| | http://www.acadx.com
| |
| | "Eric Schneider" wrote in message
| | news:CEE5E0063099941F31A459F2A130DFD6@in.WebX.SaUCah8kaAW...
| | > Hello group,
| | >
| | > Using LISP, how would one calc a point (p3), between two other points
| (p1
| | > and p2), a given distance (dist) from p1?
| | > Example:
| | >
| | > p1 = (2.0 2.5 0.0)
| | > p2 = (6.5 2.2 1.0)
| | > dist = 1.5
| | > p3 = ?
| | >
| | > I'm sure there is a simple formula, however, I failed 3rd grade math
| five
| | > times.
| | > --
| | > Eric S. eschneider@jensenprecast.com
| | >
| |
|
0 Likes
Message 5 of 63

Anonymous
Not applicable
I suppose we should exclude the (angle) function from the challenge as well.

Cliff Middleton wrote in message
news:CC9E64BF786FB517CB8A226714A62D90@in.WebX.SaUCah8kaAW...
| So without using the (polar) function, what is the formula for Eric's
| objective? (he said as his gauntlet cascaded to the floor...)
|
| Cliff
|
| R. Robert Bell wrote in message
| news:1D358B650846B6463EEED3017A46CF93@in.WebX.SaUCah8kaAW...
| | Don't feel bad Eric, it's not really *math* in this case (reduced to
| | giggling on the floor...)
| |
| | --
| | R. Robert Bell, MCSE
| | Xtending the Power
| | www.acadx.com
| |
| | "Frank Oquendo" wrote in message
| | news:17C804620D8B5BFA92D3993CF9AC8371@in.WebX.SaUCah8kaAW...
| | | (polar p1 (angle p1 p2) d)
| | |
| | | --
| | | Attitudes are contagious. Is yours worth catching?
| | | http://www.acadx.com
| | |
| | | "Eric Schneider" wrote in message
| | | news:CEE5E0063099941F31A459F2A130DFD6@in.WebX.SaUCah8kaAW...
| | | > Hello group,
| | | >
| | | > Using LISP, how would one calc a point (p3), between two other
points
| | (p1
| | | > and p2), a given distance (dist) from p1?
| | | > Example:
| | | >
| | | > p1 = (2.0 2.5 0.0)
| | | > p2 = (6.5 2.2 1.0)
| | | > dist = 1.5
| | | > p3 = ?
| | | >
| | | > I'm sure there is a simple formula, however, I failed 3rd grade math
| | five
| | | > times.
| | | > --
| | | > Eric S. eschneider@jensenprecast.com
| | | >
| | |
| |
|
0 Likes
Message 6 of 63

Anonymous
Not applicable
Thanks Frank. You know, I've seen this before somewhere (spoken with a deep
reddish hue from neck up).

Now what the heck is d?






--
Eric S. eschneider@jensenprecast.com
0 Likes
Message 7 of 63

Anonymous
Not applicable
"R. Robert Bell" wrote:
>
> Don't feel bad Eric, it's not really *math* in this case (reduced to
> giggling on the floor...)

Are you giggling because what Frank posted doesn't
work, or is there some other humor to this?

Yes Robert, it really is *math* in this case.

--

Checkout the AcadX(tm) ActiveX Extension Library at:

http://www.caddzone.com/acadx/acadx.htm

/*********************************************************/
/* Tony Tanzillo Design Automation Consulting */
/* Programming & Customization for AutoCAD & Compatibles */
/* ----------------------------------------------------- */
/* tony.tanzillo@worldnet.att.net */
/* http://www.caddzone.com */
/*********************************************************/
0 Likes
Message 8 of 63

Anonymous
Not applicable
What Frank posted doesn't work in the 3D case, as
original example requires.

;; (point-on-line )
;;
;; Returns a point on the line -
;; a specified distance from

(defun point-on-line (p1 p2 dist / sc)
(setq sc (/ dist (distance p1 p2)))
(mapcar '+ p1
(mapcar '*
(mapcar '- p2 p1)
(list sc sc sc)
)
)
)

Cliff Middleton wrote:
>
> So without using the (polar) function, what is the formula for Eric's
> objective? (he said as his gauntlet cascaded to the floor...)
>
> Cliff
>
> R. Robert Bell wrote in message
> news:1D358B650846B6463EEED3017A46CF93@in.WebX.SaUCah8kaAW...
> | Don't feel bad Eric, it's not really *math* in this case (reduced to
> | giggling on the floor...)
> |
> | --
> | R. Robert Bell, MCSE
> | Xtending the Power
> | www.acadx.com
> |
> | "Frank Oquendo" wrote in message
> | news:17C804620D8B5BFA92D3993CF9AC8371@in.WebX.SaUCah8kaAW...
> | | (polar p1 (angle p1 p2) d)
> | |
> | | --
> | | Attitudes are contagious. Is yours worth catching?
> | | http://www.acadx.com
> | |
> | | "Eric Schneider" wrote in message
> | | news:CEE5E0063099941F31A459F2A130DFD6@in.WebX.SaUCah8kaAW...
> | | > Hello group,
> | | >
> | | > Using LISP, how would one calc a point (p3), between two other points
> | (p1
> | | > and p2), a given distance (dist) from p1?
> | | > Example:
> | | >
> | | > p1 = (2.0 2.5 0.0)
> | | > p2 = (6.5 2.2 1.0)
> | | > dist = 1.5
> | | > p3 = ?
> | | >
> | | > I'm sure there is a simple formula, however, I failed 3rd grade math
> | five
> | | > times.
> | | > --
> | | > Eric S. eschneider@jensenprecast.com
> | | >
> | |
> |

--

Checkout the AcadX(tm) ActiveX Extension Library at:

http://www.caddzone.com/acadx/acadx.htm

/*********************************************************/
/* Tony Tanzillo Design Automation Consulting */
/* Programming & Customization for AutoCAD & Compatibles */
/* ----------------------------------------------------- */
/* tony.tanzillo@worldnet.att.net */
/* http://www.caddzone.com */
/*********************************************************/
0 Likes
Message 9 of 63

Anonymous
Not applicable
I would assume the half distance of p1 too p2.

(setq d (/ (distance p1 p2)2))

But it could have been written like below:

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

rudy@cadentity.com

Eric Schneider wrote in message
news:223A93FD2DF838D2083BCEEEB4C7E328@in.WebX.SaUCah8kaAW...
> Thanks Frank. You know, I've seen this before somewhere (spoken with a
deep
> reddish hue from neck up).
>
> Now what the heck is d?
>
>
>
>
>
>
> --
> Eric S. eschneider@jensenprecast.com
>
0 Likes
Message 10 of 63

Anonymous
Not applicable
Do'h! (again) [you're on a roll today, Tony ]

Sorry Eric, I missed the Z displacement in your original post.

"Tony Tanzillo" wrote in message
news:39A44F15.1B2FD49C@worldnet.att.net...
| "R. Robert Bell" wrote:
| >
| > Don't feel bad Eric, it's not really *math* in this case (reduced to
| > giggling on the floor...)
|
| Are you giggling because what Frank posted doesn't
| work, or is there some other humor to this?
|
| Yes Robert, it really is *math* in this case.
|
0 Likes
Message 11 of 63

Anonymous
Not applicable
Just saw Tony's example.

Well put, Not 2d but 3d.

Reviewed the example Eric posted.

Cadentity.com wrote in message
news:5B4AF54856FDF1ECA09754522938FF0A@in.WebX.SaUCah8kaAW...
> I would assume the half distance of p1 too p2.
>
> (setq d (/ (distance p1 p2)2))
>
> But it could have been written like below:
>
> (setq p3 (polar p1 (angle p1 p2)(/ (distance p1 p2)2)))
>
> rudy@cadentity.com
>
> Eric Schneider wrote in message
> news:223A93FD2DF838D2083BCEEEB4C7E328@in.WebX.SaUCah8kaAW...
> > Thanks Frank. You know, I've seen this before somewhere (spoken with a
> deep
> > reddish hue from neck up).
> >
> > Now what the heck is d?
> >
> >
> >
> >
> >
> >
> > --
> > Eric S. eschneider@jensenprecast.com
> >
>
0 Likes
Message 12 of 63

Anonymous
Not applicable
Hey Tony did I miss something?

Must have.

Isn't this suppose to return a 'Z' differing also?

A2 + B2 = C2

rudy@cadentity.com

Tony Tanzillo wrote in message
news:39A44FAA.16A37871@worldnet.att.net...
> What Frank posted doesn't work in the 3D case, as
> original example requires.
>
> ;; (point-on-line )
> ;;
> ;; Returns a point on the line -
> ;; a specified distance from
>
> (defun point-on-line (p1 p2 dist / sc)
> (setq sc (/ dist (distance p1 p2)))
> (mapcar '+ p1
> (mapcar '*
> (mapcar '- p2 p1)
> (list sc sc sc)
> )
> )
> )
>
> Cliff Middleton wrote:
> >
> > So without using the (polar) function, what is the formula for Eric's
> > objective? (he said as his gauntlet cascaded to the floor...)
> >
> > Cliff
> >
> > R. Robert Bell wrote in message
> > news:1D358B650846B6463EEED3017A46CF93@in.WebX.SaUCah8kaAW...
> > | Don't feel bad Eric, it's not really *math* in this case (reduced to
> > | giggling on the floor...)
> > |
> > | --
> > | R. Robert Bell, MCSE
> > | Xtending the Power
> > | www.acadx.com
> > |
> > | "Frank Oquendo" wrote in message
> > | news:17C804620D8B5BFA92D3993CF9AC8371@in.WebX.SaUCah8kaAW...
> > | | (polar p1 (angle p1 p2) d)
> > | |
> > | | --
> > | | Attitudes are contagious. Is yours worth catching?
> > | | http://www.acadx.com
> > | |
> > | | "Eric Schneider" wrote in message
> > | | news:CEE5E0063099941F31A459F2A130DFD6@in.WebX.SaUCah8kaAW...
> > | | > Hello group,
> > | | >
> > | | > Using LISP, how would one calc a point (p3), between two other
points
> > | (p1
> > | | > and p2), a given distance (dist) from p1?
> > | | > Example:
> > | | >
> > | | > p1 = (2.0 2.5 0.0)
> > | | > p2 = (6.5 2.2 1.0)
> > | | > dist = 1.5
> > | | > p3 = ?
> > | | >
> > | | > I'm sure there is a simple formula, however, I failed 3rd grade
math
> > | five
> > | | > times.
> > | | > --
> > | | > Eric S. eschneider@jensenprecast.com
> > | | >
> > | |
> > |
>
> --
>
> Checkout the AcadX(tm) ActiveX Extension Library at:
>
> http://www.caddzone.com/acadx/acadx.htm
>
> /*********************************************************/
> /* Tony Tanzillo Design Automation Consulting */
> /* Programming & Customization for AutoCAD & Compatibles */
> /* ----------------------------------------------------- */
> /* tony.tanzillo@worldnet.att.net */
> /* http://www.caddzone.com */
> /*********************************************************/
0 Likes
Message 13 of 63

Anonymous
Not applicable
Tony,

Thanks once again. That's a nifty little function. Tight. Clean. Versatile.
--
Eric S. eschneider@jensenprecast.com
0 Likes
Message 14 of 63

Anonymous
Not applicable
"Cadentity.com" wrote:

> Hey Tony did I miss something?
>
> Must have.
>
> Isn't this suppose to return a 'Z' differing also?

It returns a point on the line, a measured distance
from the starting point. If the line is sloped, the
resulting point has a different z than the starting
point.

--

Checkout the AcadX(tm) ActiveX Extension Library at:

http://www.caddzone.com/acadx/acadx.htm

/*********************************************************/
/* Tony Tanzillo Design Automation Consulting */
/* Programming & Customization for AutoCAD & Compatibles */
/* ----------------------------------------------------- */
/* tony.tanzillo@worldnet.att.net */
/* http://www.caddzone.com */
/*********************************************************/
0 Likes
Message 15 of 63

Anonymous
Not applicable
I tried it and it returned the same 'Z' as one of the points.

One point had a 'Z' of 0. (zero).

The other had a 'Z' of 12.

The result was a 'Z' of 12 for the 3rd point, or in this case the actual
value.

I tried it (3)three times, differing points

And the result was the same, each returned the highest point of reference,
for the 'Z'.

If one 'Z' is 0 and the other 'Z' is 12, the returned 'Z' should have been
6, and not 12.

But with this in mind you also have to account for negative numbers, for a
'Z'.

Say for example the value was -6.5 on one 'Z' and 6.5 on the other.

Then the 'Z' would have to be 0(zero), for a point of reference.

Your function returns the first 'Z' it encounters within first point being
referenced.

rudy@cadentity.com

Tony Tanzillo wrote in message
news:39A46784.F9EAC982@worldnet.att.net...
> "Cadentity.com" wrote:
>
> > Hey Tony did I miss something?
> >
> > Must have.
> >
> > Isn't this suppose to return a 'Z' differing also?
>
> It returns a point on the line, a measured distance
> from the starting point. If the line is sloped, the
> resulting point has a different z than the starting
> point.
>
> --
>
> Checkout the AcadX(tm) ActiveX Extension Library at:
>
> http://www.caddzone.com/acadx/acadx.htm
>
> /*********************************************************/
> /* Tony Tanzillo Design Automation Consulting */
> /* Programming & Customization for AutoCAD & Compatibles */
> /* ----------------------------------------------------- */
> /* tony.tanzillo@worldnet.att.net */
> /* http://www.caddzone.com */
> /*********************************************************/
0 Likes
Message 16 of 63

Anonymous
Not applicable
"Cadentity.com" wrote:
>
> I tried it and it returned the same 'Z' as one of the points.
>
> ..........
>
> I tried it (3)three times, differing points

Try turning off your object snap.

--

Checkout the AcadX(tm) ActiveX Extension Library at:

http://www.caddzone.com/acadx/acadx.htm

/*********************************************************/
/* Tony Tanzillo Design Automation Consulting */
/* Programming & Customization for AutoCAD & Compatibles */
/* ----------------------------------------------------- */
/* tony.tanzillo@worldnet.att.net */
/* http://www.caddzone.com */
/*********************************************************/
0 Likes
Message 17 of 63

Anonymous
Not applicable
Nicely done! I obviously missed the reference to differing Z values. Quick
question: would it be any more efficient to simply scale the difference in
the Z values rather than the points as whole? It would be analogous to
calculating the 2D distance and projecting it onto the line. Also, how would
you recommend handling cases where one point or the other is 2D?

--
Attitudes are contagious. Is yours worth catching?
http://www.acadx.com

Tony Tanzillo wrote in message
news:39A44FAA.16A37871@worldnet.att.net...
> What Frank posted doesn't work in the 3D case, as
> original example requires.
>
> ;; (point-on-line )
> ;;
> ;; Returns a point on the line -
> ;; a specified distance from
>
> (defun point-on-line (p1 p2 dist / sc)
> (setq sc (/ dist (distance p1 p2)))
> (mapcar '+ p1
> (mapcar '*
> (mapcar '- p2 p1)
> (list sc sc sc)
> )
> )
> )
0 Likes
Message 18 of 63

Anonymous
Not applicable
Frank,
1) How would you calculate the 2D distance
from the supplied 3D distance?
2) If either or both of the point arguments are 2D
Tony's solution returns a 2D point calculated
using X,Y values only. This is consistent with
Autocad's treatment of mixed points.
(e.g. refer the AutoLisp distance function).
If you want a different result, (there are lots of
different possibilities), you will have
to program for it either by altering the
input points or massaging the output.
Regards Ian

Frank Oquendo wrote in message
news:581792CE3DFBB7F07490FB22F2F4669F@in.WebX.SaUCah8kaAW...
> Nicely done! I obviously missed the reference to differing Z values. Quick
> question: would it be any more efficient to simply scale the difference in
> the Z values rather than the points as whole? It would be analogous to
> calculating the 2D distance and projecting it onto the line. Also, how
would
> you recommend handling cases where one point or the other is 2D?
0 Likes
Message 19 of 63

Anonymous
Not applicable
This one is faster (45%, roughly measured):

(defun point-along-line (p1 p2 dist / sc)
(setq sc (/ dist (distance p1 p2)))
(mapcar '(lambda (p1 p2) (+ p1 (* sc (- p2 p1)))) p1 p2)
)

This one is slightly slower than the previous one, but wont fail with
"divide by zero error" if p1 equals p2:

(defun point-along-line (p1 p2 dist / d sc)
(if (zerop (setq d (distance p1 p2)))
p1
(progn
(setq sc (/ dist d))
(mapcar '(lambda (p1 p2) (+ p1 (* sc (- p2 p1)))) p1 p2)
)
)
)

This one is short and funny:

(c:cal "pld(p1,p2,d)")

Jadranko

Tony Tanzillo wrote in message <39A44FAA.16A37871@worldnet.att.net>...
>What Frank posted doesn't work in the 3D case, as
>original example requires.
>
>;; (point-on-line )
>;;
>;; Returns a point on the line -
>;; a specified distance from
>
>(defun point-on-line (p1 p2 dist / sc)
> (setq sc (/ dist (distance p1 p2)))
> (mapcar '+ p1
> (mapcar '*
> (mapcar '- p2 p1)
> (list sc sc sc)
> )
> )
>)
>
0 Likes
Message 20 of 63

Anonymous
Not applicable
Here's a repeat of my reply, since my message disappeared.

I don't use running object snaps, that a bad habit.

Your function still doesn't return the right point.

--
rudy@cadentity.com
Practical Utilities for Productive Solutions

Tony Tanzillo wrote in message
news:39A47E59.4102C2E8@worldnet.att.net...
> "Cadentity.com" wrote:
> >
> > I tried it and it returned the same 'Z' as one of the points.
> >
> > ..........
> >
> > I tried it (3)three times, differing points
>
> Try turning off your object snap.
>
> --
>
> Checkout the AcadX(tm) ActiveX Extension Library at:
>
> http://www.caddzone.com/acadx/acadx.htm
>
> /*********************************************************/
> /* Tony Tanzillo Design Automation Consulting */
> /* Programming & Customization for AutoCAD & Compatibles */
> /* ----------------------------------------------------- */
> /* tony.tanzillo@worldnet.att.net */
> /* http://www.caddzone.com */
> /*********************************************************/
0 Likes