0
votes

This is a Trig 101 question. Unfortunately, I don't remember my basic trig too well (too old :). I need to find a formula in Golang to compute the angle in degrees given the coefficient. As an example:

Tan(angle) = coefficient Angle = arctan (coefficient)

Examples: Angle = arctan(0.2) = 11.31 degrees (where coefficient = 0.2)

Angle = arctan(0.3) = 16.699 degrees (where coefficient = 0.3)

Angle = arctan(0.5) = 26.565 degrees (where coefficient = 0.5)

The URL below gives the calculator which is showing the correct values:

http://www.rapidtables.com/calc/math/Tan_Calculator.htm

Given these examples, how do I derive a formula written in Golang to compute the angle in degrees given the coefficient?

Thanks in advance for your time.

Bharat

1
The math package has functions for calculating trigonometric values: golang.org/pkg/math/#Atan - william.taylor.09

1 Answers

1
votes

Go Playground

package main

import (
    "fmt"
    "math"
)

func main() {
    fmt.Println("Tan: ", math.Tan(90))
    fmt.Println("Arctan: ", math.Atan(0.2))
    fmt.Println("Arctan: ", math.Atan(0.3))
    fmt.Println("Arctan: ", math.Atan(0.5))
}

List of func in math package