Author Topic: Midpoint  (Read 5354 times)

0 Members and 1 Guest are viewing this topic.

ronjonp

  • Needs a day job
  • Posts: 7527
Midpoint
« on: September 28, 2004, 03:40:48 PM »
How do you setq a point halfway between two selected points?

(setq pt1 (getpoint ...
(setq pt2 (getpoint ...

(setq mdpt (....

Thanks,

Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Midpoint
« Reply #1 on: September 28, 2004, 03:45:32 PM »
Code: [Select]

   (setq PT1 (getpoint "\nFirst point: ")); Getting 1st point from user
   (setq X1 (car PT1))
   (setq Y1 (cadr PT1))
   (setq Z1 (caddr PT1))
   (setvar "osmode" 128 )
   (setq PT2 (getpoint PT1 "\nSecond point: ")); Get 2nd point from user
   (setvar "orthomode" 1 )
   (setq X2 (car PT2))
   (setq Y2 (cadr PT2))
   (setq Z2 (caddr PT2))
   (setq XMID (/ (+ X1 X2) 2))
   (setq YMID (/ (+ Y1 Y2) 2))
   (setq ZMID (/ (+ Z1 Z2) 2))
   (setq MPT (list XMID YMID ZMID))
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

David Bethel

  • Swamp Rat
  • Posts: 656
Midpoint
« Reply #2 on: September 28, 2004, 03:47:27 PM »
There are tons of ways for mid point.  -David

Code: [Select]
(defun mid_pt (p1 p2 / xp yp zp)               ;Mid Point
    (setq xp (+ (nth 0 p1) (* 0.5 (- (nth 0 p2) (nth 0 p1)))))
    (setq yp (+ (nth 1 p1) (* 0.5 (- (nth 1 p2) (nth 1 p1)))))
    (setq zp (+ (nth 2 p1) (* 0.5 (- (nth 2 p2) (nth 2 p1)))))
    (list xp yp zp))


Code: [Select]
(defun mid_point (s e)
   (mapcar '(lambda (a b) (* (+ a b) 0.5)) s e))



Code: [Select]
(defun midpt (p1 p2)
  (cal "(p1+p2)/2"))
R12 Dos - A2K

ronjonp

  • Needs a day job
  • Posts: 7527
Midpoint
« Reply #3 on: September 28, 2004, 03:57:18 PM »
Thanks guys.   :D

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

whdjr

  • Guest
Midpoint
« Reply #4 on: September 28, 2004, 03:59:29 PM »
Quote from: ronjonp
How do you setq a point halfway between two selected points?

Quote from: David D Bethel
There are tons of ways for mid point.

alas adding one more to the infinite number of ways:
Code: [Select]
(defun c:mid3d (/ pt1 pt2)
  (setq pt1 (getpoint "\nPick first point: ")
        pt2 (getpoint "\nPick second point: ")
  )
  (setvar
    "lastpoint"
    (mapcar '+
            pt1
            (mapcar '/ (mapcar '- pt2 pt1) '(2.0 2.0 2.0))
    )
  )
  "@"
)

SMadsen

  • Guest
Midpoint
« Reply #5 on: September 28, 2004, 04:00:35 PM »
We need the POLAR version, too :)

Code: [Select]
(defun midp (p1 p2)
  (polar p1 (angle p1 p2)(/ (distance p1 p2) 2.0)))
)

whdjr

  • Guest
Midpoint
« Reply #6 on: September 28, 2004, 04:02:45 PM »
I like the version using the "lastpoint" system variable so you can still have your running osnaps set without the system going into a frenzy.

SMadsen

  • Guest
Midpoint
« Reply #7 on: September 28, 2004, 04:35:45 PM »
Until 2005 I used a combination that returned "@" when in a command and a point otherwise. Code below.

Now midpoint has become a modifier in 2005, by typing either M2P or MTP.

Code: [Select]
(defun midp (/ p1 p2)
  (cond ((and (setq p1 (getpoint "\First point: "))
              (setq p2 (getpoint "\Second point: "))
              (setq p3 (mapcar (function (lambda (n) (/ n 2.0))) (mapcar '+ p1 p2)))
              (setvar "LASTPOINT" p3)
         )
         (if (> (getvar "CMDACTIVE") 0) "@" p3)
        )
  )
)

M-dub

  • Guest
Midpoint
« Reply #8 on: September 28, 2004, 04:49:13 PM »

danny

  • Guest
Midpoint
« Reply #9 on: September 28, 2004, 05:09:55 PM »
I use this a lot
Code: [Select]


;draw a line from the mid of 2 selected points
(DEFUN C:LM()
(setq oldos (getvar "osmode"))
(setvar "osmode" 703)
(setq pt1 (getpoint "\nPick first point: "))
(setq pt2 (getpoint pt1 "\nPick second point: "))
(setq ang (angle pt1 pt2))
(setq dist (/ (distance pt1 pt2) 2.0))
(setq pt3(polar pt1 ang dist))
(command "line" pt3)

David Bethel

  • Swamp Rat
  • Posts: 656
Midpoint
« Reply #10 on: September 28, 2004, 06:02:01 PM »
The (polar) stuff can be incorrect when it comes to 3D points.  

p1 '(1 0 1)
p2 '(4 5 6)


-David
R12 Dos - A2K

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Midpoint
« Reply #11 on: September 28, 2004, 07:13:10 PM »
Just for fun:
Code: [Select]
(defun midp ( p1 p2 )
    (mapcar
       '(lambda (a b) (- a (* 0.5 (- a b))))
        p1 p2
    )    
)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

hudster

  • Gator
  • Posts: 2848
Midpoint
« Reply #12 on: September 29, 2004, 04:00:24 AM »
This one isn't for use within a lisp, but can be used with any command to find the midpoint between any two points.

I use it as a macro button.

Code: [Select]
_non;'cal (cur + cur)/2;
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

CADaver

  • Guest
Midpoint
« Reply #13 on: September 29, 2004, 07:37:19 AM »
Quote from: Hudster
This one isn't for use within a lisp, but can be used with any command to find the midpoint between any two points.

I use it as a macro button.

Code: [Select]
_non;'cal (cur + cur)/2;
I use it (CAL) in lisp frequently.

Code: [Select]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq dst 1.0
      frc 0.5)
(defun cvd ()
(if (= cal nil)
(arxload "geomcal")
)
(setq pt1 (getpoint "\n Select First Point Of Vector")
      pt2 (getpoint "\n Select Second Point Of Vector")
)
 (IF (SETQ Ndst (GETdist (STRCAT "Enter Distance along Vector <" (rtos dst) ">:  ")))
(setq dst ndst)
 )
(cal "pld(pt1,pt2,dst)")
)
(defun cvt ()
(if (= cal nil)
(arxload "geomcal")
)
(setq pt1 (getpoint "\n Select First Point Of Vector")
      pt2 (getpoint "\n Select Second Point Of Vector")
)
 (IF (SETQ Nfrc (GETdist (STRCAT "Enter Percentage of Distance along Vector <" (rtos frc 2 6) ">:  ")))
(setq frc nfrc)
 )
(cal "plt(pt1,pt2,frc)")
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


From the above, (CVT) and (CVD) can be used like keyed-in osnaps to  find a point along a vector between two points based on a percentage of the distance between the points (CVT) or an absolute distance.