跳转至主要内容

taichi.math#

Taichi math module.

The math module supports glsl-style vectors, matrices and functions.

taichi.math.acos(x)#

Trigonometric inverse cosine, element-wise.

The inverse of cos so that, if y = cos(x), then x = acos(y).

For input x not in the domain [-1, 1], this function returns nan if it’s called in taichi scope, or raises exception if it’s called in python scope.

Parameters:

x (Union[primitive_types, Matrix]) – A scalar or a matrix with elements in [-1, 1].

Returns:

The inverse cosine of each element in x, in radians and in the closed interval [0, pi]. This is a scalar if x is a scalar.

Example:

>>> from math import pi
>>> ti.acos(ti.Matrix([-1.0, 0.0, 1.0])) * 180 / pi
[180., 90., 0.]
taichi.math.asin(x)#

Trigonometric inverse sine, element-wise.

The inverse of sin so that, if y = sin(x), then x = asin(y).

For input x not in the domain [-1, 1], this function returns nan if it’s called in taichi scope, or raises exception if it’s called in python scope.

Parameters:

x (Union[primitive_types, Matrix]) – A scalar or a matrix with elements in [-1, 1].

Returns:

The inverse sine of each element in x, in radians and in the closed interval [-pi/2, pi/2].

Example:

>>> from math import pi
>>> ti.asin(ti.Matrix([-1.0, 0.0, 1.0])) * 180 / pi
[-90., 0., 90.]
taichi.math.atan2(x1, x2)#

Element-wise arc tangent of x1/x2.

Parameters:
Returns:

Angles in radians, in the range [-pi, pi]. This is a scalar if both x1 and x2 are scalars.

Example:

>>> from math import pi
>>> @ti.kernel
>>> def test():
>>>     x = ti.Matrix([-1.0, 1.0, -1.0, 1.0])
>>>     y = ti.Matrix([-1.0, -1.0, 1.0, 1.0])
>>>     z = ti.atan2(y, x) * 180 / pi
>>>     print(z)
>>>
>>> test()
[-135.0, -45.0, 135.0, 45.0]
taichi.math.cconj(z)#

Returns the complex conjugate of a 2d vector.

If z=(x, y) then the conjugate of z is (x, -y).

Parameters:

z (vec2) – The input.

Returns:

The complex conjugate of z.

Return type:

vec2

taichi.math.cdiv(z1, z2)#

Performs complex division between two 2d vectors.

This is equivalent to the division in the complex number field when z1 and z2 are treated as complex numbers.

Parameters:
  • z1 (vec2) – The first input.

  • z2 (vec2) – The second input.

Example:

>>> @ti.kernel
>>> def test():
>>>     z1 = ti.math.vec2(1, 1)
>>>     z2 = ti.math.vec2(0, 1)
>>>     ti.math.cdiv(z1, z2)  # [1, -1]
Returns:

the complex division of z1 / z2.

Return type:

vec2

taichi.math.ceil(x, dtype=None)#

Return the ceiling of the input, element-wise.

The ceil of the scalar x is the smallest integer k, such that k >= x.

Parameters:
  • x (Union[primitive_types, Matrix]) – Input scalar or matrix.

  • dtype – (primitive_types): the returned type, default to None. If set to None the retuned value will have the same type with x.

Returns:

The ceiling of each element in x, with return value type dtype.

Example:

>>> @ti.kernel
>>> def test():
>>>     x = ti.Matrix([3.14, -1.5])
>>>     y = ti.ceil(x)
>>>     print(y)  # [4.0, -1.0]
taichi.math.cexp(z)#

Returns the complex exponential \(e^z\).

z is a 2d vector treated as a complex number.

Parameters:
  • z (vec2) – The base.

  • a (float) – The exponent.

Example:

>>> @ti.kernel
>>> def test():
>>>     z = ti.math.vec2(1, 1)
>>>     w = ti.math.cexp(z)  # [1.468694, 2.287355]
Returns:

The power \(z^a\)

Return type:

vec2

taichi.math.cinv(z)#

Computes the reciprocal of a complex z.

Parameters:

z (vec2) – The input.

Example:

>>> @ti.kernel
>>> def test():
>>>     z = ti.math.vec2(1, 1)
>>>     w = ti.math.cinv(z)  # [0.5, -0.5]
Returns:

The reciprocal of z.

Return type:

vec2

taichi.math.clamp(x, xmin, xmax)#

Constrain a value to lie between two further values, element-wise. The returned value is computed as min(max(x, xmin), xmax).

The arguments can be scalars or Matrix, as long as they can be broadcasted to a common shape.

Parameters:
Returns:

The value of x constrained to the range xmin to xmax.

Example:

>>> v = ti.Vector([0, 0.5, 1.0, 1.5])
>>> ti.math.clamp(v, 0.5, 1.0)
[0.500000, 0.500000, 1.000000, 1.000000]
>>> x = ti.Matrix([[0, 1], [-2, 2]], ti.f32)
>>> y = ti.Matrix([[1, 2], [1, 2]], ti.f32)
>>> ti.math.clamp(x, 0.5, y)
[[0.500000, 1.000000], [0.500000, 2.000000]]
taichi.math.clog(z)#

Returns the complex logarithm of z, so that if \(e^w = z\), then \(log(z) = w\).

z is a 2d vector treated as a complex number. The argument of \(w\) lies in the range (-pi, pi].

Parameters:

z (vec2) – The input.

Example:

>>> @ti.kernel
>>> def test():
>>>     z = ti.math.vec2(1, 1)
>>>     w = ti.math.clog(z)  # [0.346574, 0.785398]
Returns:

The logarithm of z.

Return type:

vec2

taichi.math.cmul(z1, z2)#

Performs complex multiplication between two 2d vectors.

This is equivalent to the multiplication in the complex number field when z1 and z2 are treated as complex numbers.

Parameters:
  • z1 (vec2) – The first input.

  • z2 (vec2) – The second input.

Example:

>>> @ti.kernel
>>> def test():
>>>     z1 = ti.math.vec2(1, 1)
>>>     z2 = ti.math.vec2(0, 1)
>>>     ti.math.cmul(z1, z2)  # [-1, 1]
Returns:

the complex multiplication z1 * z2.

Return type:

vec2

taichi.math.cos(x)#

Trigonometric cosine, element-wise.

Parameters:

x (Union[primitive_types, Matrix]) – Angle, in radians.

Returns:

The cosine of each element of x.

Example:

>>> from math import pi
>>> x = ti.Matrix([-pi, 0, pi/2.])
>>> ti.cos(x)
[-1., 1., 0.]
taichi.math.cpow(z, n)#

Computes the power of a complex z: \(z^a\).

Parameters:
  • z (vec2) – The base.

  • a (float) – The exponent.

Example:

>>> @ti.kernel
>>> def test():
>>>     z = ti.math.vec2(1, 1)
>>>     w = ti.math.cpow(z)  # [-2, 2]
Returns:

The power \(z^a\).

Return type:

vec2

taichi.math.cross(x, y)#

Calculate the cross product of two vectors.

The two input vectors must have the same dimension \(d <= 3\).

This function calls the cross method of Vector.

Parameters:
  • x (Matrix) – The first input vector.

  • y (Matrix) – The second input vector.

Returns:

The cross product of two vectors.

Example:

>>> x = ti.Vector([1., 0., 0.])
>>> y = ti.Vector([0., 1., 0.])
>>> ti.math.cross(x, y)
[0.000000, 0.000000, 1.000000]
taichi.math.csqrt(z)#

Returns the complex square root of a 2d vector z, so that if w^2=z, then w = csqrt(z).

Among the two square roots of z, if their real parts are non-zero, the one with positive real part is returned. If both their real parts are zero, the one with non-negative imaginary part is returned.

Parameters:

z (vec2) – The input.

Example:

>>> @ti.kernel
>>> def test():
>>>     z = ti.math.vec2(-1, 0)
>>>     w = ti.math.csqrt(z)  # [0, 1]
Returns:

The complex square root.

Return type:

vec2

taichi.math.degrees(x)#

Convert x in radians to degrees, element-wise.

Parameters:

x (Matrix) – The input angle in radians.

Returns:

angle in degrees.

Example:

>>> x = ti.Vector([-pi/2, pi/2])
>>> ti.math.degrees(x)
[-90.000000, 90.000000]
taichi.math.determinant(m)#

Alias for taichi.Matrix.determinant().

taichi.math.distance(x, y)#

Calculate the distance between two points.

This function is equivalent to the distance function is GLSL.

Parameters:
Returns:

The distance between the two points.

Example:

>>> x = ti.Vector([0, 0, 0])
>>> y = ti.Vector([1, 1, 1])
>>> ti.math.distance(x, y)
1.732051
taichi.math.dot(x, y)#

Calculate the dot product of two vectors.

Parameters:
  • x (Matrix) – The first input vector.

  • y (Matrix) – The second input vector.

Returns:

The dot product of two vectors.

Example:

>>> x = ti.Vector([1., 1., 0.])
>>> y = ti.Vector([0., 1., 1.])
>>> ti.math.dot(x, y)
1.000000
taichi.math.exp(x)#

Compute the exponential of all elements in x, element-wise.

Parameters:

x (Union[primitive_types, Matrix]) – Input scalar or matrix.

Returns:

Element-wise exponential of x.

Example:

>>> @ti.kernel
>>> def test():
>>>     x = ti.Matrix([-1.0, 0.0, 1.0])
>>>     y = ti.exp(x)
>>>     print(y)
>>>
>>> test()
[0.367879, 1.000000, 2.718282]
taichi.math.eye(n: ti.template())#

Returns the nxn identity matrix.

Alias for identity().

taichi.math.floor(x, dtype=None)#

Return the floor of the input, element-wise. The floor of the scalar x is the largest integer k, such that k <= x.

Parameters:
  • x (Union[primitive_types, Matrix]) – Input scalar or matrix.

  • dtype – (primitive_types): the returned type, default to None. If set to None the retuned value will have the same type with x.

Returns:

The floor of each element in x, with return value type dtype.

Example::
>>> @ti.kernel
>>> def test():
>>>     x = ti.Matrix([-1.1, 2.2, 3.])
>>>     y = ti.floor(x, ti.f64)
>>>     print(y)  # [-2.000000000000, 2.000000000000, 3.000000000000]
taichi.math.fract(x)#

Compute the fractional part of the argument, element-wise. It’s equivalent to x - ti.floor(x).

Parameters:

x (primitive_types, Matrix) – The input value.

Returns:

The fractional part of x.

Example:

>>> x = ti.Vector([-1.2, -0.7, 0.3, 1.2])
>>> ti.math.fract(x)
[0.800000, 0.300000, 0.300000, 0.200000]
taichi.math.inverse(mat)#

Calculate the inverse of a matrix.

This function is equivalent to the inverse function in GLSL.

Parameters:

mat (taichi.Matrix) – The matrix of which to take the inverse.

Returns:

Inverse of the input matrix.

Example:

>>> m = ti.math.mat3([(1, 1, 0), (0, 1, 1), (0, 0, 1)])
>>> ti.math.inverse(m)
[[1.000000, -1.000000, 1.000000],
 [0.000000, 1.000000, -1.000000],
 [0.000000, 0.000000, 1.000000]]
taichi.math.isinf(x)#

Determines whether the parameter is positive or negative infinity, element-wise.

Parameters:

x (primitive_types, taichi.Matrix) – The input.

Example

>>> x = ti.math.vec4(inf, -inf, nan, 1)
>>> ti.math.isinf(x)
[1, 1, 0, 0]
Returns:

For each element i of the result, returns 1 if x[i] is posititve or negative floating point infinity and 0 otherwise.

taichi.math.isnan(x)#

Determines whether the parameter is a number, element-wise.

Parameters:

x (primitive_types, taichi.Matrix) – The input.

Example

>>> x = ti.math.vec4(nan, -nan, inf, 1)
>>> ti.math.isnan(x)
[1, 1, 0, 0]
Returns:

For each element i of the result, returns 1 if x[i] is posititve or negative floating point NaN (Not a Number) and 0 otherwise.

taichi.math.ivec2#

2D signed int vector type.

taichi.math.ivec3#

3D signed int vector type.

taichi.math.ivec4#

3D signed int vector type.

taichi.math.length(x)#

Calculate the length of a vector.

This function is equivalent to the length function in GLSL. :param x: The vector of which to calculate the length. :type x: Matrix

Returns:

The Euclidean norm of the vector.

Example:

>>> x = ti.Vector([1, 1, 1])
>>> ti.math.length(x)
1.732051
taichi.math.log(x)#

Compute the natural logarithm, element-wise.

The natural logarithm log is the inverse of the exponential function, so that log(exp(x)) = x. The natural logarithm is logarithm in base e.

Parameters:

x (Union[primitive_types, Matrix]) – Input scalar or matrix.

Returns:

The natural logarithm of x, element-wise.

Example:

>>> @ti.kernel
>>> def test():
>>>     x = ti.Vector([-1.0, 0.0, 1.0])
>>>     y = ti.log(x)
>>>     print(y)
>>>
>>> test()
[-nan, -inf, 0.000000]
taichi.math.log2(x)#

Return the base 2 logarithm of x, so that if \(2^y=x\), then \(y=\log2(x)\).

This is equivalent to the log2 function is GLSL.

Parameters:

x (Matrix) – The input value.

Returns:

The base 2 logarithm of x.

Example:

>>> x = ti.Vector([1., 2., 3.])
>>> ti.math.log2(x)
[0.000000, 1.000000, 1.584962]
taichi.math.mat2#

2x2 floating matrix type.

taichi.math.mat3#

3x3 floating matrix type.

taichi.math.mat4#

4x4 floating matrix type.

taichi.math.max(*args)#

Compute the maximum of the arguments, element-wise.

This function takes no effect on a single argument, even it’s array-like. When there are both scalar and matrix arguments in args, the matrices must have the same shape, and scalars will be broadcasted to the same shape as the matrix.

Parameters:

args – (List[primitive_types, Matrix]): The input.

Returns:

Maximum of the inputs.

Example:

>>> @ti.kernel
>>> def foo():
>>>     x = ti.Vector([0, 1, 2])
>>>     y = ti.Vector([3, 4, 5])
>>>     z = ti.max(x, y, 4)
>>>     print(z)  # [4, 4, 5]
taichi.math.min(*args)#

Compute the minimum of the arguments, element-wise.

This function takes no effect on a single argument, even it’s array-like. When there are both scalar and matrix arguments in args, the matrices must have the same shape, and scalars will be broadcasted to the same shape as the matrix.

Parameters:

args – (List[primitive_types, Matrix]): The input.

Returns:

Minimum of the inputs.

Example:

>>> @ti.kernel
>>> def foo():
>>>     x = ti.Vector([0, 1, 2])
>>>     y = ti.Vector([3, 4, 5])
>>>     z = ti.min(x, y, 1)
>>>     print(z)  # [0, 1, 1]
taichi.math.mix(x, y, a)#

Performs a linear interpolation between x and y using a to weight between them. The return value is computed as \(x imes a + (1-a) imes y\).

The arguments can be scalars or Matrix, as long as the operation can be performed.

This function is similar to the mix function in GLSL.

Parameters:
Returns:

The linear

interpolation of x and y by weight a.

Return type:

(primitive_types, Matrix)

Example:

>>> x = ti.Vector([1, 1, 1])
>>> y = ti.Vector([2, 2, 2])
>>> a = ti.Vector([1, 0, 0])
>>> ti.math.mix(x, y, a)
[2.000000, 1.000000, 1.000000]
>>> x = ti.Matrix([[1, 2], [2, 3]], ti.f32)
>>> y = ti.Matrix([[3, 5], [4, 5]], ti.f32)
>>> a = 0.5
>>> ti.math.mix(x, y, a)
[[2.000000, 3.500000], [3.000000, 4.000000]]
taichi.math.mod(x, y)#

Compute value of one parameter modulo another, element-wise.

Parameters:
Returns:

the value of x modulo y. This is computed as x - y * floor(x/y).

Example:

>>> x = ti.Vector([-0.5, 0.5, 1.])
>>> y = 1.0
>>> ti.math.mod(x, y)
[0.500000, 0.500000, 0.000000]
taichi.math.normalize(v)#

Calculates the unit vector in the same direction as the original vector v.

It’s equivalent to the normalize function is GLSL.

Parameters:

x (Matrix) – The vector to normalize.

Returns:

The normalized vector \(v/|v|\).

Example:

>>> v = ti.Vector([1, 2, 3])
>>> ti.math.normalize(v)
[0.267261, 0.534522, 0.801784]
taichi.math.pow(base, exponent)#

First array elements raised to second array elements \({base}^{exponent}\), element-wise.

The result type of two scalar operands is determined as follows: - If the exponent is an integral value, then the result type takes the type of the base. - Otherwise, the result type follows

With the above rules, an integral value raised to a negative integral value cannot have a feasible type. Therefore, an exception will be raised if debug mode or optimization passes are on; otherwise 1 will be returned.

In the following situations, the result is undefined: - A negative value raised to a non-integral value. - A zero value raised to a non-positive value.

Parameters:
Returns:

base raised to exponent. This is a scalar if both base and exponent are scalars.

Example:

>>> @ti.kernel
>>> def test():
>>>     x = ti.Matrix([-2.0, 2.0])
>>>     y = -3
>>>     z = ti.pow(x, y)
>>>     print(z)
>>>
>>> test()
[-0.125000, 0.125000]
taichi.math.radians(x)#

Convert x in degrees to radians, element-wise.

Parameters:

x (Matrix) – The input angle in degrees.

Returns:

angle in radians.

Example:

>>> x = ti.Vector([-90., 45., 90.])
>>> ti.math.radians(x) / pi
[-0.500000, 0.250000, 0.500000]
taichi.math.reflect(x, n)#

Calculate the reflection direction for an incident vector.

For a given incident vector x and surface normal n this function returns the reflection direction calculated as \(x - 2.0 * dot(x, n) * n\).

This is equivalent to the reflect function is GLSL.

n should be normalized in order to achieve the desired result.

Parameters:
  • x (Matrix) – The incident vector.

  • n (Matrix) – The normal vector.

Returns:

The reflected vector.

Example:

>>> x = ti.Vector([1., 2., 3.])
>>> n = ti.Vector([0., 1., 0.])
>>> ti.math.reflect(x, n)
[1.000000, -2.000000, 3.000000]
taichi.math.refract(x, n, eta)#

Calculate the refraction direction for an incident vector.

This function is equivalent to the refract function in GLSL.

Parameters:
  • x (Matrix) – The incident vector.

  • n (Matrix) – The normal vector.

  • eta (float) – The ratio of indices of refraction.

Returns:

The refraction direction vector.

Return type:

Matrix

Example:

>>> x = ti.Vector([1., 1., 1.])
>>> y = ti.Vector([0, 1., 0])
>>> ti.math.refract(x, y, 2.0)
[2.000000, -1.000000, 2.000000]
taichi.math.rot_by_axis(axis, ang)#

Returns the 4x4 matrix representation of a 3d rotation with given axis axis and angle ang.

Parameters:
  • axis (vec3) – rotation axis

  • ang (float) – angle in radians unit

Returns:

rotation matrix

Return type:

mat4

taichi.math.rot_yaw_pitch_roll(yaw, pitch, roll)#

Returns a 4x4 homogeneous rotation matrix representing the 3d rotation with Euler angles (rotate with Y axis first, X axis second, Z axis third).

Parameters:
  • yaw (float) – yaw angle in radians unit

  • pitch (float) – pitch angle in radians unit

  • roll (float) – roll angle in radians unit

Returns:

rotation matrix

Return type:

mat4

taichi.math.rotation2d(ang)#

Returns the matrix representation of a 2d counter-clockwise rotation, given the angle of rotation.

Parameters:

ang (float) – Angle of rotation in radians.

Returns:

2x2 rotation matrix.

Return type:

mat2

Example:

>>>ti.math.rotation2d(ti.math.radians(30))
[[0.866025, -0.500000], [0.500000, 0.866025]]
taichi.math.rotation3d(ang_x, ang_y, ang_z)#

Returns a 4x4 homogeneous rotation matrix representing the 3d rotation with Euler angles (rotate with Y axis first, X axis second, Z axis third).

Parameters:
  • ang_x (float) – angle in radians unit around X axis

  • ang_y (float) – angle in radians unit around Y axis

  • ang_z (float) – angle in radians unit around Z axis

Returns:

rotation matrix

Return type:

mat4

Example

>>> ti.math.rotation3d(0.52, -0.785, 1.046)
[[ 0.05048351 -0.61339645 -0.78816002  0.        ]
[ 0.65833154  0.61388511 -0.4355969   0.        ]
[ 0.75103329 -0.49688014  0.4348093   0.        ]
[ 0.          0.          0.          1.        ]]
taichi.math.round(x, dtype=None)#

Round to the nearest integer, element-wise.

Parameters:
  • x (Union[primitive_types, Matrix]) – A scalar or a matrix.

  • dtype – (primitive_types): the returned type, default to None. If set to None the retuned value will have the same type with x.

Returns:

The nearest integer of x, with return value type dtype.

Example:

>>> @ti.kernel
>>> def test():
>>>     x = ti.Vector([-1.5, 1.2, 2.7])
>>>     print(ti.round(x))
[-2., 1., 3.]
taichi.math.scale(sx, sy, sz)#

Constructs a scale Matrix with shape (4, 4).

Parameters:
  • sx (float) – scale x.

  • sy (float) – scale y.

  • sz (float) – scale z.

Returns:

scale matrix.

Return type:

mat4

Example:

>>> ti.math.scale(1, 2, 3)
[[ 1. 0. 0. 0.]
 [ 0. 2. 0. 0.]
 [ 0. 0. 3. 0.]
 [ 0. 0. 0. 1.]]
taichi.math.sign(x)#

Extract the sign of the parameter, element-wise.

Parameters:

x (primitive_types, Matrix) – The input value.

Returns:

-1.0 if x is less than 0.0, 0.0 if x is equal to 0.0, and +1.0 if x is greater than 0.0.

Example:

>>> x = ti.Vector([-1.0, 0.0, 1.0])
>>> ti.math.sign(x)
[-1.000000, 0.000000, 1.000000]
taichi.math.sin(x)#

Trigonometric sine, element-wise.

Parameters:

x (Union[primitive_types, Matrix]) – Angle, in radians.

Returns:

The sine of each element of x.

Example:

>>> from math import pi
>>> x = ti.Matrix([-pi/2., 0, pi/2.])
>>> ti.sin(x)
[-1., 0., 1.]
taichi.math.smoothstep(edge0, edge1, x)#

Performs smooth Hermite interpolation between 0 and 1 when edge0 < x < edge1, element-wise.

The arguments can be scalars or Matrix, as long as they can be broadcasted to a common shape.

This function is equivalent to the smoothstep in GLSL.

Parameters:
Returns:

The smoothly interpolated value.

Example:

>>> edge0 = ti.Vector([0, 1, 2])
>>> edge1 = 1
>>> x = ti.Vector([0.5, 1.5, 2.5])
>>> ti.math.smoothstep(edge0, edge1, x)
[0.500000, 1.000000, 0.000000]
taichi.math.sqrt(x)#

Return the non-negative square-root of a scalar or a matrix, element wise. If x < 0 an exception is raised.

Parameters:

x (Union[primitive_types, Matrix]) – The scalar or matrix whose square-roots are required.

Returns:

The square-root y so that y >= 0 and y^2 = x. y has the same type as x.

Example:

>>> x = ti.Matrix([1., 4., 9.])
>>> y = ti.sqrt(x)
>>> y
[1.0, 2.0, 3.0]
taichi.math.step(edge, x)#

Generate a step function by comparing two values, element-wise.

step generates a step function by comparing x to edge. For element i of the return value, 0.0 is returned if x[i] < edge[i], and 1.0 is returned otherwise.

The two arguments can be scalars or Matrix, as long as they can be broadcasted to a common shape.

Parameters:
Returns:

The return value is computed as x >= edge, with type promoted.

Example:

>>> x = ti.Matrix([[0, 1], [2, 3]], ti.f32)
>>> y = 1
>>> ti.math.step(x, y)
[[1.000000, 1.000000], [0.000000, 0.000000]]
taichi.math.tan(x)#

Trigonometric tangent function, element-wise.

Equivalent to ti.sin(x)/ti.cos(x) element-wise.

Parameters:

x (Union[primitive_types, Matrix]) – Input scalar or matrix.

Returns:

The tangent values of x.

Example:

>>> from math import pi
>>> @ti.kernel
>>> def test():
>>>     x = ti.Matrix([-pi, pi/2, pi])
>>>     y = ti.tan(x)
>>>     print(y)
>>>
>>> test()
[-0.0, -22877334.0, 0.0]
taichi.math.tanh(x)#

Compute the hyperbolic tangent of x, element-wise.

Parameters:

x (Union[primitive_types, Matrix]) – Input scalar or matrix.

Returns:

The corresponding hyperbolic tangent values.

Example:

>>> @ti.kernel
>>> def test():
>>>     x = ti.Matrix([-1.0, 0.0, 1.0])
>>>     y = ti.tanh(x)
>>>     print(y)
>>>
>>> test()
[-0.761594, 0.000000, 0.761594]
taichi.math.translate(dx, dy, dz)#

Constructs a translation Matrix with shape (4, 4).

Parameters:
  • dx (float) – delta x.

  • dy (float) – delta y.

  • dz (float) – delta z.

Returns:

translation matrix.

Return type:

mat4

Example:

>>> ti.math.translate(1, 2, 3)
[[ 1. 0. 0. 1.]
 [ 0. 1. 0. 2.]
 [ 0. 0. 1. 3.]
 [ 0. 0. 0. 1.]]
taichi.math.uvec2#

2D unsigned int vector type.

taichi.math.uvec3#

3D unsigned int vector type.

taichi.math.uvec4#

4D unsigned int vector type.

taichi.math.vdir(ang)#

Returns the 2d unit vector with argument equals ang.

x (primitive_types): The input angle in radians.

Example

>>> x = pi / 2
>>> ti.math.vdir(x)
[0, 1]
Returns:

a 2d vector with argument equals ang.

taichi.math.vec2#

2D floating vector type.

taichi.math.vec3#

3D floating vector type.

taichi.math.vec4#

4D floating vector type.