math docs
    Preparing search index...

    Function rotateTowards

    • Rotates the unit vector from toward the unit vector to by at most maxAngle radians.

      When the two are already within maxAngle this copies to, so the function doubles as a cone clamp: the result is to, limited to lie within maxAngle of from. That is the form a rotor joint limit and a per-frame turn rate both want.

      Both inputs are assumed to be unit length, and the result is unit length. maxAngle is treated as 0 if negative. When the inputs are exactly antiparallel the rotation plane is undefined and an arbitrary perpendicular is used.

      Parameters

      • out: vec3.Vec3

        the receiving vector

      • from: readonly [number, number, number]

        the unit vector to rotate away from

      • to: readonly [number, number, number]

        the unit vector to rotate toward

      • maxAngle: number

        the maximum rotation, in radians

      Returns vec3.Vec3

      out