View Full Version : Polar (angel)?
J-LYLE
1st Apr 2005, 09:05 pm
Can someone please help me with this question? Ok lets say i have
(setq a1 (getdist "\n Enter Degree:"))
and lets say the user inputs 45 or 90 or 30 ect..., how can i set a point polar another point and the (user) input of the degree be the angel i use for that point? Am i explaining clearly if not let me know and ill post more info.
paulmcz
1st Apr 2005, 09:38 pm
Joe, it's:
(setq a1 (getangle "\n Enter Degree:"))
J-LYLE
1st Apr 2005, 09:42 pm
Thanks Paul for the responce ill check it out and let ya know if that fixed my prob. :D Maby i sould have known (getangle) that already..huh. :oops: .Sorry still new at lisp :unsure:
CarlB
1st Apr 2005, 09:45 pm
If you're going to use the input angle in a "polar" calculation, according to the lisp reference "getorient" is preferred to "getangle". Both of these will convert a user angular input to radians, which you'll need for the "polar" function.
(setq a1 (getorient "\n Enter Degree:"))
J-LYLE
1st Apr 2005, 09:48 pm
Thanks carl ill try both ways and let ya all know :D
David Bethel
2nd Apr 2005, 03:27 pm
I thought the diiferences between the two were:
Use getangle when you need a rotation amount (a relative angle). Use getorient to obtain an orientation (an absolute angle).
Where relative uses ANGDIR and ANGBASE current settings and absolute ignores ANGDIR and ANGBASE. -David
paulmcz
2nd Apr 2005, 11:30 pm
I thought the diiferences between the two were:
Use getangle when you need a rotation amount (a relative angle). Use getorient to obtain an orientation (an absolute angle).
Where relative uses ANGDIR and ANGBASE current settings and absolute ignores ANGDIR and ANGBASE. -David
David,
I tried a few tricks to test it but I am yet to see where is the actual difference between "getangle" and "getorient". Both ask for an angle, both convert comm. line entry to radians and even if I rotate UCS, results are the same?!?! Could you think of an example where these two would show different results?
Paul.
David Bethel
3rd Apr 2005, 01:45 pm
Paul,
Set ANGDIR to 1
Set ANGBASE to 180
Command: angdir
Enter new value for ANGDIR <0>:
Command: angbase
Enter new value for ANGBASE <0>:
Command: (getangle)
45
0.785398
Command: (getorient)
45
0.785398
Command: angdir
Enter new value for ANGDIR <0>: 1
Command: angbase
Enter new value for ANGBASE <0>: 180
Command: (getangle)
45
5.49779
Command: (getorient)
45
2.35619
Command: angdir
Enter new value for ANGDIR <1>: 0
Command: angbase
Enter new value for ANGBASE <180>: 0
Now exactly why someone would do that is the thing. I can confuse myself enough without someone changing a basic such as the way that angles are measured and oriented. But maybe there are some disiplines that use that system. -David
paulmcz
3rd Apr 2005, 03:34 pm
I see... One has to mess with angbase and/or angdir to see the difference.
Got it.
Thanks David.
Paul.
Adesu
4th Apr 2005, 06:43 am
Can someone please help me with this question? Ok lets say i have
(setq a1 (getdist "\n Enter Degree:"))
and lets say the user inputs 45 or 90 or 30 ect..., how can i set a point polar another point and the (user) input of the degree be the angel i use for that point? Am i explaining clearly if not let me know and ill post more info.
Or other solution
(defun rtd (a)
(* 180.0 (/ a pi)))
(setq ang (rtd (getangle "\nEnter Degree: ")))
CAB
6th Apr 2005, 12:53 pm
Yet another way to skin the cat.
(if (setq a (getangle "\nEnter angle"))
(setq a (cvunit a "radian" "degree"))
)
J-LYLE
6th Apr 2005, 10:26 pm
Ok i tried to use the infor provided and i dont know what i did wrong. Why will it not draw the arc? :unsure: did i change the arc to negitive# wrong? also why when i do 45 as input it show 90 degrees and 90 it shows 180 degrees? i can fix 45-90 to do what i want i just dont understand why it does that. Can anyone help beginer lisper :(
(defun c:elb( / d1 d2 d4 os p1 p2 bp1 bp2 cp ang1 ang2 name ss osmode)
(setq osmode (getvar "osmode"))
(setq d1 (getpoint "\n Pick point start of elbow:"))
(setq d2 (getdist "\n Enter Radius of elbow:"))
(setq d4 (getdist "\n Enter size Pipe:"))
(setq ang1(getangle"\ Enter #of Degree Elbow:"))
(setq ang2(* ang1 -1.0))
(setq os (/ d4 2.0))
(setq p1 (polar d1 0 os))
(setq p2 (polar d1 pi os))
(setq bp1(polar p1 (* pi 0.5)(* d4 2)))
(setq bp2(polar p2 (* pi 0.5)(* d4 2)))
(setq cp (polar bp2 0 (+ d2 os)))
(setq cp2 (polar cp ang2 1.0))
(setq name (strcat (rtos (fix d4)) "P" (rtos (fix d2))))
(if (not (tblsearch "block" name))
(progn
(setq ss (ssadd))
(setvar "osmode" 0)
(command "arc" "ce" cp bp1 "a" ang2 )
(ssadd (entlast) ss)
(command "arc" "ce" cp bp2 "a" ang2)
(ssadd (entlast) ss)
(command "pline" bp2 p2 p1 bp1 "")
(ssadd (entlast) ss)
(command "mirror" "l" "" cp cp2 "n")
(ssadd (entlast) ss)
(command "-block" name d1 ss "")
(setvar "osmode" osmode)
))
(command "-insert" name d1 "" "")
(princ)
)
CAB
6th Apr 2005, 11:51 pm
Here is a routine I wrote some time back as an exercize. It may give you some ideas on how to proceed.
;;*//*/*/*/*/*/*/*/*/*/*/*/*/**/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
;;*//*/*/*/*/*/*/*/*/*/*/*/*/**/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
;; elb.lsp Draw an elbow from user input
;;
;;*//*/*/*/*/*/*/*/*/*/*/*/*/**/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
;;*//*/*/*/*/*/*/*/*/*/*/*/*/**/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
(defun c:elb (/ p90 p45 p30 p60 p180 p270
rtd dtr fij ing draw choose om
calc_points pt1 pt2 pt3 pt4 pt5 pt6 pt7 pt8 ptc
get_direction midpoint direction dir alpha ductdia
)
;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;; Local Functions
;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;; RADIAN TO DEGREE function
(defun rtd (r) (/ (* r 180.0) pi))
;;define DEGREE to RADIAN function
(defun dtr (d) (/ (* d pi) 180.0))
;; find mid point between two points
(defun midpoint (p1 p2)(mapcar '(lambda (a b) (* 0.5 (+ a b))) p1 p2))
;; ================================================== =======
;; (vector-side <origin> <direction> <point> )
;;
;; Returns an integer code indicating position of <point>
;; in relation to the directed vector whose endpoints are
;; <origin> and <direction>.
;;
;; Result Meaning
;; ---------------------------------------------------------
;; -1 Point is to the right of vector.
;; 0 Point is on (colinear with) vector
;; 1 Point is to the left of vector.
(defun vector-side (v1 v2 p / r *fuzz*)
(setq *fuzz* 1e-10)
(setq r (- (* (-(car v2)(car v1))(-(cadr p)(cadr v1)))
(* (-(cadr v2)(cadr v1))(-(car p)(car v1)))
)
)
(cond ((equal r 0.0 *fuzz*) 0)
(t (fix (/ (abs r) r)))
)
) ; end defun
;; ================================================== =======
;; determine the elbow direction
(defun calc_direction (/ dircode ang midpt vpt dir)
(if (= (setq dircode (vector-side pt1 pt2 ptside)) 0)
(prompt "\nError, Point was on elbow base line.")
(progn ; got which side of the elbow base line
;; get direction for elbow
(cond
((= dircode 1) ;ccw
(setq dir '+)
)
((= dircode -1) ; cw
(setq dir '-)
)
) ; end cond stmt
(setq ang (apply dir (list (angle pt1 pt2) p90))
midpt (midPoint pt1 pt2)
vpt (polar midpt ang 20) ; vector point
)
(if (= (setq dircode (vector-side midpt vpt ptside)) 0)
(prompt "\nError, Point was in the middle.")
(progn ; got which side of duct
;; get direction for elbow
(cond
((= dircode 1) ;ccw
(setq direction "CCW")
(setq dir '+)
)
((= dircode -1) ; cw
(setq direction "CW")
(setq dir '-)
)
) ; end cond stmt
) ; end progn
) ;end if
) ; end progn
) ;end if
)
;;*//*/*/*/*/*/*/*/*/*/*/*/*/**/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
;;DATA INPUT PER USER
(defun Get_Location ()
(initget 7) ; NO 0, NULL, NIETHER NEGATIVE VALUE ALLOWED
(setq om (getvar "osmode"))
(setvar "osmode" 1) ; osmode to End
(if (setq pt1 (getpoint "\nSelect insertion point of elbow."))
(if (setq pt2
(getpoint pt1 "\nSelect the end point of the other duct side.")
)
(progn
(setvar "osmode" 0) ; osmode to None
(command "._Line" pt1 pt2 "")
(if (setq ptside
(getpoint "\nSelect point near the other end of the elbow.")
)
(progn
(entdel (entlast))
(if (> (distance pt1 ptside)(distance pt2 ptside))
(setq tmp pt1 ; keep pt1 as inside point of elbow
pt1 pt2
pt2 tmp)
)
(setq alfa (angle pt1 pt2) ; angle between sides
ductdia (distance pt1 pt2)) ; get the duct size
t ; return True
) ; end progn
(entdel (entlast))
) ; endif
);end progn
) ; endif
) ; endif
) ;_end ing func
;;*//*/*/*/*/*/*/*/*/*/*/*/*/**/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
;;Calculate Points
(defun calc_points (/ ang elbrad elbstr)
(setq elbrad (* ductdia 1.5) ;Duct Radious = 1.5 OF A
elbstr (* ductdia 0.25) ; THE ELLBOW'S STRAIGHT PART
ang (apply dir (list alfa p90))
pt3 (polar pt2 ang elbstr)
pt4 (polar pt1 ang elbstr)
ptc (polar pt4 (+ alfa pi) elbrad)
pt5 (polar ptc ang elbrad)
pt6 (polar pt5 ang ductdia)
pt7 (polar pt6 (+ alfa pi) elbstr)
pt8 (polar pt5 (+ alfa pi) elbstr)
) ; end setq
) ;_END CALC FOR CW
;;*//*/*/*/*/*/*/*/*/*/*/*/*/**/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
(defun draw ()
(command ".undo" "begin")
(setvar "osmode" 0) ; osmode to None
;; draw the straigth part of the elbow beside the duct
(command ".pline" pt1 pt2 pt3 pt4 "c")
;; idem for the elbows's end
(command ".pline" pt5 pt6 pt7 pt8 "c")
(cond
((= direction "CCW")
(command ".arc" "c" ptc pt3 pt6) ; THE ARC CCW
(command ".arc" "c" ptc pt4 pt5) ; THE ARC CCW
) ;_END cond CCW
((= direction "CW")
(command ".arc" "c" ptc pt5 pt4) ;THE ARC CW
(command ".arc" "c" ptc pt6 pt3) ;THE ARC CW
) ;_END cond CW
) ; end cond stmt
(command ".undo" "end")
) ;_END DRAW
;;*//*/*/*/*/*/*/*/*/*/*/*/*/**/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;;=============================================== =================
;;; Start of Routine
;;;=============================================== =================
;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;constant definition
(setq p90 (/ pi 2.0)) ; 90 DEGREE
(setq p45 (/ pi 4.0)) ;45 DEGREE
(setq p30 (/ pi 6.0)) ; 30 DEGREE
(setq p60 (/ pi 3.0)) ;60 DEGREE
(setq p180 pi) ;180 degre
(setq p270 (* pi 1.5)) ;270 degree
;;************************************************ ******
(setvar "angdir" 0)
;;(setvar "lunits" 4); the user unit
(setvar "lunits" 2) ; my units system
;;-------------------------------------------------------
(if (Get_Location) ; get points
(if (setq dir (calc_direction))
(progn
(calc_points)
(draw)
) ; end progn
(prompt "\nCalculate direction failed...")
) ; endif
(prompt "\nGet location failed...")
) ; endif
(princ)
(setvar "osmode" om)
) ;_end defun c:elb
(prompt "\nElbow DRAWER ... type ELB as a command")
(princ)
;;; //////////////
;;; End Of File
;;; \\\\\\\\\\\\\\
J-LYLE
7th Apr 2005, 02:33 pm
Can anyone help me figure out why it does not draw the arc in my rutine? :(
CAB
7th Apr 2005, 02:59 pm
start with this:
(defun c:elb (/ d1 d2 d4 os p1 p2 bp1 bp2 cp ang1 ang2 name ss osmode)
(setq osmode (getvar "osmode"))
(setq p1 (getpoint "\n Pick point start of elbow:"))
(setq rad (getdist p1 "\n Enter Radius of elbow:"))
(setq dia (getdist "\n Enter size Pipe:"))
(setq ang1 (getangle "\ Enter #of Degree Elbow:"))
(setvar "osmode" 0)
(setq ang1 (* 180.0 (/ ang1 pi))) ; r2d
(setq p2 (polar p1 0 dia)) ; outer rad of pipe
(setq cp (polar p1 pi rad))
;(setq name (strcat (rtos (fix d4)) "P" (rtos (fix d2))))
;(if (not (tblsearch "block" name))
(progn
(setq ss (ssadd))
(command "arc" "ce" cp p1 "a" ang1)
(ssadd (entlast) ss)
(command "arc" "ce" cp p2 "a" ang1)
)
;)
)
J-LYLE
8th Apr 2005, 08:39 pm
Thanks :D got it finnaly :)
Powered by vBulletin™ Version 4.1.2 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.