---
tags:
    - "Lerp"
---

# Interpolate

[Math](index.md) / **Interpolate**

<div class="grid cards" markdown>

* :green_circle: Can Read

* :red_circle: Cannot Write

</div>

## Description

Interpolates between two rotations given a ratio number

## Code

```cs
using System;
using UnityEngine;
using VisualScript.Icons;

namespace VisualScript.Runtime
{
    [Get]
    
    [Title("Interpolate")]
    [Category("Math/Interpolate")]
    
    [Description("Interpolates between two rotations given a ratio number")]
    [Image(typeof(IconInterpolate), ColorTheme.Type.Yellow)]
    
    [Keywords("Lerp")]
    
    [Serializable]
    public class TypeQuaternionMathInterpolate : TypeQuaternion
    {
        [SerializeField] private GetQuaternion m_RotationA = new GetQuaternion();
        [SerializeField] private GetQuaternion m_RotationB = new GetQuaternion();
        
        [SerializeField] private GetNumber m_Ratio = new GetNumber();
        [SerializeField] private EaseMode m_Easing = EaseMode.Linear;
        [SerializeField] private GetBool m_Clamp = new GetBool();

        public override Quaternion GetPreview(GameObject source)
        {
            float ratio = Ease.Get(this.m_Easing, (float) this.m_Ratio.GetPreview(source));
            return Interpolate(this.m_RotationA.GetPreview(source), this.m_RotationB.GetPreview(source), ratio,
                this.m_Clamp.GetPreview(source));
        }

        public override Quaternion Get(Args args)
        {
            Quaternion a = this.m_RotationA.Get(args);
            Quaternion b = this.m_RotationB.Get(args);
            
            double ratio = Ease.Get(this.m_Easing, (float) this.m_Ratio.Get(args));
            bool clamp = this.m_Clamp.Get(args);
            
            return Interpolate(a, b, ratio, clamp);
        }

        private static Quaternion Interpolate(Quaternion a, Quaternion b, double ratio, bool clamp)
        {
            return clamp
                ? Quaternion.Lerp(a, b, (float) ratio)
                : Quaternion.LerpUnclamped(a, b, (float) ratio);
        }

        public override string ToString()
        {
            return $"Interpolate({this.m_RotationA}, {this.m_RotationB}, {this.m_Ratio})";
        }
        
        protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
    }
}
```

