Home Newsletter Utter Rubbish Coding Tips AutoCAD Tips Contact Downloads WAUN
 I have a problem with some basic trigonometry, and maybe I'm looking at this too hard. How does one work out the angle of a triangle knowing the lengths of it's sides? And some of the answers : I just wanted to say that arc sine does not equal to 1/sin . AutoLISP has arc tan function that returns the angle in radians knowing the tangent of the angle. The following equations can be useful : sin a * sin a + cos a * cos b = 1 tan a = sin a / cos a this means you can calculate tan of the angle if you have the sin or the cos. The arc tan function in AutoLISP is (atan ). It takes one or two arguments. You can take a look at this function in the LISP help . Sherko ========================================================= Autolisp does have an inverse tan function: atan. And that's all you need really. ;asin ;-1<=y<=1 ;returns inverse sin in radians (defun asin (y) (atan y (sqrt (- 1 (* y y)))) ) ;acos ;-1<=y<=1 ;returns inverse cos in radians (defun acos (y) (atan (sqrt (- 1 (* y y))) y) ) btw, 1/sin(x) would be sec(x) not the inverse sine. Arc sin is indeed the inverse of sine but the notation "sin to the power -1" is just shorthand for inverse sine, it does not mean literally raised to the power of minus 1; i.e. 1/sin(x). jeff russon ====================================================== Trig functions in AutoLISP. Jasmina ;CODING STARTS HERE ;Trig functions in AutoLISP ;adapted from CADalyst tip 442, by John Howard ; ;CO-TANGENT (defun cot (x) (cond ((equal (sin x) 0.0 1.0e-16) (if (minusp x) -1.0e200 1.0e200 ) ) (T (/ (cos x) (sin x)) ) ) ) ; ;CO-SECANT (defun csc (x) (cond ((equal (sin x) 0.0 1.0e-16) (if (minusp x) -1.0e200 1.0e200 ) ) (T (/ 1.0 (sin x)) ) ) ) ; ;SECANT (defun sec (x) (cond ((equal (sin x) 0.0 1.0e-16) (if (minusp x) -1.0e200 1.0e200 ) ) (T (/ 1.0 (cos x)) ) ) ) ; ;TANGENT (defun tan (x) (cond ((equal (cos x) 0.0 1.0e-16) (if (minusp x) -1.0e200 1.0e200 ) ) (T (/ (sin x) (cos x)) ) ) ) ; ;ARC COSECANT (defun acsc (x) (cond ((equal x 1.0 1.0e-16) (* pi 0.5) ) ((equal x -1.0 1.0e-16) (* pi -0.5) ) ((> (abs x) 1.0) (atan (/ (/ 1.0 x) (sqrt (- 1.0 (/ 1.0 (* x x)))))) ) (T (prompt "\n*ERROR* (abs x) < 1.0 from ACSC function\n") ) ) ) ; ;ARC COSINE (defun acos (x) (cond ((equal x 1.0 1.0e-16) 0.0 ) ((equal x -1.0 1.0e-16) pi ) ((< (abs x) 1.0) (- (* pi 0.5) (atan (/ x (sqrt (- 1.0 (* x x)))))) ) (T (prompt "\n*ERROR* (abs x) > 1.0 from ACOS function\n") ) ) ) ; ;ARC SECANT (defun asec (x) (cond ((equal x 1.0 1.0e-16) 0.0 ) ((equal x -1.0 1.0e-16) pi ) ((> (abs x) 1.0) (- (* pi 0.5) (atan (/ (/ 1.0 x) (sqrt (- 1.0 (/ 1.0 (* x x))))))) ) (T (prompt "\n*ERROR* (abs x) < 1.0 from ASEC function\n") ) ) ) ; ;ARC SINE (defun asin (x) (cond ((equal x 1.0 1.0e-16) (* pi 0.5) ) ((equal x -1.0 1.0e-16) (* pi -0.5) ) ((< (abs x) 1.0) (atan (/ x (sqrt (- 1.0 (* x x))))) ) (T (prompt "\n*ERROR* (abs x) > 1.0 from ASIN function\n") ) ) ) ; (princ "\nCOT, CSC, SEC, TAN, ACSC, ACOS, ASEC, ASIN \n") (prin1) ;CODING ENDS HERE ========================================================== Try this simple one : (defun cangle (a b c) (setq max_val (max a b c)) (cond ((= max_val a)(setq a b b c)) ((= max_val b)(setq b c)) ) (setq A_ang (/ (* 180 (atan a b)) pi) B_ang (/ (* 180 (atan b a)) pi) C_ang (- 180.0 A_ang B_ang) ) (print (strcat "Angle A is " (rtos A_ang) " degrees")) (print (strcat "Angle B is " (rtos B_ang) " degrees")) (print (strcat "Angle C is " (rtos C_ang) " degrees")) (princ) ) Lennart Ekelund ================================================================= And from the wonder Llama himself : *ahem* 'CODING STARTS HERE Function ArcSin(x As Double) As Double 'Inverse Sin If x = 1 Then ArcSin = PI() / 2 ElseIf x = -1 Then ArcSin = -PI() / 2 Else ArcSin = Atn(x / Sqr(-x * x + 1)) End If End Function Function ArcCos(x As Double) As Double ' Inverse Cosine If x = 1 Then ArcCos = 0 ElseIf x = -1 Then ArcCos = -PI() Else ArcCos = Atn(x / Sqr(-x * x + 1)) + PI() / 2 End If End Function Function Arccotan(x As Double) As Double Arccotan = Atn(x) + PI() / 2 End Function Function PI() As Double PI = Atn(1) * 4 End Function 'CODING ENDS HERE
 Copyright © 1999-Perpetuity by AfraLisp All rights reserved. Information in this document is subject to change without notice. Site created and maintained by Kenny Ramage