# mix的函数描述似乎有误

mix 函数的描述为 x\times a + (1-a)\times y，但是实际的代码是 x * (1.0 - a) + y * a

@ti.func
def mix(x, y, a):
"""Performs a linear interpolation between x and y using
a to weight between them. The return value is computed as
:math:x\times a + (1-a)\times y.

The arguments can be scalars or :class:~taichi.Matrix,
as long as the operation can be performed.

This function is similar to the mix function in GLSL.

Args:
x (:mod:~taichi.types.primitive_types, :class:~taichi.Matrix): Specify
the start of the range in which to interpolate.
y (:mod:~taichi.types.primitive_types, :class:~taichi.Matrix): Specify
the end of the range in which to interpolate.
a (:mod:~taichi.types.primitive_types, :class:~taichi.Matrix): Specify
the weight to use to interpolate between x and y.

Returns:
(:mod:~taichi.types.primitive_types, :class:~taichi.Matrix): The linear
interpolation of x and y by weight a.

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]]
"""
return x * (1.0 - a) + y * a


1 Like