Jump to content

create a point in vertical distance from a line


Guest

Recommended Posts

Hi, i am trying to convert hanhphuc lisp from an old post to create a point in vertical distance from a line like the photo. Can any one help me ?

 

(defun c:test (/ os asin _line p1 p2 d2 l1 ad d ok p ang d3 dir ip )
; hanhphuc 25.02.2015
(COMMAND "_layer" "_m" "new_point" "_c" "10" "" "")
(setvar 'pdmode 35)
 (setq os    (getvar 'osmode)
asin  '((x) (atan (/ x (sqrt (+ 1.0 (* x (- x)))))))
_line '((a lst) (foreach x lst (entmake (list '(0 . "LINE") (cons 10 a) (cons 11 x)))))
) ;_ end of setq
 (setvar 'osmode 1)
 (if (and (setq p1 (getpoint "\nPick point A: "))
   (setq p2 (getpoint p1 "\nPick point B: "))
   (setq d2 (getdist p2 "\nInput perpendicular length: "))   
   (setq l1  (list p1 p2)
	 ad  (mapcar ''((x) (apply x l1)) '(angle distance))
	 d   (cadr ad)
         ok (< d2 d))
   (setq p (getpoint "\nPick side to draw.. "))
   ) ;_ end of and
   (progn (setq ang (asin (/ d2 d))
	 d3  (* d (cos ang))
	 dir (car ad)
	 ip  (apply 'if
		    (vl-list*
			      (minusp (- (* (- (cadr p) (cadr p1)) (cos dir)) (* (- (car p) (car p1)) (sin dir))))
			      (mapcar ''((f) (polar p1 ((eval f) dir ang) d3)) '(- +))
			      ) ;_ end of vl-list*
		    ) ;_ end of apply
	 ) ;_ end of setq
   (_line ip l1)
   ) ;_ end of progn

(if (not ok)  (alert "Perpendicular line exceeds length of A to B!") )

   ) ;_ end of if
 (setvar 'osmode os)
(command "setvar" "clayer" "0")
 (princ)
 ) ;_ end of defun

 

Thanks

1.jpg

Link to comment
Share on other sites

A lot of code for a simple task think about doing this way set up your angle units and angle direction look at UNITS, set variables angdir and aunits, pick p1 pick p2, get angle, no need to pick side as you always add 90 to angle but use a positive or negative value for the side direction. new point is then simply a polar from pt2. The polar command allows a negative distance so will draw in opposite direction to angle.

 

(SETVAR "ANGBASE" 0.0)
(SETVAR "ANGDIR" 0)
(SETVAR "AUNITS" 3)
(SETVAR "AUPREC" 6)
(setvar 'osmode 512)
(setq pt1 (getpoint "Pick point A"))
(setq pt2 (getpoint "pick point B"))
(setq ang (angle pt1 pt2))
(setq dist (getreal "Enter dist + for left - for right"))
(setq pt3 (polar pt2 (+ (/ pi 2.0) ang) dist))
(command "line" pt2 pt3 "")

Link to comment
Share on other sites

Hi Bigal.Thanks for the replay. I do same changes to your code.Is it posible to create only a point and not a line?

 

(defun c:test (/ pt1 pt2 pt3 ang dist )
(COMMAND "_layer" "_m" "new_point" "_c" "10" "" "")
(setvar 'pdmode 35)
(setvar "unitmode" 0)
(setvar "aunits" 2)
(setvar "angbase" (/ pi 2))
(setvar "angdir" 1)
(setvar "auprec" 4)
(setvar "lunits" 2)
(setvar "luprec" 3)
(setvar "dimzin" 0)
(setq pt1 (getpoint "Pick point A"))
(setq pt2 (getpoint "pick point B"))
(setq ang (angle pt1 pt2))
(setq dist (getreal "Enter dist + for left - for right"))
(setq pt3 (polar pt2 (+ (/ pi 2.0) ang) dist))
(command "line" pt2 pt3 "")
(command "setvar" "clayer" "0")
(princ)
) 

 

Thanks

Link to comment
Share on other sites

i fix it .Thanks

 

(defun c:test (/ pt1 pt2 pt3 ang dist )
(COMMAND "_layer" "_m" "new_point" "_c" "10" "" "")
(setvar 'pdmode 35)
(setvar "unitmode" 0)
(setvar "aunits" 2)
(setvar "angbase" (/ pi 2))
(setvar "angdir" 1)
(setvar "auprec" 4)
(setvar "lunits" 2)
(setvar "luprec" 3)
(setvar "dimzin" 0)
(setq pt1 (getpoint "Pick point A"))
(setq pt2 (getpoint "pick point B"))
(setq ang (angle pt1 pt2))
(setq dist (getreal "Enter dist + for left - for right"))
(setq pt3 (polar pt2 (+ (/ pi 2.0) ang) dist))
;(command "line" pt2 pt3 "")
(command "point" pt3 "")
(command "setvar" "clayer" "0")
(princ)
) 

Link to comment
Share on other sites

You should add at start save existing units settings then restore at end if they are different than what you normally use.

 

(setq oldsnap (getvar "osmode"))
.....
(setvar "osmode" oldsnap)

Link to comment
Share on other sites

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