Trigonometric functions Sin-1

Trigonometric functions Sin-1

Henrik_Lo
Collaborator Collaborator
1,855 Views
10 Replies
Message 1 of 11

Trigonometric functions Sin-1

Henrik_Lo
Collaborator
Collaborator

Hi

Is the a function to do this calculation by LISP I can’t find the Sin -1 function
I need to find the angle by use of formula a/c*sin-1
My example : 1.4/31.5907 = 0.0443

0.0443*sin-1 = 2.54

a and c is my to changing variables controlling the angle.

 

 

Regards

Henrik

0 Likes
1,856 Views
10 Replies
Replies (10)
Message 2 of 11

_gile
Consultant
Consultant

Hi,

 

There's no built-in function, but you can build your own.

 

;; gc:asin
;; Returns the arc sine of the number
;;
;; Argument
;; n : the angle sine
(defun gc:asin (n)
  (cond
    ((equal n 1. 1e-9) (/ pi 2.))
    ((equal n -1. 1e-9) (/ pi -2.))
    ((< -1. n 1.)
     (atan n (sqrt (- 1 (expt n 2))))
    )
  )
)

;; gc:acos
;; Returns the arc cosine of the number
;;
;; Argument
;; n : the angle cosine
(defun gc:acos (n)
  (cond
    ((equal n 1. 1e-9) 0.)
    ((equal n -1. 1e-9) pi)
    ((< -1. n 1.)
     (atan (sqrt (- 1. (expt n 2))) n)
    )
  )
)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 11

hak_vz
Advisor
Advisor
(defun asin (x)
      (cond 
        ((and(> x -1.0)(< x 1.0)) (atan (/ x (sqrt (- 1.0 (* x x))))))
        ((= x -1.0) (* -1.0 (/ pi 2)))
        ((= x  1) (/ pi 2))
      )
    )
(defun acos (x)(cond ((and(>= x -1.0)(<= x 1.0)) (-(* pi 0.5) (asin x)))))

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 4 of 11

Henrik_Lo
Collaborator
Collaborator

HI tangs for replying

Iam not familiar by using functions like that gc:asin

(Defun c:arcc ()
   (setq nnnn (GetReal))
   (setq angg (gc:asin nnnn))
)

 

Regards

Henrik

0 Likes
Message 5 of 11

Kent1Cooper
Consultant
Consultant

There are routines for all possible trigonometric functions that AutoLisp doesn't already include, in AutoLisp functions, in various places, one being >here<.

Kent Cooper, AIA
0 Likes
Message 6 of 11

Henrik_Lo
Collaborator
Collaborator

Hi Kent
I will give it a tray, to see if I can use these functions
Regards
Henrik

0 Likes
Message 7 of 11

Henrik_Lo
Collaborator
Collaborator

Hi Kent

 

Can you show me ha I could build up my base lisp program
And the using some of the add in functions it need to return 2.54 degree, iam not familiarized
Using prebuild functions

 

I need to find the angle by use of formula a/c*sin-1
My example : 1.4/31.5907 = 0.0443
0.0443*sin-1 = 2.54

How do I build it into fx. this function

(Defun c:trrr ()
(Setq a (getreal)) ; 1.3
(Setq c (getreal)) ; 31.5907
(setq ac (/ a c)) ; 0.443
) ;The output need to be in degree , 2.54Degree

 

Regards

Henrik

0 Likes
Message 8 of 11

hak_vz
Advisor
Advisor

Here are functions to convert from radians to degrees and opposite. Functions sin cos....asin and so on require angle to be entered as radians and provide result in radians. So if you enter angle in degrees conver them to radians before ading ro trigonometric function, and final result convert back to degrees.

 

(defun rad_to_deg (rad)(* 180.0 (/ rad pi)))
(defun deg_to_rad (deg)(* pi (/ deg 180.0)))

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 9 of 11

Henrik_Lo
Collaborator
Collaborator

HI hak_vz, thangs

regards

Henrik

0 Likes
Message 10 of 11

_gile
Consultant
Consultant

Hi,

 

Here's an example of what you describe with some comments:

(defun c:trrr (/ a c ac rad deg)	; local variables
  (setq a (getreal))			; 1.4
  (setq c (getreal))			; 31.5907
  (setq ac (/ a c))			; 0.0443  
(terpri) ; print a newline (princ (rtos ac 2 4)) ; print the sine with 4 digits (setq rad (gc:asin ac)) ; angle in radians (setq deg (* rad (/ pi 180.))) ; angle in degrees
(terpri) ; print a newline (princ (angtos rad 0 2)) ; print the angle in degrees with 2 digits (princ) ; exit silently )


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 11 of 11

Henrik_Lo
Collaborator
Collaborator

HI gille, thangs

 

This is fantastic, now I know how to use intergraded function, cut out I heavy paper for me, thangs

Regards

Henrik

0 Likes