PDA

View Full Version : Inverse trig functions (finding angles)


rken.laws
2007-10-25, 05:19 PM
I need to find the angle of a line not in the current construction plane. I can do it with a calculator by using the arcsine of the opposite divided by the hypotenuse. arcsine, asin or sin-1 are not functions in lisp. I'm sure there is a formula to convert it but I am not a trig expert. Is there any way to find an angle if I know all sides and one angle is 90??

CAB2k
2007-10-25, 06:37 PM
trigonometric functions
http://tinyurl.com/2uwfl5

'gile'
2007-10-25, 06:38 PM
Hi,

Here're the ones I use.

(defun ASIN (num)
(cond
((equal num 1 1e-9) (/ pi 2))
((equal num -1 1e-9) (/ pi -2))
((< -1 num 1)
(atan num (sqrt (- 1 (expt num 2))))
)
)
)

(defun ACOS (num)
(cond
((equal num 1 1e-9) 0.0)
((equal num -1 1e-9) pi)
((< -1 num 1)
(atan (sqrt (- 1 (expt num 2))) num)
)
)
)

and to get a 3d angle by 3 points (where sum is the angle summit) :

(defun angle_3pts (sum p1 p2)
((lambda (d1 d2 d3)
(if (and (< 0 d1) (< 0 d2))
(acos (/ (+ (* d1 d1) (* d2 d2) (- (* d3 d3)))
(* 2 d1 d2)
)
)
)
)
(distance sum p1)
(distance sum p2)
(distance p1 p2)
)
)

rken.laws
2007-10-25, 09:42 PM
Thanks for the help. I didn't realize "atan" was a lisp function. I saw it in gile's code and used it in mine just fine.