dart:math library
Mathematical constants and functions, plus a random number generator.
To use this library in your code:
import 'dart:math';Random
Random is a generator ofbool,int ordouble values.
var intValue = Random().nextInt(10); // Value is >= 0 and < 10.var doubleValue = Random().nextDouble(); // Value is >= 0.0 and < 1.0.var boolValue = Random().nextBool(); // true or false, with equal chance.Point
Point is a utility class for representing two-dimensional positions.
var leftTop = const Point(0, 0);var rightBottom = const Point(200, 400);Rectangle
Rectangle is a class for representing two-dimensional axis-alignedrectangles whose properties are immutable.
Create a rectangle spanned by the points.
var leftTop = const Point(20, 50);var rightBottom = const Point(300, 600);var rectangle = Rectangle.fromPoints(leftTop, rightBottom);print(rectangle.left); // 20print(rectangle.top); // 50print(rectangle.right); // 300print(rectangle.bottom); // 600Create a rectangle spanned by(left, top) and(left+width, top+height).
var rectangle = const Rectangle(20, 50, 300, 600);print(rectangle.left); // 20print(rectangle.top); // 50print(rectangle.right); // 320print(rectangle.bottom); // 650MutableRectangle
MutableRectangle is a class for representing two-dimensional axis-alignedrectangles with mutable properties.
Create a mutable rectangle spanned by(left, top) and(left+width, top+height).
var rectangle = MutableRectangle(20, 50, 300, 600);print(rectangle); // Rectangle (20, 50) 300 x 600print(rectangle.left); // 20print(rectangle.top); // 50print(rectangle.right); // 320print(rectangle.bottom); // 650// Change rectangle width and height.rectangle.width = 200;rectangle.height = 100;print(rectangle); // Rectangle (20, 50) 200 x 100print(rectangle.left); // 20print(rectangle.top); // 50print(rectangle.right); // 220print(rectangle.bottom); // 150Classes
- MutableRectangle<
T extendsnum> - A class for representing two-dimensional axis-aligned rectangles withmutable properties.
- Point<
T extendsnum> - A utility class for representing two-dimensional positions.
- Random
- A generator of random bool, int, or double values.
- Rectangle<
T extendsnum> - A class for representing two-dimensional rectangles whose properties areimmutable.
Constants
- e→ constdouble
- Base of the natural logarithms.
- ln10→ constdouble
- Natural logarithm of 10.
- ln2→ constdouble
- Natural logarithm of 2.
- log10e→ constdouble
- Base-10 logarithm ofe.
- log2e→ constdouble
- Base-2 logarithm ofe.
- pi→ constdouble
- The PI constant.
- sqrt1_2→ constdouble
- Square root of 1/2.
- sqrt2→ constdouble
- Square root of 2.
Functions
- acos(
numx)→double - Converts
xto adouble and returns its arc cosine in radians. - asin(
numx)→double - Converts
xto adouble and returns its arc sine in radians. - atan(
numx)→double - Converts
xto adouble and returns its arc tangent in radians. - atan2(
numa,numb)→double - A variant ofatan.
- cos(
numradians)→double - Converts
radiansto adouble and returns the cosine of the value. - exp(
numx)→double - Converts
xto adouble and returns the natural exponent,e,to the powerx. - log(
numx)→double - Converts
xto adouble and returns the natural logarithm of the value. - max<
T extendsnum> (Ta,Tb)→ T - Returns the larger of two numbers.
- min<
T extendsnum> (Ta,Tb)→ T - Returns the lesser of two numbers.
- pow(
numx,numexponent)→num - Returns
xto the power ofexponent. - sin(
numradians)→double - Converts
radiansto adouble and returns the sine of the value. - sqrt(
numx)→double - Converts
xto adouble and returns the positive square root of thevalue. - tan(
numradians)→double - Converts
radiansto adouble and returns the tangent of the value.