Jump to content

Recommended Posts

Posted

Can anyone please help me to find mid between 2 points defined in a lisp.

 

Thanks & regards

Vivian

Posted
(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)
)

Posted
(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.

Posted
(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]))))

Posted

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

Posted

Thank you very much guys.

 

Regards

Vivian

Posted
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"))

Posted (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 by pBe
Posted
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.

Posted

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)

 

:)

Posted

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]

Posted

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

Posted

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)

 

:)

Posted
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)

 

:)

Posted (edited)

hmmmmn you're right.. :lol:

 

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 :lol:

Its getting worse :lol:

 

Just playing around (5)

Edited by pBe
Posted

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...

Posted
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... :shock:

geez, i'm not thinking straight.. must be the cold weather or its just me being me (always rushing and not testing)

Thanks Lee... :)

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...