Trigonometric functions

119 views
Skip to first unread message

Grewsadon

unread,
Feb 19, 2012, 12:27:59 PM2/19/12
to sketch...@googlegroups.com
Hey all, I am kinda new to sketch.

For a technical drawing, I need the inverse sine and cosine functions. I didn't find anything about them in the online manual (http://www.frontiernet.net/~eugene.ressler/sketch.html). Is there a way to access them?

I am using sketch 0.3 under kubuntu 11.04.

Thanks,

Sebastian

Gene

unread,
Feb 20, 2012, 8:00:53 PM2/20/12
to Sketch Users
They're not there. If you can wait about a week I can add them. I'm
traveling with no access to the development environment.

If you are a C programmer, they're easy to add:
sketch.l: Look at token definitions for sin and cos and add asin and
acos.
sketch.y: Look at rules for SIN and COS. Add similar for ASIN and
ACOS. Also add %token directives at top.
expr.c: Add do_asin and do_acos to match sin( and cos(. Additionally
since asin and acos have finite domain, see sqrt( to see how to handle
bad argument values.

This ought to be it. You will need flex, bison, and GNU make as well
as gcc to complete the build.

Grewsadon

unread,
Feb 21, 2012, 2:56:41 AM2/21/12
to Sketch Users
Thank you Gene for your fast reply.

I figured out a how to work around it without changing anything by
using the atan2 function:

asin(x) = sgn(x) * atan2( x, sqrt( 1 - x^2 ) )
acos(x) = 90 - sgn(x) * atan2( x, sqrt( 1- x^2 ) )

where x is the scalar cosine of some angle. Source (in german):
http://de.wikipedia.org/wiki/Arkussinus_und_Arkuskosinus#Beziehung_zum_Arkustangens

So no need for quick action.

Gene

unread,
Feb 24, 2012, 9:34:51 PM2/24/12
to Sketch Users
Thanks. I just uploaded an update with asin() and acos() implemented
but not tested. The results are in degrees. The manual is updated,
also.

Please let me know if you see any problems.

Gene

On Feb 21, 2:56 am, Grewsadon <graus...@googlemail.com> wrote:
> Thank you Gene for your fast reply.
>
> I figured out a how to work around it without changing anything by
> using the atan2 function:
>
>   asin(x) = sgn(x) * atan2( x, sqrt( 1 - x^2 ) )
>   acos(x) = 90 - sgn(x) * atan2( x, sqrt( 1- x^2 ) )
>
> where x is the scalar cosine of some angle. Source (in german):http://de.wikipedia.org/wiki/Arkussinus_und_Arkuskosinus#Beziehung_zu...
Reply all
Reply to author
Forward
0 new messages