Converting between degrees and radians
The trigonometric operations and geometric manipulation are usually done in radians; it is always useful to be able to convert these into degrees and vice versa. This recipe will show you some tips on how to handle the conversion between these units.
How to do it...
- Open the console and create the folder
chapter03/recipe10. - Navigate to the directory.
- Create the
radians.gofile with the following content:
package main
import (
"fmt"
"math"
)
type Radian float64
func (rad Radian) ToDegrees() Degree {
return Degree(float64(rad) * (180.0 / math.Pi))
}
func (rad Radian) Float64() float64 {
return float64(rad)
}
type Degree float64
func (deg Degree) ToRadians() Radian {
return Radian(float64(deg) * (math.Pi / 180.0))
}
func (deg Degree) Float64() float64 {
return float64(deg)
}
func...