POV-Ray : Newsgroups : povray.general : Dumb clock animation question : Re: Dumb clock animation question Server Time
9 Jun 2024 11:06:42 EDT (-0400)
  Re: Dumb clock animation question  
From: JimT
Date: 20 Feb 2019 06:05:01
Message: <web.5c6d343930cdf982c97227110@news.povray.org>
Mike Horvath <mik### [at] gmailcom> wrote:
> On 2/19/2019 9:42 AM, Tor Olav Kristensen wrote:
> > Now S will vary between 0 and +pi. cos(S) will vary between +1 and -1. And T
> > will vary between 0 and +1.
> >
> > https://upload.wikimedia.org/wikipedia/commons/d/d2/Sine_and_Cosine.svg
> >
>
>
> Thank you again. That is what I needed.
>
>
> Mike

TOK's cosine formulation is actually extremely close to constant acceleration
for half the period followed by constant deceleration.

The following (tested in Matlab, not POVRay, but I think I've transliterated it)
allows for linear interpolation for AccFrac = 0, something very close to the
cosine for AccFrac = 0.5 (constant acceleration for half the period followed by
constant deceleration for the other half) or an acceleration followed by a
coast, followed by a deceleration for 0 < AccFrac < 0.5

#macro AccDec(StartTime,EndTime,AccFrac)
//
// AccFrac should be between 0 and 0.5. It will be clipped.
//
#local KFrac    = min(max(0,AccFrac),0.5);
//
#local RelTime  = (clock - StartTime)/(EndTime - StartTime);
#local RelTime  = min(max(0,RelTime),1);
//
#if(KFrac = 0)
  #local SP = RelTime;
#elseif(RelTime < KFrac)
  #local SP = RelTime*RelTime/(2*KFrac*(1-KFrac));
#elseif(RelTime < 1 - KFrac)
  #local SP = RelTime/(1-KFrac) - KFrac/(2*(1-KFrac));
#else
  #local SP = 1 - (1 - RelTime)*(1 - RelTime)/(2*KFrac*(1-KFrac));
#end
  SP
//
#end


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.