Discussion Groups

All Discussion Groups » Visual LISP, AutoLISP and General Customization Issues

Thread: Midpoint between two Getpoints?


Permlink Replies: 22 - Last Post: Feb 1, 2009 1:20 PM Last Post By: Joe Burke
structure_fire3

Posts: 24
Registered: 01/22/09
Midpoint between two Getpoints?
Posted: Jan 27, 2009 6:00 PM
  Click to reply to this thread Reply
I am trying to set a point as the midpoint between two (Getpoints..) Everything I think of is way too lengthy, is there a shortway to find this?


(setq pt1 (getpoint "\nPick LEFT point:")
pt2 (getpoint "\nPick RIGHT point:")
pt3 (...
andrew
Re: Midpoint between two Getpoints?
Posted: Jan 27, 2009 6:12 PM   in response to: structure_fire3 in response to: structure_fire3
  Click to reply to this thread Reply


you could draw a line between the two points, get
the mid point of the line then erase the line


<structure_fire3> wrote in message news:6112636@discussion.autodesk.com...
I
am trying to set a point as the midpoint between two (Getpoints..) Everything
I think of is way too lengthy, is there a shortway to find this? (setq pt1
(getpoint "\nPick LEFT point:") pt2 (getpoint "\nPick RIGHT point:") pt3
(...

lpseifert

Posts: 727
Registered: 08/08/06
Re: Midpoint between two Getpoints?
Posted: Jan 27, 2009 6:14 PM   in response to: structure_fire3 in response to: structure_fire3
  Click to reply to this thread Reply
(setq pt1 (getpoint "\nPick LEFT point:")
      pt2 (getpoint "\nPick RIGHT point:")
      x	  (/ (+ (car pt1) (car pt2)) 2)
      y	  (/ (+ (cadr pt1) (cadr pt2)) 2)
      z	  (/ (+ (caddr pt1) (caddr pt2)) 2)
      pt3 (list x y z)
)
structure_fire3

Posts: 24
Registered: 01/22/09
Re: Midpoint between two Getpoints?
Posted: Jan 27, 2009 6:21 PM   in response to: lpseifert in response to: lpseifert
  Click to reply to this thread Reply
Thanks, thats exactly what i was looking for.
MelFranks
Re: Midpoint between two Getpoints?
Posted: Jan 27, 2009 6:16 PM   in response to: structure_fire3 in response to: structure_fire3
  Click to reply to this thread Reply
One way: (setq midpt(polar p1(angle p1 p2)(/(distance p1 p2)2)))
Alternatively: (setq midpt(mapcar '* (mapcar '+ p1 p2) '(0.5 0.5 0.5)))

Regards,

Mel
Some Buddy
Re: Midpoint between two Getpoints?
Posted: Jan 27, 2009 6:29 PM   in response to: MelFranks in response to: MelFranks
  Click to reply to this thread Reply
< (setq midpt (mapcar '* (mapcar '+ p1 p2) '(0.5 0.5 0.5)))>

Now, this is elegant and slick :)

Regards
structure_fire3

Posts: 24
Registered: 01/22/09
Re: Midpoint between two Getpoints?
Posted: Jan 27, 2009 6:35 PM   in response to: Some Buddy in response to: Some Buddy
  Click to reply to this thread Reply
Thanks, worked like a charm. That was slick. =)
Bill Gilliss
Re: Midpoint between two Getpoints?
Posted: Jan 27, 2009 6:42 PM   in response to: MelFranks in response to: MelFranks
  Click to reply to this thread Reply


MelFranks wrote:

One way: (setq midpt(polar p1(angle p1 p2)(/(distance p1 p2)2)))
Alternatively: (setq midpt(mapcar '* (mapcar '+ p1 p2) '(0.5 0.5 0.5)))

Regards,

Mel




These are about as compact as you can get.



Note that when using points p1 and p2 with different Z-coordinates, the
(polar) approach above returns a point whose Z-coordinate is equal to
that of p1, while the (mapcar) approach returns a point whose
Z-coordinate is half-way between those of p1 and p2.


Some Buddy
Re: Midpoint between two Getpoints?
Posted: Jan 27, 2009 6:48 PM   in response to: Bill Gilliss in response to: Bill Gilliss
  Click to reply to this thread Reply


Good point you have here, Bill. Afterall, the
world's not flat and of course Mel knows it, but it was just answered in a blink
:)


"Bill Gilliss" <bill@realerthanreal.com> a écrit
dans le message de news: 6112683@discussion.autodesk.com...

MelFranks wrote:
One way: (setq midpt(polar p1(angle p1 p2)(/(distance p1 p2)2)))
Alternatively: (setq midpt(mapcar '* (mapcar '+ p1 p2) '(0.5 0.5 0.5)))

Regards,

Mel

These are about as compact as you can get.


Note that when using points p1 and p2 with different Z-coordinates,
the (polar) approach above returns a point whose Z-coordinate is equal to that
of p1, while the (mapcar) approach returns a point whose Z-coordinate is
half-way between those of p1 and p2.

Kent Cooper
Re: Midpoint between two Getpoints?
Posted: Jan 27, 2009 7:06 PM   in response to: MelFranks in response to: MelFranks
  Click to reply to this thread Reply
Or, other-alternatively [same effect, but just slightly shorter]:

(setq midpt (mapcar '/ (mapcar '+ p1 p2) '(2 2 2)))

--
Kent Cooper


"MelFranks" wrote...
....
Alternatively: (setq midpt(mapcar '* (mapcar '+ p1 p2) '(0.5 0.5 0.5)))
....
Bill Gilliss
Re: Midpoint between two Getpoints?
Posted: Jan 27, 2009 10:14 PM   in response to: Kent Cooper in response to: Kent Cooper
  Click to reply to this thread Reply


Kent Cooper wrote:

Or, other-alternatively [same effect, but just slightly shorter]:

(setq midpt (mapcar '/ (mapcar '+ p1 p2) '(2 2 2)))



Shorter yet, in terms of characters:



(setq midpt (c:cal
"(p1+p1)/2"))



unless you count the required initial (arxload "geomcal").



The meaning is perfectly clear, too.





-Bill



Some Buddy
Re: Midpoint between two Getpoints?
Posted: Jan 27, 2009 10:40 PM   in response to: Bill Gilliss in response to: Bill Gilliss
  Click to reply to this thread Reply


You mean (setq midpt (c:cal "(p1+p2)/2")), but it's been a long day :)

 

Yes, this one of yours is really
shorter, in terms of functions calls
or otherwise I can do a shorter one too:

 

(setq mp (c:cal "(p1+p2)*.5"))

 

 ;^)

 

And let's assume that the arx is loaded, Or
at least, DEMANDLOAD is set to 2 or 3.

 

Regards




"Bill Gilliss" <bill@realerthanreal.com> a écrit
dans le message de news: 6112911@discussion.autodesk.com...

Kent Cooper wrote:
Or, other-alternatively [same effect, but just slightly shorter]:

(setq midpt (mapcar '/ (mapcar '+ p1 p2) '(2 2 2)))

Shorter
yet, in terms of characters:

(setq midpt (c:cal
"(p1+p1)/2"))

unless you count the required initial
(arxload
"geomcal").

The meaning is perfectly clear,
too.


-Bill

Bill Gilliss
Re: Midpoint between two Getpoints?
Posted: Jan 28, 2009 12:34 AM   in response to: Some Buddy in response to: Some Buddy
  Click to reply to this thread Reply


Some
Buddy wrote:


You mean (setq midpt (c:cal "(p1+p2)/2")), but it's been a long day :)

 

Yes, this one of yours is
really shorter, in terms of functions calls
or otherwise I can do a shorter one too:

 

(setq mp (c:cal "(p1+p2)*.5"))





You got me on the (p1+p1).



But /2  is still
shorter than  *.5



While we are at it, let's get rid of all spaces and both earlier
(getpoint) functions with



(set'm(c:cal"(cur+cur)/2"))



27 characters.



Joe Burke
Re: Midpoint between two Getpoints?
Posted: Jan 28, 2009 12:55 PM   in response to: Bill Gilliss in response to: Bill Gilliss
  Click to reply to this thread Reply
Bill

IMO, calling cal is not a good idea since it is not loaded by default.

I would use a LISP function similar to what Kent suggested.

Joe Burke


"Bill Gilliss" wrote in message
news:6113023@discussion.autodesk.com...
Some Buddy wrote:
You mean (setq midpt (c:cal "(p1+p2)/2")), but it's been a long day :)

Yes, this one of yours is really shorter, in terms of functions calls or otherwise I
can do a shorter one too:

(setq mp (c:cal "(p1+p2)*.5"))

You got me on the (p1+p1).

But /2 is still shorter than *.5

While we are at it, let's get rid of all spaces and both earlier (getpoint) functions
with

(set'm(c:cal"(cur+cur)/2"))

27 characters.
Bill Gilliss
Re: Midpoint between two Getpoints?
Posted: Jan 28, 2009 2:22 PM   in response to: Joe Burke in response to: Joe Burke
  Click to reply to this thread Reply
Yeah, yeah - we agreed in an earlier post that geomcal would need to be
loaded, just as (vl-load-com) must be. This was just a little contest to
find the most compact midpoint routine once such preliminaries were
taken care of.

Joe Burke wrote:
Bill

IMO, calling cal is not a good idea since it is not loaded by default.

I would use a LISP function similar to what Kent suggested.

Joe Burke
Joe Burke
Re: Midpoint between two Getpoints?
Posted: Jan 28, 2009 2:43 PM   in response to: Bill Gilliss in response to: Bill Gilliss
  Click to reply to this thread Reply
Bill,

I stand by my statement. Cal and the time to first load it simply isn't needed.

It's not a good idea since the goal can be met with a simple LISP function as Kent
suggested.


"Bill Gilliss" wrote in message
news:6113238@discussion.autodesk.com...
Yeah, yeah - we agreed in an earlier post that geomcal would need to be
loaded, just as (vl-load-com) must be. This was just a little contest to
find the most compact midpoint routine once such preliminaries were
taken care of.

Joe Burke wrote:
Bill

IMO, calling cal is not a good idea since it is not loaded by default.

I would use a LISP function similar to what Kent suggested.

Joe Burke
Some Buddy
Re: Midpoint between two Getpoints?
Posted: Jan 28, 2009 1:49 PM   in response to: Bill Gilliss in response to: Bill Gilliss
  Click to reply to this thread Reply


OK, you win :)

Kent Cooper
Re: Midpoint between two Getpoints?
Posted: Jan 28, 2009 2:27 PM   in response to: Some Buddy in response to: Some Buddy
  Click to reply to this thread Reply
Well, to take it perhaps to the extreme, if one *really* wanted to minimize the total amount of
code, and if this is something used within many different routines, one could put a function in a
place where it would be available in any drawing, such as in acaddoc.lsp:

(defun midway (p1 p2)
(mapcar '/ (mapcar '+ p1 p2) '(2 2 2)); or other approach
)

and then just call that function within each of the various routines:

(midway pt1 pt2)

as some do with functions like (dtr) [degrees-to-radians conversion], etc.

--
Kent Cooper


"Some Buddy" wrote...
OK, you win :)
Joe Burke
Re: Midpoint between two Getpoints?
Posted: Jan 28, 2009 2:51 PM   in response to: Kent Cooper in response to: Kent Cooper
  Click to reply to this thread Reply
Also keep in mind the M2P and MTP commands which are available in recent versions at
any getpoint prompt.


"Kent Cooper" wrote in message
news:6113211@discussion.autodesk.com...
Well, to take it perhaps to the extreme, if one *really* wanted to minimize the total
amount of
code, and if this is something used within many different routines, one could put a
function in a
place where it would be available in any drawing, such as in acaddoc.lsp:

(defun midway (p1 p2)
(mapcar '/ (mapcar '+ p1 p2) '(2 2 2)); or other approach
)

and then just call that function within each of the various routines:

(midway pt1 pt2)

as some do with functions like (dtr) [degrees-to-radians conversion], etc.

--
Kent Cooper


"Some Buddy" wrote...
OK, you win :)
Kent Cooper
Re: Midpoint between two Getpoints?
Posted: Jan 28, 2009 3:02 PM   in response to: Joe Burke in response to: Joe Burke
  Click to reply to this thread Reply
Wish I had a more "recent version" than I do, sometimes....
--
Kent Cooper


"Joe Burke" wrote...
Also keep in mind the M2P and MTP commands which are available in recent versions at
any getpoint prompt.
....
Bill Gilliss
Re: Midpoint between two Getpoints?
Posted: Jan 28, 2009 3:13 PM   in response to: Kent Cooper in response to: Kent Cooper
  Click to reply to this thread Reply


Doh!



(setq c"mtp"a b)



16 characters, including spaces. I think Joe wins, even if he
wasn't playing.












Joe Burke
Re: Midpoint between two Getpoints?
Posted: Feb 1, 2009 1:20 PM   in response to: Kent Cooper in response to: Kent Cooper
  Click to reply to this thread Reply
Hi Kent,

I think the M2P and MTP commands were added at 2005.

Joe

"Kent Cooper" wrote in message
news:6113273@discussion.autodesk.com...
Wish I had a more "recent version" than I do, sometimes....
--
Kent Cooper


"Joe Burke" wrote...
Also keep in mind the M2P and MTP commands which are available in recent versions at
any getpoint prompt.
....
Chatchawal

Posts: 120
Registered: 09/22/08
Re: Midpoint between two Getpoints?
Posted: Jan 28, 2009 1:00 AM   in response to: structure_fire3 in response to: structure_fire3
  Click to reply to this thread Reply
My favourite: (mapcar '/ (mapcar '+ p1 p2) (list 2.0 2.0 2.0))
Alternate : (mapcar '(lambda (x y) (/ (+ x y) 2.0)) p1 p2)