Core\Math::asin
Returns the angle whose sine is the number you give it. This is the arc sine, and it undoes Core\Math::sin.
The number must be from -1.0 to 1.0, because a sine is always in that range. The angle is in radians, from -PI / 2 to PI / 2. Core\Math::toDegrees converts it to degrees. A number outside the range gives NaN (a value that means "not a number"), and Core\Math::isNan tests for it.
Good to know: a sine you calculated can end up a tiny bit past 1.0 because of rounding, and then the result is NaN. Use Core\Math::clamp to keep the number in range first.
The examples below show the angles for a few sines, then what happens outside the range, then how steep a ramp is from its length and its height.
Parameters
$nfloatA sine: a number from-1.0to1.0.
Return value
Returns float. An angle from -PI / 2 to PI / 2, in radians. A $n outside -1.0 to 1.0 gives NaN.
Examples
The angle for a sine
<?nvs// Shows the angles `Core\Math::asin` returns for a few sines, in radians and in degrees.
// A sine of 0.5 belongs to an angle of 30 degrees. This prints 0.5235987755983.echo Core\Math::asin(0.5), "\n";
// `Core\Math::toDegrees` converts the angle to degrees. This prints 30.echo Core\Math::round(Core\Math::toDegrees(Core\Math::asin(0.5))), "\n";
// A negative sine gives a negative angle. This prints -90.echo Core\Math::toDegrees(Core\Math::asin(-1.0)), "\n";0.523598775598330-90A sine outside the range
<?nvs// Shows what `Core\Math::asin` returns for a number that is not a sine,// and how to keep a calculated sine in range.
// No angle has a sine of 2.0, so the result is `NaN`. This prints NAN.echo Core\Math::asin(2.0), "\n";
// `Core\Math::isNan` tests for that result. This prints "not an angle".echo Core\Math::isNan(Core\Math::asin(2.0)) ? 'not an angle' : 'an angle', "\n";
// A calculation can end a tiny bit below -1.0 because of rounding.float $sine = -1.0000000000000002;
// `Core\Math::clamp` moves it back to -1.0 first. This prints -1.5707963267949.echo Core\Math::asin(Core\Math::clamp($sine, -1.0, 1.0)), "\n";NANnot an angle-1.5707963267949How steep a ramp is
<?nvs// Shows how a building planner checks whether a wheelchair ramp is too steep,// from the length of the ramp and the height it climbs.
class Ramp{ // Returns the angle of the ramp, in degrees, with one decimal place. public static function angle(float $length, float $height): float { // The height divided by the length is the sine of the ramp's angle. float $radians = Core\Math::asin($height / $length); return Core\Math::round(Core\Math::toDegrees($radians), { precision: 1 }); }}
// A ramp 6 metres long climbs half a metre. This prints 4.8.echo Ramp::angle(6.0, 0.5), "\n";
// A ramp half as long climbs the same height. This prints 9.6.echo Ramp::angle(3.0, 0.5), "\n";
// Many building rules allow at most 4.8 degrees. This prints "too steep".echo Ramp::angle(3.0, 0.5) > 4.8 ? 'too steep' : 'allowed', "\n";4.89.6too steep