IC Python API:Linear Interpolation
From Reallusion Wiki!
Revision as of 21:59, 13 May 2019 by Chuck (RL) (Talk | contribs) (Created page with "This article will introduce the concept of linear interpolation and it's usefulness. This lesson will use linear interpolation to build a staircase and customize it with simp...")
This article will introduce the concept of linear interpolation and it's usefulness. This lesson will use linear interpolation to build a staircase and customize it with simple to understand attributes.
Required Modules
Besides the rudimentary iClone Python module, we'll also be using os and winreg as a means to import a box prop to build the staircase.
import RLPy
import os
import winreg
</syntaxhighllight>
== Linear Interpoloation (Lerp) Formula ==
In mathematics, linear interpolation is a method of curve fitting using linear polynomials to construct new data points within the range of a discrete set of known data points. Simply put, linear interpolation can be used to retrieve the location of point along a line. Programmatically, we can reduce the complexity of this formula to simply give us a value between two given values based on far along the line we proceed.
<syntaxhighlight lang="Python">
def lerp(value_a, value_b, interpolation):
# Precise method, which guarantees v = v1 when t = 1
return (1 - interpolation) * value_a + value_b * interpolation
The interpolation value is always normalized for the size of the line i.e. it is always a value clamped between 0 and 1.