Search Unity

How to find the degree of interpolation?

Discussion in 'Scripting' started by MiaoBolverk, Jun 21, 2018.

  1. MiaoBolverk

    MiaoBolverk

    Joined:
    Feb 6, 2018
    Posts:
    26
    I have two quaternions: A and B. I want to lerp between them.

    Given another quaternion C, I want to find the variable unknown, as seen in the equation below:
    Code (csharp):
    1. Quaternion.Lerp(A, B, unknown) == C
    (Unfortunately, the equation above is misleading. In the scenario that C is "out of range" (i.e. not along the shortest path to get from A to B), unknown should simply be 0 or 1.)

    How can I do so?
     
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,537
    Well there is a big problem here.

    C isn't necessarily on the linear trajectory between A and B.

    The following will be a gross over-simplification of quats, but since it's difficult to describe 4 dimensional complex values in words without just using quats, this will have to do.

    Lets imagine your quaternions as points on a sphere. You draw 2 points, A and B, on that sphere. Then you draw a ring around the sphere that passes through both points and sheers the center point of the sphere. Any point on that ring are the possible results of Lerp (well, technically not since Lerp also clamps to 0->1, but that's a unity thing... LerpUnclamped doesn't clamp, and would give you the entire ring).

    If C is anywhere not on that ring... well, there is no 't' or 'unknown' to get to it.

    And the biggest issue... there are far more impossible C's then there are possible C's.

    ...

    With that said, if you have a value of C that you know for a fact is on that linear path of trajectory between A and B. Then just get the angle between A->C, and A->B and divide those to get 't' (unknown).
     
    Last edited: Jun 21, 2018
    xVergilx likes this.
  3. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
  4. WheresMommy

    WheresMommy

    Joined:
    Oct 4, 2012
    Posts:
    890
    Would be interesting to know, what you are trying to achieve. Maybe there is a better way to avoid that Lerp equation.
     
    Kurt-Dekker likes this.
  5. CubicCBridger

    CubicCBridger

    Joined:
    Apr 19, 2017
    Posts:
    44
    Assuming C is along lerp path between A and B, Total Angle = get angle between A and B , FractionAngle = angle between A and C, then unknown= FractionAngle/TotalAngle

    using https://math.stackexchange.com/questions/167827/compute-angle-between-quaternions-in-matlab

    If C is NOT along lerp path this will still get you a result, but the only thing you will be able to determine from this result is the magnitude of the angle C is away from A compared to B, and may not be useful depending on why you actually want to do this. (e.g if c not along lerp path a result of 1 will jsut mean both b and c are same angular distance from a, without being the same rotation).