PDA

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.

&#40;if &#40;setq a &#40;getangle "\nEnter angle"&#41;&#41;
&#40;setq a &#40;cvunit a "radian" "degree"&#41;&#41;
&#41;

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 :(


&#40;defun c&#58;elb&#40; / d1 d2 d4 os p1 p2 bp1 bp2 cp ang1 ang2 name ss osmode&#41;

&#40;setq osmode &#40;getvar "osmode"&#41;&#41;

&#40;setq d1 &#40;getpoint "\n Pick point start of elbow&#58;"&#41;&#41;
&#40;setq d2 &#40;getdist "\n Enter Radius of elbow&#58;"&#41;&#41;
&#40;setq d4 &#40;getdist "\n Enter size Pipe&#58;"&#41;&#41;
&#40;setq ang1&#40;getangle"\ Enter #of Degree Elbow&#58;"&#41;&#41;
&#40;setq ang2&#40;* ang1 -1.0&#41;&#41;
&#40;setq os &#40;/ d4 2.0&#41;&#41;
&#40;setq p1 &#40;polar d1 0 os&#41;&#41;
&#40;setq p2 &#40;polar d1 pi os&#41;&#41;
&#40;setq bp1&#40;polar p1 &#40;* pi 0.5&#41;&#40;* d4 2&#41;&#41;&#41;
&#40;setq bp2&#40;polar p2 &#40;* pi 0.5&#41;&#40;* d4 2&#41;&#41;&#41;
&#40;setq cp &#40;polar bp2 0 &#40;+ d2 os&#41;&#41;&#41;
&#40;setq cp2 &#40;polar cp ang2 1.0&#41;&#41;

&#40;setq name &#40;strcat &#40;rtos &#40;fix d4&#41;&#41; "P" &#40;rtos &#40;fix d2&#41;&#41;&#41;&#41;

&#40;if &#40;not &#40;tblsearch "block" name&#41;&#41;
&#40;progn
&#40;setq ss &#40;ssadd&#41;&#41;

&#40;setvar "osmode" 0&#41;

&#40;command "arc" "ce" cp bp1 "a" ang2 &#41;
&#40;ssadd &#40;entlast&#41; ss&#41;

&#40;command "arc" "ce" cp bp2 "a" ang2&#41;
&#40;ssadd &#40;entlast&#41; ss&#41;

&#40;command "pline" bp2 p2 p1 bp1 ""&#41;
&#40;ssadd &#40;entlast&#41; ss&#41;

&#40;command "mirror" "l" "" cp cp2 "n"&#41;
&#40;ssadd &#40;entlast&#41; ss&#41;

&#40;command "-block" name d1 ss ""&#41;

&#40;setvar "osmode" osmode&#41;
&#41;&#41;

&#40;command "-insert" name d1 "" ""&#41;

&#40;princ&#41;
&#41;

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
;;
;;*//*/*/*/*/*/*/*/*/*/*/*/*/**/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
;;*//*/*/*/*/*/*/*/*/*/*/*/*/**/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
&#40;defun c&#58;elb &#40;/ 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
&#41;
;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;; Local Functions
;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-

;; RADIAN TO DEGREE function
&#40;defun rtd &#40;r&#41; &#40;/ &#40;* r 180.0&#41; pi&#41;&#41;
;;define DEGREE to RADIAN function
&#40;defun dtr &#40;d&#41; &#40;/ &#40;* d pi&#41; 180.0&#41;&#41;
;; find mid point between two points
&#40;defun midpoint &#40;p1 p2&#41;&#40;mapcar '&#40;lambda &#40;a b&#41; &#40;* 0.5 &#40;+ a b&#41;&#41;&#41; p1 p2&#41;&#41;


;; ================================================== =======
;; &#40;vector-side <origin> <direction> <point> &#41;
;;
;; 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 &#40;colinear with&#41; vector
;; 1 Point is to the left of vector.

&#40;defun vector-side &#40;v1 v2 p / r *fuzz*&#41;
&#40;setq *fuzz* 1e-10&#41;
&#40;setq r &#40;- &#40;* &#40;-&#40;car v2&#41;&#40;car v1&#41;&#41;&#40;-&#40;cadr p&#41;&#40;cadr v1&#41;&#41;&#41;
&#40;* &#40;-&#40;cadr v2&#41;&#40;cadr v1&#41;&#41;&#40;-&#40;car p&#41;&#40;car v1&#41;&#41;&#41;
&#41;
&#41;
&#40;cond &#40;&#40;equal r 0.0 *fuzz*&#41; 0&#41;
&#40;t &#40;fix &#40;/ &#40;abs r&#41; r&#41;&#41;&#41;
&#41;
&#41; ; end defun

;; ================================================== =======
;; determine the elbow direction
&#40;defun calc_direction &#40;/ dircode ang midpt vpt dir&#41;
&#40;if &#40;= &#40;setq dircode &#40;vector-side pt1 pt2 ptside&#41;&#41; 0&#41;
&#40;prompt "\nError, Point was on elbow base line."&#41;
&#40;progn ; got which side of the elbow base line
;; get direction for elbow
&#40;cond
&#40;&#40;= dircode 1&#41; ;ccw
&#40;setq dir '+&#41;
&#41;
&#40;&#40;= dircode -1&#41; ; cw
&#40;setq dir '-&#41;
&#41;
&#41; ; end cond stmt
&#40;setq ang &#40;apply dir &#40;list &#40;angle pt1 pt2&#41; p90&#41;&#41;
midpt &#40;midPoint pt1 pt2&#41;
vpt &#40;polar midpt ang 20&#41; ; vector point
&#41;
&#40;if &#40;= &#40;setq dircode &#40;vector-side midpt vpt ptside&#41;&#41; 0&#41;
&#40;prompt "\nError, Point was in the middle."&#41;
&#40;progn ; got which side of duct
;; get direction for elbow
&#40;cond
&#40;&#40;= dircode 1&#41; ;ccw
&#40;setq direction "CCW"&#41;
&#40;setq dir '+&#41;
&#41;
&#40;&#40;= dircode -1&#41; ; cw
&#40;setq direction "CW"&#41;
&#40;setq dir '-&#41;
&#41;
&#41; ; end cond stmt
&#41; ; end progn
&#41; ;end if
&#41; ; end progn
&#41; ;end if
&#41;

;;*//*/*/*/*/*/*/*/*/*/*/*/*/**/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
;;DATA INPUT PER USER
&#40;defun Get_Location &#40;&#41;
&#40;initget 7&#41; ; NO 0, NULL, NIETHER NEGATIVE VALUE ALLOWED
&#40;setq om &#40;getvar "osmode"&#41;&#41;
&#40;setvar "osmode" 1&#41; ; osmode to End
&#40;if &#40;setq pt1 &#40;getpoint "\nSelect insertion point of elbow."&#41;&#41;
&#40;if &#40;setq pt2
&#40;getpoint pt1 "\nSelect the end point of the other duct side."&#41;
&#41;
&#40;progn
&#40;setvar "osmode" 0&#41; ; osmode to None
&#40;command "._Line" pt1 pt2 ""&#41;
&#40;if &#40;setq ptside
&#40;getpoint "\nSelect point near the other end of the elbow."&#41;
&#41;
&#40;progn
&#40;entdel &#40;entlast&#41;&#41;
&#40;if &#40;> &#40;distance pt1 ptside&#41;&#40;distance pt2 ptside&#41;&#41;
&#40;setq tmp pt1 ; keep pt1 as inside point of elbow
pt1 pt2
pt2 tmp&#41;
&#41;
&#40;setq alfa &#40;angle pt1 pt2&#41; ; angle between sides
ductdia &#40;distance pt1 pt2&#41;&#41; ; get the duct size
t ; return True
&#41; ; end progn
&#40;entdel &#40;entlast&#41;&#41;
&#41; ; endif
&#41;;end progn
&#41; ; endif
&#41; ; endif
&#41; ;_end ing func

;;*//*/*/*/*/*/*/*/*/*/*/*/*/**/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
;;Calculate Points
&#40;defun calc_points &#40;/ ang elbrad elbstr&#41;
&#40;setq elbrad &#40;* ductdia 1.5&#41; ;Duct Radious = 1.5 OF A
elbstr &#40;* ductdia 0.25&#41; ; THE ELLBOW'S STRAIGHT PART
ang &#40;apply dir &#40;list alfa p90&#41;&#41;
pt3 &#40;polar pt2 ang elbstr&#41;
pt4 &#40;polar pt1 ang elbstr&#41;
ptc &#40;polar pt4 &#40;+ alfa pi&#41; elbrad&#41;
pt5 &#40;polar ptc ang elbrad&#41;
pt6 &#40;polar pt5 ang ductdia&#41;
pt7 &#40;polar pt6 &#40;+ alfa pi&#41; elbstr&#41;
pt8 &#40;polar pt5 &#40;+ alfa pi&#41; elbstr&#41;
&#41; ; end setq
&#41; ;_END CALC FOR CW

;;*//*/*/*/*/*/*/*/*/*/*/*/*/**/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
&#40;defun draw &#40;&#41;
&#40;command ".undo" "begin"&#41;
&#40;setvar "osmode" 0&#41; ; osmode to None
;; draw the straigth part of the elbow beside the duct
&#40;command ".pline" pt1 pt2 pt3 pt4 "c"&#41;
;; idem for the elbows's end
&#40;command ".pline" pt5 pt6 pt7 pt8 "c"&#41;
&#40;cond
&#40;&#40;= direction "CCW"&#41;
&#40;command ".arc" "c" ptc pt3 pt6&#41; ; THE ARC CCW
&#40;command ".arc" "c" ptc pt4 pt5&#41; ; THE ARC CCW
&#41; ;_END cond CCW
&#40;&#40;= direction "CW"&#41;
&#40;command ".arc" "c" ptc pt5 pt4&#41; ;THE ARC CW
&#40;command ".arc" "c" ptc pt6 pt3&#41; ;THE ARC CW
&#41; ;_END cond CW
&#41; ; end cond stmt
&#40;command ".undo" "end"&#41;
&#41; ;_END DRAW

;;*//*/*/*/*/*/*/*/*/*/*/*/*/**/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*


;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;;=============================================== =================
;;; Start of Routine
;;;=============================================== =================
;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;constant definition
&#40;setq p90 &#40;/ pi 2.0&#41;&#41; ; 90 DEGREE
&#40;setq p45 &#40;/ pi 4.0&#41;&#41; ;45 DEGREE
&#40;setq p30 &#40;/ pi 6.0&#41;&#41; ; 30 DEGREE
&#40;setq p60 &#40;/ pi 3.0&#41;&#41; ;60 DEGREE
&#40;setq p180 pi&#41; ;180 degre
&#40;setq p270 &#40;* pi 1.5&#41;&#41; ;270 degree
;;************************************************ ******
&#40;setvar "angdir" 0&#41;
;;&#40;setvar "lunits" 4&#41;; the user unit
&#40;setvar "lunits" 2&#41; ; my units system
;;-------------------------------------------------------

&#40;if &#40;Get_Location&#41; ; get points
&#40;if &#40;setq dir &#40;calc_direction&#41;&#41;
&#40;progn
&#40;calc_points&#41;
&#40;draw&#41;
&#41; ; end progn
&#40;prompt "\nCalculate direction failed..."&#41;
&#41; ; endif
&#40;prompt "\nGet location failed..."&#41;
&#41; ; endif
&#40;princ&#41;
&#40;setvar "osmode" om&#41;

&#41; ;_end defun c&#58;elb

&#40;prompt "\nElbow DRAWER ... type ELB as a command"&#41;
&#40;princ&#41;


;;; //////////////
;;; 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:

&#40;defun c&#58;elb &#40;/ d1 d2 d4 os p1 p2 bp1 bp2 cp ang1 ang2 name ss osmode&#41;

&#40;setq osmode &#40;getvar "osmode"&#41;&#41;

&#40;setq p1 &#40;getpoint "\n Pick point start of elbow&#58;"&#41;&#41;

&#40;setq rad &#40;getdist p1 "\n Enter Radius of elbow&#58;"&#41;&#41;
&#40;setq dia &#40;getdist "\n Enter size Pipe&#58;"&#41;&#41;
&#40;setq ang1 &#40;getangle "\ Enter #of Degree Elbow&#58;"&#41;&#41;

&#40;setvar "osmode" 0&#41;

&#40;setq ang1 &#40;* 180.0 &#40;/ ang1 pi&#41;&#41;&#41; ; r2d
&#40;setq p2 &#40;polar p1 0 dia&#41;&#41; ; outer rad of pipe
&#40;setq cp &#40;polar p1 pi rad&#41;&#41;

;&#40;setq name &#40;strcat &#40;rtos &#40;fix d4&#41;&#41; "P" &#40;rtos &#40;fix d2&#41;&#41;&#41;&#41;

;&#40;if &#40;not &#40;tblsearch "block" name&#41;&#41;
&#40;progn
&#40;setq ss &#40;ssadd&#41;&#41;


&#40;command "arc" "ce" cp p1 "a" ang1&#41;
&#40;ssadd &#40;entlast&#41; ss&#41;
&#40;command "arc" "ce" cp p2 "a" ang1&#41;
&#41;
;&#41;
&#41;

J-LYLE
8th Apr 2005, 08:39 pm
Thanks :D got it finnaly :)