Used data types: AngleUnit

The AngleUnit type is used to set angular values. AngleUnit is declared as

type AngleUnit struct {
	Type  AngleUnitType
	Value float64
}

where Type is the type of angular value; Value is the angular value

The Type can take the following values:

  • Radian (0) - the Value field defines the angular value in radians.
  • PiRadian (1) - the Value field defines the angular value in radians multiplied by π.
  • Degree (2) - the Value field defines the angular value in degrees.
  • Gradian (3) - the Value field defines the angular value in grades (gradians).
  • Turn (4) - the Value field defines the angular value in turns (1 turn == 360°).

For a more visual and simple setting of variables of the AngleUnit type, the functions below can be used.

Function Equivalent definition
rui.Rad(n) rui.AngleUnit{ Type: rui.Radian, Value: n }
rui.PiRad(n) rui.AngleUnit{ Type: rui.PiRadian, Value: n }
rui.Deg(n) rui.AngleUnit{ Type: rui.Degree, Value: n }
rui.Grad(n) rui.AngleUnit{ Type: rui.Gradian, Value: n }

Variables of type AngleUnit have a textual representation consisting of a number (equal to the value of the Value field)followed by a suffix defining the type. The suffixes are listed in the following table:

Suffix Type
deg Degree
° Degree
rad Radian
π PiRadian
pi PiRadian
grad Gradian
turn Turn

Examples: “45deg”, “90°”, “3.14rad”, “2π”, “0.5pi”

The String function is used to convert AngleUnit to a string.To convert a string to AngleUnit is used the function:

func StringToAngleUnit(value string) (AngleUnit, bool)