Abrasive Posted August 13, 2022 Posted August 13, 2022 What I would like to do is start a line then, enter the second set of points but based on the location of start point? What I need is to enter and draw the hypotenuse, by entering the hypotenuse length and the rise of the triangle. The lines could be any directions but the "rise" will always be smaller than the base. If possible the routine would find the direction of the offset so I don't have to enter the sign (+ or -) The end result will be a closed shape. Thanks In advance Quote
Abrasive Posted August 13, 2022 Author Posted August 13, 2022 (edited) I'm still not good at explaining. I need to draw Line 2 from entering 2 and 3 based from the start point Edited August 13, 2022 by Tom Matson Quote
Steven P Posted August 13, 2022 Posted August 13, 2022 A bit basic but it works OK, you might want to look at the loop and options to continue with the next line segment or end the lines there, a check that the supplied distances are valid (triangles... can it be made up), and also a check if hypotenuse distance added is +/- to draw the line left or right.. nut this is the basics - will leave it up to you to change or ask for more details and help (defun c:MakeLines ( / Pt1 Pt2 Hipo VD HD ss) (setq Pt1 (getpoint "\nSelect Start Point")) (setq Hipo (getreal "Enter hypotenuse Distance: ")) (setq VD (getreal "Enter Vertical Distance: ")) (setq HD (sqrt ( - (* Hipo Hipo) (* vd vd)))) (setq Pt2 (mapcar '+ (list HD VD 0) Pt1 )) (command "Line" Pt1 Pt2 "") (setq Pt1 Pt2) (setq ss (ssadd (entlast))) (setq Loop "Yes") (while (= Loop "Yes") (setq Hipo (getreal "Enter hypotenuse Distance: ")) (setq VD (getreal "Enter Vertical Distance: ")) (setq HD (sqrt ( - (* Hipo Hipo) (* vd vd)))) (setq Pt2 (mapcar '+ (list HD VD 0) Pt1 )) (command "Line" Pt1 Pt2 "") (setq ss (ssadd (entlast) ss )) (setq Pt1 Pt2) (initget "Y N") (if (= (getkword "Continue [Y/N]: ") "N")(setq Loop "No")) ) (command "_.pedit" "_m" ss "" "Y" "_j" "" "") ) 1 Quote
Abrasive Posted September 15, 2022 Author Posted September 15, 2022 This works Nice! Is there a way to capture what direction or angle the mouse is dragged based on start point? Then draw the hypotenuse IN THAT "quadrant". Based on Direction angle Check for a threshold value say: "greater than zero but less than 45" = quadrant 1. = +Pt1 +Pt2 "greater than 45 but less than 90" = quadrant 2. = + Pt2 +Pt1 (points both "+" just switched) "greater than 90 but less than 135" = quadrant 3. = +Pt2 -Pt1 (Pt1 sign changed) "greater than 135 but less than 180" = quadrant 4. = -Pt1 +Pt2 ... etc etc Quote
mhupp Posted September 15, 2022 Posted September 15, 2022 53 minutes ago, Tom Matson said: Is there a way to capture what direction or angle the mouse is dragged based on start point? grread But have never used the function before. Quote
Abrasive Posted September 15, 2022 Author Posted September 15, 2022 That's what I was looking at I Just don't how to use it in code to test for the quadrant. Quote
mhupp Posted September 15, 2022 Posted September 15, 2022 this lisp uses it. http://www.lee-mac.com/objectalign.html Quote
Jonathan Handojo Posted September 16, 2022 Posted September 16, 2022 Something like this? I don't know about the one between 45-90 because your OP mentioned "rise", so I'm not sure what you mean. (defun c:foo ( / ep gr grp grv hor hyp msg off pt ris) (and (setq ang (* 0.5 pi) msg "\nSpecify point to place <exit>: " pt (getpoint "\nSpecify starting point <exit>: ")) (while (and (setq hyp (getdist pt "\nSpecify hypothenuse length <exit>: ")) (progn (while (and (setq ris (getdist pt "\nSpecify rise length <exit>: ")) (if (>= ris hyp) (princ "\nRise cannot exceed hypothenuse.")) ) ) ris ) (progn (setq hor (sqrt (- (expt hyp 2) (expt ris 2))) off (mapcar 'abs (list hor ris 0.0)) ) (princ msg) (while (progn (setq gr (grread t 15 0) grp (cadr gr) grv (car gr) ) (redraw) (cond ( (member grv '(5 3)) (setq ep (mapcar '+ pt (mapcar '* off (list (if (> (car grp) (car pt)) 1 -1) (if (> (cadr grp) (cadr pt)) 1 -1) 1 ) ) ) ) (grvecs (list -7 pt ep)) (cond ( (= grv 5)) ( (progn (entmake (list '(0 . "LINE") (cons 10 (trans pt 1 0)) (cons 11 (trans ep 1 0)) ) ) (setq pt ep) nil ) ) ) ) ( (= grv 2) (cond ( (member grp '(13 32)) (setq hyp nil)) ( t ) ) ) ( (= grv 25) (setq hyp nil) ) ( t ) ) ) ) (redraw) hyp ) ) ) ) (princ) ) Quote
Abrasive Posted September 16, 2022 Author Posted September 16, 2022 @Jonathan Handojo For me it crashes after it asks me to "\nSpecify point to place ..? As far as "rise" that's what I'm calling the short leg of the triangle Quote
Tsuky Posted September 16, 2022 Posted September 16, 2022 And this? (defun where_cursor (alpha / ) (cond ((not (eq (rem alpha (/ (* 3 pi) 2)) alpha)) (setq dx '+ dy '-) ) ((not (eq (rem alpha pi) alpha)) (setq dx '- dy '-) ) ((not (eq (rem alpha (/ pi 2)) alpha)) (setq dx '- dy '+) ) (T (setq dx '+ dy '+) ) ) ) (defun c:My_pline ( / h_d v_d tmp dx dy) (initget 9) (setvar "LASTPOINT" (getpoint "\nStart point?: ")) (command "_.pline" (getvar "LASTPOINT") (while (not (zerop (getvar "cmdactive"))) (initget 6) (setq h_d (getdist (getvar "LASTPOINT") "\nEnter hypotenuse Distance/Enter for quit: ")) (cond (h_d (initget 7) (setq v_d (getdist (getvar "LASTPOINT") "\nEnter vertical Distance: ")) (initget 33) (getorient (getvar "LASTPOINT") "\nChoose quadrant with orientation of rubber-band line: ") (setq tmp (grread T 5 0)) (if (eq (car tmp) 5) (where_cursor (angle (getvar "LASTPOINT") (cadr tmp))) (where_cursor 0.0) ) (command "_none" (list ((eval dx) (car (getvar "LASTPOINT")) h_d) ((eval dy) (cadr (getvar "LASTPOINT")) v_d) (caddr (getvar "LASTPOINT")))) ) (T (command "")) ) ) ) (prin1) ) 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.