github.com/blend/go-sdk@v1.20220411.3/mathutil/radians.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package mathutil
     9  
    10  import "math"
    11  
    12  // DegreesToRadians returns degrees as radians.
    13  func DegreesToRadians(degrees float64) float64 {
    14  	return degrees * _d2r
    15  }
    16  
    17  // RadiansToDegrees translates a radian value to a degree value.
    18  func RadiansToDegrees(value float64) float64 {
    19  	return math.Mod(value, _2pi) * _r2d
    20  }
    21  
    22  // PercentToRadians converts a normalized value (0,1) to radians.
    23  func PercentToRadians(pct float64) float64 {
    24  	return DegreesToRadians(360.0 * pct)
    25  }
    26  
    27  // RadianAdd adds a delta to a base in radians.
    28  func RadianAdd(base, delta float64) float64 {
    29  	value := base + delta
    30  	if value > _2pi {
    31  		return math.Mod(value, _2pi)
    32  	} else if value < 0 {
    33  		return math.Mod(_2pi+value, _2pi)
    34  	}
    35  	return value
    36  }
    37  
    38  // DegreesAdd adds a delta to a base in radians.
    39  func DegreesAdd(baseDegrees, deltaDegrees float64) float64 {
    40  	value := baseDegrees + deltaDegrees
    41  	if value > _2pi {
    42  		return math.Mod(value, 360.0)
    43  	} else if value < 0 {
    44  		return math.Mod(360.0+value, 360.0)
    45  	}
    46  	return value
    47  }
    48  
    49  // DegreesToCompass returns the degree value in compass / clock orientation.
    50  func DegreesToCompass(deg float64) float64 {
    51  	return DegreesAdd(deg, -90.0)
    52  }