viviancarvalho Posted December 14, 2010 Posted December 14, 2010 Can anyone please help me to find mid between 2 points defined in a lisp. Thanks & regards Vivian Quote
alanjt Posted December 14, 2010 Posted December 14, 2010 (defun AT:Midpoint (p1 p2) ;; Midpoint between two points ;; Alan J. Thompson, 04.23.09 (mapcar (function (lambda (a b) (/ (+ a b) 2.))) p1 p2) ) Quote
ccowgill Posted December 14, 2010 Posted December 14, 2010 (DEFUN c:Half3dpt (/ |Half3dpt| |pt1| |pt2|) (SETQ |pt1| (GETPOINT "\nHalf3dPT: Specify first point: ") |pt2| (GETPOINT |pt1| "\nHalf3dPT: Specify second point: ") ) ;_ end of SETQ (SETQ |Half3dpt| (MAPCAR '+ |pt1| (MAPCAR '/ (MAPCAR '- |pt2| |pt1|) '(2.0 2.0 2.0)) ) ;_ end of MAPCAR ) ;_ end of SETQ (COMMAND "_non" |Half3dpt|) ) ;_ end of DEFUN I have this in my archive of files, I've never used it, I always just used MTP when drafting. Quote
BlackBox Posted December 14, 2010 Posted December 14, 2010 (defun c:FOO (/ pt1 pt2 mid) (if (and (setq pt1 (getpoint "\n >> Specify first point: ")) (setq pt2 (getpoint "\n >> Specify second point: "))) (progn (prompt "\n<< The midpoint is: ") (setq mid [color=blue](mapcar '*[/color] [color=blue] (mapcar '+ pt1 pt2)[/color] [color=blue] '(0.5 0.5 0.5))[/color])))) Quote
David Bethel Posted December 14, 2010 Posted December 14, 2010 If GEOMCAL still loads automatically: ;;;MidPoint Between 2 Point Using CAL ;;;ARG -> 2 Points ;;;RET -> PointList (defun midpt (p1 p2) (cal "(p1+p2)/2")) -David Quote
viviancarvalho Posted December 14, 2010 Author Posted December 14, 2010 Thank you very much guys. Regards Vivian Quote
fuccaro Posted December 15, 2010 Posted December 15, 2010 If GEOMCAL still loads automatically: [...] And if it doesn't load by itself, you can use something like: (if (not (member "geomcal.arx" (arx))) (arxload "geomcal")) Quote
pBe Posted December 15, 2010 Posted December 15, 2010 (edited) Mid of two points (if not lisp (while in active command) <Shift+right click> <Ctrl+right click> [i]Mid between two points[/i] ) mid of rectangle (if not lisp (while in active command)<Ctrl+right click> [i]point filters [/i] .xz mid mid) ) just playing around Edited December 15, 2010 by pBe Quote
David Bethel Posted December 15, 2010 Posted December 15, 2010 And if it doesn't load by itself, you can use something like: (if (not (member "geomcal.arx" (arx))) (arxload "geomcal")) I've always thought that GEOMCAL was one of the best and yet most overlooked by most ( including myself ) addon for Autocad. It has some really neat functions. Quote
GP_ Posted December 15, 2010 Posted December 15, 2010 Mid of two points (if not lisp (while in active command) [b]M2P[/b] <click1> <click2> [i]Mid between two points[/i] ) just playing around (2) Quote
Lee Mac Posted December 15, 2010 Posted December 15, 2010 Midpoint of 'n' points [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] [color=black]Mid[/color] [b][color=RED]([/color][/b] _pointlist [b][color=RED])[/color][/b] [i][color=#990099];; © Lee Mac 2010 - www.lee-mac.com[/color][/i] [b][color=RED]([/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]lambda[/color][/b] [b][color=RED]([/color][/b] l [b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]/[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]apply[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]+[/color][/b] _pointlist[b][color=RED]))[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]list[/color][/b] l l l[b][color=RED])))[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]float[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]length[/color][/b] _pointlist[b][color=RED]))[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] Quote
BIGAL Posted December 16, 2010 Posted December 16, 2010 Autocad V12 real manual paper copy "Autocad Extras Manual" Chapter 4 Drawing aids GEOMCAL never throw the old books away, CAL has some really good functions. eg draw circle want a second half size C pick point 'cal rad*0.5 pick first circle done. I use it all the time for level checks on long and cross sections 1:50 = 20xrad wher rad is level diff between datum and RL Quote
pBe Posted December 16, 2010 Posted December 16, 2010 Another version using polar (nobody seem to use anymore) (defun c:FOO (/ pt1 pt2 mid) (if (and (setq pt1 (getpoint "\n >> Specify first point: ")) (setq pt2 (getpoint "\n >> Specify second point: ")) ) (progn (prompt "\n<< The midpoint is: ") [color=navy](setq mid (polar pt1 (angle pt1 pt2) (/ (distance pt1 pt2) 2.0)) [/color] ) ) ) ) just playing around (3) Quote
GP_ Posted December 16, 2010 Posted December 16, 2010 Another version using polar (nobody seem to use anymore) [color=navy](polar pt1 (angle pt1 pt2) (/ (distance pt1 pt2) 2.0))[/color] Only if the points have the same z coordinate. ------------------------------------------------ Mid of two points (3D) (defun c:FOO (/ pt1 pt2 ptmid) (if (and (setq pt1 (getpoint "\n >> Specify first point: ")) (setq pt2 (getpoint "\n >> Specify second point: ")) ) (progn (prompt "\n<< The midpoint is: ") [color=blue] (cal "[b]ptmid[/b]=plt(pt1,pt2,0.5)")[/color] ) ) ) just playing around (4) Quote
pBe Posted December 16, 2010 Posted December 16, 2010 (edited) hmmmmn you're right.. it follows pt1's Z coordinates, it never occured to me to test the code in 3D.. Good catch GP_ quick fix (defun c:FOO (/ pt1 pt2 mid) (if (and (setq pt1 (getpoint "\n >> Specify first point: ")) (setq pt2 (getpoint "\n >> Specify second point: ")) ) (progn (prompt "\n<< The midpoint is: ") (reverse (vl-list* (/ (+ (last pt1) (last pt2)) 2) (vl-remove (last mid) (setq mid (polar pt1 (angle pt1 pt2) (/ (distance pt1 pt2) 2.0)) ) ) ) ) ) ) ) What the heck Its getting worse Just playing around (5) Edited December 16, 2010 by pBe Quote
Lee Mac Posted December 16, 2010 Posted December 16, 2010 Bear in mind vl-remove will remove all instances of an item... Better: (reverse (cons (/ (+ (last pt1) (last pt2)) 2) (cdr (reverse (polar pt1 (angle pt1 pt2) (/ (distance pt1 pt2) 2.0)) But, I wouldn't really go the polar route with this one... Quote
alanjt Posted December 16, 2010 Posted December 16, 2010 M2P/MTP replacement for older versions of CAD: http://www.cadtutor.net/forum/showthread.php?11722-Contribute-a-tip-become-famous&p=323269&viewfull=1#post323269 Quote
pBe Posted December 17, 2010 Posted December 17, 2010 Bear in mind vl-remove will remove all instances of an item... Better: (reverse (cons (/ (+ (last pt1) (last pt2)) 2) (cdr (reverse (polar pt1 (angle pt1 pt2) (/ (distance pt1 pt2) 2.0)) But, I wouldn't really go the polar route with this one... Oops... geez, i'm not thinking straight.. must be the cold weather or its just me being me (always rushing and not testing) Thanks Lee... Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.