|
Replies:
22
-
Last Post:
Feb 1, 2009 1:20 PM
Last Post By: Joe Burke
|
|
|
Posts:
24
Registered:
01/22/09
|
|
|
|
Midpoint between two Getpoints?
Posted:
Jan 27, 2009 6:00 PM
|
|
|
|
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 (...
|
|
|
|
|
|
|
|
Re: Midpoint between two Getpoints?
Posted:
Jan 27, 2009 6:12 PM
in response to: structure_fire3
|
|
|
you could draw a line between the two points, get the mid point of the line then erase the line 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 (...
|
|
|
|
|
Posts:
727
Registered:
08/08/06
|
|
|
|
Re: Midpoint between two Getpoints?
Posted:
Jan 27, 2009 6:14 PM
in response to: structure_fire3
|
|
|
(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)
)
|
|
|
|
|
Posts:
24
Registered:
01/22/09
|
|
|
|
Re: Midpoint between two Getpoints?
Posted:
Jan 27, 2009 6:21 PM
in response to: lpseifert
|
|
|
|
Thanks, thats exactly what i was looking for.
|
|
|
|
|
|
|
|
|
Re: Midpoint between two Getpoints?
Posted:
Jan 27, 2009 6:16 PM
in response to: structure_fire3
|
|
|
|
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
|
|
|
|
|
|
|
|
|
Re: Midpoint between two Getpoints?
Posted:
Jan 27, 2009 6:29 PM
in response to: MelFranks
|
|
|
|
< (setq midpt (mapcar '* (mapcar '+ p1 p2) '(0.5 0.5 0.5)))>
Now, this is elegant and slick :)
Regards
|
|
|
|
|
Posts:
24
Registered:
01/22/09
|
|
|
|
Re: Midpoint between two Getpoints?
Posted:
Jan 27, 2009 6:35 PM
in response to: Some Buddy
|
|
|
|
Thanks, worked like a charm. That was slick. =)
|
|
|
|
|
|
|
|
|
Re: Midpoint between two Getpoints?
Posted:
Jan 27, 2009 6:42 PM
in response to: MelFranks
|
|
|
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.
|
|
|
|
|
|
|
|
|
Re: Midpoint between two Getpoints?
Posted:
Jan 27, 2009 6:48 PM
in response to: Bill Gilliss
|
|
|
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 :)
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.
|
|
|
|
|
|
|
|
|
Re: Midpoint between two Getpoints?
Posted:
Jan 27, 2009 7:06 PM
in response to: MelFranks
|
|
|
|
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))) ....
|
|
|
|
|
|
|
|
|
Re: Midpoint between two Getpoints?
Posted:
Jan 27, 2009 10:14 PM
in response to: Kent Cooper
|
|
|
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
|
|
|
|
|
|
|
|
|
Re: Midpoint between two Getpoints?
Posted:
Jan 27, 2009 10:40 PM
in response to: Bill Gilliss
|
|
|
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
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
|
|
|
|
|
|
|
|
|
Re: Midpoint between two Getpoints?
Posted:
Jan 28, 2009 12:34 AM
in response to: Some Buddy
|
|
|
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 *.5While 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.
|
|
|
|
|
|
|
|
|
Re: Midpoint between two Getpoints?
Posted:
Jan 28, 2009 12:55 PM
in response to: Bill Gilliss
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
Re: Midpoint between two Getpoints?
Posted:
Jan 28, 2009 2:22 PM
in response to: Joe Burke
|
|
|
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
|
|
|
|
|
|
|
|
|
Re: Midpoint between two Getpoints?
Posted:
Jan 28, 2009 2:43 PM
in response to: Bill Gilliss
|
|
|
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
|
|
|
|
|
|
|
|
|
Re: Midpoint between two Getpoints?
Posted:
Jan 28, 2009 1:49 PM
in response to: Bill Gilliss
|
|
|
|
|
|
|
|
|
|
|
|
Re: Midpoint between two Getpoints?
Posted:
Jan 28, 2009 2:27 PM
in response to: Some Buddy
|
|
|
|
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 :)
|
|
|
|
|
|
|
|
|
Re: Midpoint between two Getpoints?
Posted:
Jan 28, 2009 2:51 PM
in response to: Kent Cooper
|
|
|
|
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 :)
|
|
|
|
|
|
|
|
|
Re: Midpoint between two Getpoints?
Posted:
Jan 28, 2009 3:02 PM
in response to: Joe Burke
|
|
|
|
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. ....
|
|
|
|
|
|
|
|
|
Re: Midpoint between two Getpoints?
Posted:
Jan 28, 2009 3:13 PM
in response to: Kent Cooper
|
|
|
Doh!
(setq c"mtp"a b)
16 characters, including spaces. I think Joe wins, even if he wasn't playing.
|
|
|
|
|
|
|
|
|
Re: Midpoint between two Getpoints?
Posted:
Feb 1, 2009 1:20 PM
in response to: Kent Cooper
|
|
|
|
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. ....
|
|
|
|
|
Posts:
120
Registered:
09/22/08
|
|
|
|
Re: Midpoint between two Getpoints?
Posted:
Jan 28, 2009 1:00 AM
in response to: structure_fire3
|
|
|
|
My favourite: (mapcar '/ (mapcar '+ p1 p2) (list 2.0 2.0 2.0)) Alternate : (mapcar '(lambda (x y) (/ (+ x y) 2.0)) p1 p2)
|
|
|
|
|
|