TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: ronjonp 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
-
(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))
-
There are tons of ways for mid point. -David
(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))
(defun mid_point (s e)
(mapcar '(lambda (a b) (* (+ a b) 0.5)) s e))
(defun midpt (p1 p2)
(cal "(p1+p2)/2"))
-
Thanks guys. :D
-
How do you setq a point halfway between two selected points?
There are tons of ways for mid point.
alas adding one more to the infinite number of ways:
(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))
)
)
"@"
)
-
We need the POLAR version, too :)
(defun midp (p1 p2)
(polar p1 (angle p1 p2)(/ (distance p1 p2) 2.0)))
)
-
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.
-
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.
(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)
)
)
)
-
Have a lookie here...
http://theswamp.org/phpBB2/viewtopic.php?t=2111&highlight=btwn
-
I use this a lot
;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)
-
The (polar) stuff can be incorrect when it comes to 3D points.
p1 '(1 0 1)
p2 '(4 5 6)
-David
-
Just for fun:
(defun midp ( p1 p2 )
(mapcar
'(lambda (a b) (- a (* 0.5 (- a b))))
p1 p2
)
)
-
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.
_non;'cal (cur + cur)/2;
-
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.
_non;'cal (cur + cur)/2;
I use it (CAL) in lisp frequently.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(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.