Dart: Trigonometry

Here are some examples for this topic.

import 'dart:math' as math;

void main() {
var beta = 40;
var radians = beta * (math.PI / 180);
print("beta = $beta°: $radians");

var sinBeta = double.parse(math.sin(radians).toStringAsPrecision(3));
var cosBeta = double.parse(math.cos(radians).toStringAsPrecision(3));
var tanBeta = double.parse(math.tan(radians).toStringAsPrecision(3));

print("sinus : $sinBeta");
print("cosinus : $cosBeta");
print("tangens : $tanBeta");
}

Its very simple, and there is something real cool about Dart that we see here:

toStringAsPrecision(3)

This automatically rounds the number up or down. So the number -1.117214930923896 gets -1.12. I think this really makes many things easier when you work with this kind of math things. Another nice thing that you can see here is the following print-method:

print("beta = $beta°");

No need to use tokens like ‘+’ or ‘.’. Just use ‘$’. By the way, the output looked like that:

beta = 40°: 0.6981317007977318
sinus : 0.643
cosinus : 0.766
tangens : 0.839

Yannick Signer