About Store Forum Documentation Contact



Post Reply 
Blending between 3 Vecs by one Flt
Author Message
Chris Offline
Member

Post: #1
Blending between 3 Vecs by one Flt
Hi,

Before me trying to explain my problem, here's a picture:

   

Input:

I have a Flt a = 0..1; I have three Vec p, v, and x and I have a Flt threshold such as 0.1f

Desired output:

I want a new Vec which is smoothly blended (it'd be good for both cubic and linear solutions) between p and v, when lower than threshold, or smoothly blended between v and x, when a is higher than threshold. I can't have any more "weights" other than a. Looking for correctness.

1. Is this just a simple case of if statements from a < threshold, then individual lerps to each one? If so, can LerpCube be applied component-wise to xyz to get the desired behaviour correctly?

2. Is there a more elegant way to do this, i'm very interested!
3. Is there a mathematical name for doing this optimally, like "offset cubic equation" etc?

Thanks for your help,
Chris
(This post was last modified: 04-13-2011 06:22 PM by Chris.)
04-13-2011 06:00 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: Blending between 3 Vecs by one Flt
you will get smooth result only when using EE::Lerp4 (but that needs 4 values, and you have 3)
I think there is on internet a smooth lerp that uses 3 values (search for "catmull-rom" in google for 3 values)

once you have the Lerp3 function you can do:

Code:
if(a<threshold)
{
   Flt step=LerpRS(a, 0, threshold);
   Vec out=Lerp3(p,v,x, step*0.5f);
}else
{
   Flt step=LerpRS(a, threshold, 1);
   Vec out=Lerp3(p,v,x, 0.5f+step*0.5f);
}

Lerp3(a,b,c, step) is assumed to return a..b for step=0 .. 0.5
and b..c for step = 0.5 .. 1
04-13-2011 07:29 PM
Find all posts by this user Quote this message in a reply
Chris Offline
Member

Post: #3
RE: Blending between 3 Vecs by one Flt
Thanks!

After looking around I think natural cubic splines seem to be good.

Here's a small implementation: http://www.cse.unsw.edu.au/~lambert/spli...Cubic.java (refers to here) and a test app.
04-13-2011 11:39 PM
Find all posts by this user Quote this message in a reply
Post Reply