sm.vec3

Associated object type: Vec3

A vector is used to represent position and direction in 3D space, using X, Y and Z coordinates.

To create one, use sm.vec3.new.

Functions:

  • bezier2
  • bezier3
  • closestAxis
  • getRotation
  • lerp
  • new
  • one
  • zero

  • sm.vec3.bezier2(c0, c1, c2, t)

    Quadratic Bezier interpolation. Three dimensional bezier curve.

    Parameters:

    TypeNameDescription
    Vec3c0The start point.
    Vec3c1The control point.
    Vec3c2The end point.
    numbertThe interpolation step.

    Returns:

    TypeDescription
    Vec3The interpolated value between two values.

    sm.vec3.bezier3(c0, c1, c2, c3, t)

    Cubic Bezier interpolation. Three dimensional bezier curve.

    Parameters:

    TypeNameDescription
    numberc0The start point.
    numberc1The first control point.
    numberc2The second control point.
    numberc3The end point.
    numbertThe interpolation step.

    Returns:

    TypeDescription
    numberThe interpolated value between two values.

    sm.vec3.closestAxis(vector)

    Finds the closest axis-aligned vector from the given vector

    Parameters:

    TypeNameDescription
    Vec3vectorThe vector.

    Returns:

    TypeDescription
    Vec3The axis-aligned vector.

    sm.vec3.getRotation(v1, v2)

    Returns a quaternion representing the rotation from one vector to another.

    The quaternion can then be multiplied with any vector to rotate it in the same fashion.

    v1 = sm.vec3.new(1,0,0)
    v2 = sm.vec3.new(0,1,0)
    
    trans = sm.vec3.getRotation(v1, v2)
    -- `trans` now rotates a vector 90 degrees
    
    print(trans * v2)
    -- {, x = -1, y = 0, z = 0}

    Parameters:

    TypeNameDescription
    Vec3v1The first vector.
    Vec3v2The second vector.

    Returns:

    TypeDescription
    QuatThe transformation.

    sm.vec3.lerp(v1, v2, t)

    Performs a linear interpolation between two vectors.

    Parameters:

    TypeNameDescription
    Vec3v1The first vector.
    Vec3v2The second vector.
    numbertInterpolation amount between the two inputs.

    Returns:

    TypeDescription
    Vec3Interpolated vector.

    sm.vec3.new(x, y, z)

    Creates a new vector.

    Parameters:

    TypeNameDescription
    numberxThe X value.
    numberyThe Y value.
    numberzThe Z value.

    Returns:

    TypeDescription
    Vec3The created vector.

    sm.vec3.one()

    Creates a new vector with 1 in x, y, x.

    Returns:

    TypeDescription
    Vec3The one vector.

    sm.vec3.zero()

    Creates a new vector with 0 in x, y, x.

    Returns:

    TypeDescription
    Vec3The zero vector.