math-expressions icon indicating copy to clipboard operation
math-expressions copied to clipboard

Using degrees for sin(),cos() and tan()

Open AmirHosein-Gharaati opened this issue 4 years ago • 5 comments

Is it possible to use degrees for sin,cos and tan ?

sin(90) = 1

I figured out we can just use radian...

AmirHosein-Gharaati avatar Aug 30 '20 21:08 AmirHosein-Gharaati

Hi

Correct, as you figured out, it's currently only possible to use radians on all trigonometric functions. I'll update the documentation for the next version to state this explicitly.

Hence you'd have to do the conversion from degree to radians in your application.

While input in degrees could be supported directly in this library (either by introducing a specific degree notation that the parser understands, or a second set of function definitions), I'm not sure there is much value since the conversions are pretty trivial.

fkleon avatar Aug 31 '20 04:08 fkleon

How can I change the parser, to use degrees entirely, instead of radian?

AmirHosein-Gharaati avatar Sep 01 '20 09:09 AmirHosein-Gharaati

Three options:

  • Convert the input values to from degrees radians in the parser when constructing trigonometric expression - somewhere around parser.dart#92
  • Convert the input values from degrees to radians in the expression constructors - for example functions.dart#L562
  • Change the trigonometric functions to operate on degrees - however the Dart-internal math functions operate on radians so this would still need conversion

I think the first option is most flexible and could be toggled via a configuration option for the parser.

fkleon avatar Sep 03 '20 20:09 fkleon

I think the first option is most flexible and could be toggled via a configuration option for the parser.

Went through the codebase. Can you explain in detail how can I achieve this?

danger-ahead avatar Jan 13 '22 07:01 danger-ahead