monotonicCubicInterpolant, Implementation Question

19 views
Skip to first unread message

Maik Figura

unread,
Jul 16, 2013, 5:27:05 AM7/16/13
to field...@googlegroups.com
Hello Magnus, 

when I was looking at the source code of the monotonicCubicInterpolant, I was wondering how the case (which is described in the original paper) delta_k != 0 and signum(d_k) == signum(d_k+1) == signum(delta_k) is checked against? I could not yet figure out, how you make sure that when delta_k != 0 all signums are the same. From what I understand, the case delta_k =! 0 is implicit by checking for if(delta_k == 0) but this does not include the signums condition, does it? 

template<class T>
T monotonicCubicInterpolant(const T &f1, const T &f2, const T &f3, const T &f4, 
                            double t)
{
  T d_k = T(.5) * (f3 - f1);
  T d_k1 = T(.5) * (f4 - f2);
  T delta_k = f3 - f2;

  if (delta_k == static_cast<T>(0)) {
    d_k = static_cast<T>(0);
    d_k1 = static_cast<T>(0);
  }

  T a0 = f2;
  T a1 = d_k;
  T a2 = (T(3) * delta_k) - (T(2) * d_k) - d_k1;
  T a3 = d_k + d_k1 - (T(2) * delta_k);

  T t1 = t;
  T t2 = t1 * t1;
  T t3 = t2 * t1;

  return a3 * t3 + a2 * t2 + a1 * t1 + a0;
}

Cheers 
Maik 

Magnus Wrenninge

unread,
Jul 31, 2013, 1:19:32 PM7/31/13
to field...@googlegroups.com
Hi Maik,

Sorry for the late reply, I was out at Siggraph last week.

I think you're right, we don't correctly check for that.

 if (delta_k == static_cast<T>(0)) {
    d_k = static_cast<T>(0);
    d_k1 = static_cast<T>(0);
  }

should really be

 if (delta_k == static_cast<T>(0) ||
    (sign(d_k) != sign(delta_k) || sign(d_k1) != sign(delta_k))) {
    d_k = static_cast<T>(0);
    d_k1 = static_cast<T>(0);
 } 

I'll submit a ticket for it. Thanks for finding that.

Magnus


Maik 

--
You received this message because you are subscribed to the Google Groups "Field3D dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to field3d-dev...@googlegroups.com.
To post to this group, send email to field...@googlegroups.com.
Visit this group at http://groups.google.com/group/field3d-dev.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages