POV-Ray : Newsgroups : povray.animations : Math Question Server Time
23 Nov 2024 19:58:19 EST (-0500)
  Math Question (Message 1 to 10 of 10)  
From: Josh
Subject: Math Question
Date: 13 Oct 2005 04:05:06
Message: <434e1532@news.povray.org>
I've got a Key Frame animation utility I've written.

Unfortunately it only works in straight lines, that is to say it calculates 
the variables for each frame by dividing the starting and ending values by 
the number of frames.

This is fine but I want to be able to start the movement faster and end it 
slower, and vice versa, possibly even have it faster at the beginning and 
and with it slower in the middle.

Example of what I am doing at the moment.

Start Value for Camera X is -100
End Value for Camera X is 1095
There are 150 frames, so I increment the Camera X by +7.96 per frame, a 
straight line.

What formular can I use to have the camera start faster and slow to a halt?


Post a reply to this message

From: Chris B
Subject: Re: Math Question
Date: 13 Oct 2005 05:12:32
Message: <434e2500$1@news.povray.org>
"Josh" <s### [at] acom> wrote in message news:434e1532@news.povray.org...
> I've got a Key Frame animation utility I've written.
>
> Unfortunately it only works in straight lines, that is to say it 
> calculates the variables for each frame by dividing the starting and 
> ending values by the number of frames.
>
> This is fine but I want to be able to start the movement faster and end it 
> slower, and vice versa, possibly even have it faster at the beginning and 
> and with it slower in the middle.
>
> Example of what I am doing at the moment.
>
> Start Value for Camera X is -100
> End Value for Camera X is 1095
> There are 150 frames, so I increment the Camera X by +7.96 per frame, a 
> straight line.
>
> What formular can I use to have the camera start faster and slow to a 
> halt?
>

It depends what sort of deceleration you want, but one option is to simply 
use a sin function something like:

Camera X =  sin( (FrameCounter-1)*90/149)*1195-100   ## Untested ##

So that, as the FrameCounter goes from 1 to 150 we take the sine of a number 
that goes from 0 to 90. This gives us a number that passes from 0 to 1 in a 
sinusoidal fashion (approaching 1 increasingly slowly) which we can multiply 
by the total distance to travel and finally adjust to start at -100.

Any good?

Chris B.


Post a reply to this message

From: Jaap
Subject: Re: Math Question
Date: 13 Oct 2005 15:20:01
Message: <web.434eb2871fdfabe8a8399d8d0@news.povray.org>
you can also do this using a (smooth) 2D or 3D spline function.
specify a couple if points, to define the path that an object
(or camera) shoeld follow, and use 2 or 3 points realy close
together at the start end end of the spline, so it starts/stops
at near-zero speed.
you can also yse a linear spline, if you realy want exactly trait
corners.
i'll try to find some old code of mine.


Post a reply to this message

From: Jaap
Subject: Re: Math Question
Date: 13 Oct 2005 15:30:00
Message: <web.434eb5471fdfabe8a8399d8d0@news.povray.org>
"Jaap" <jws### [at] yahoocom> wrote:
> i'll try to find some old code of mine.

copy-pate of the intersting parts:

// Render instructions:
// half:
// +w360 +h200 +a0.3 -j +kff100 +SF1 +EF99 +MB0 +UA +FN
// full:
// +w720 +h400 +a0.3 -j +kff100 +SF1 +EF99 +MB0 +UA +FN

// render settings:
// +w720   width  (overwrites other size settings) (also set camera
width/height ratio if needed)
// +h400   height (overwrites other size settings) (also set camera
width/height ratio if needed)
// +a0.3   use sub-sampling when difference between pixels > 0.3
// -j      disable pixel jitter
// +kff100 render a 100 frame animation
// +SF1    start with frame 1
// +EF99   last frame = 99
// +MB0    set bounding box threshold to 0. (see: explode.htm)
// +UA     leaf sky transparent (black) in output image. (sky and clouds are
still used for radiosity!)

// ------------------------------------------------------------------------
// |                    CAMERA POSITION:                                  |
// ------------------------------------------------------------------------
// PAN = camera field of view in degrees (smaller= zoom in, bigger = zoom
out)
// PdV = camera location
// PdA = camera "look at"

//#declare PAN=30; #declare PdV=<10000,-4000,250>; #declare PdA=<0,0,4900>;
// dichtbij

#declare camerPosSpline =
spline {
  cubic_spline
  -.25, <32000,-1000,250>
  0.00, <32000,-1000,250> // camera starting point
  0.50, <35000,-1000,250>
  1.00, <35000,-15000,250> // camera end point
  1.25, <35000,-15000,250>
}

#declare camerLookAtSpline =
spline {
  cubic_spline
  -.25, <  0,0,4500>
  0.00, <  0,0,4600> // camera starting point
  0.50, <500,0,4600>
  1.00, <  0,0,5000> // camera end point
  1.25, <  0,0,5100>
}

// get a point on the spline, depending in the "clock"
#declare PAN=30;
#declare PdV=camerPosSpline(clock);
#declare PdA=camerLookAtSpline(clock);

camera {
  location  PdV
//direction y*2.3
  sky       z
//up        z
//right     x*(4/3)     // "normal" ratio
//right     x           // sqare vield of view.
  right     x*(720/400) // widescreen ratio
  look_at   PdA
  angle     PAN
}

// --- your code here. ---


Post a reply to this message

From: Josh
Subject: Re: Math Question
Date: 17 Oct 2005 12:14:40
Message: <4353cdf0$1@news.povray.org>
> Any good?

Sadly not.  It does seem to be implementing a a sin value

frame 1 = 0
frame 10 = 749
frame 100 = 108
frame 150 = 893

Thanks for trying.  I couldn't even make a guess.


Post a reply to this message

From: Jaap
Subject: Re: Math Question
Date: 17 Oct 2005 17:45:01
Message: <web.43541aab1fdfabe8a8399d8d0@news.povray.org>
It was marked as "untested" :-)

pov-ray is a bit funny, it uses degrees in rotate commands, but radians in
functions: "sin(A) Sine of A. Returns the sine of the angle A, where  A is
measured in radians."
so try:
Camera_X =  sin(radians((FrameCounter-1)*90/149))*1195-100
or just:
Camera_X =  sin((FrameCounter-1)*(2*pi)/149)*1195-100
or:
Camera_X_start  = -100;
Camera_X_end    = 1095;
Camera_X_length = Camera_X_end-Camera_X_start;
Camera_X = sin((FrameCounter-1)*(2*pi)/149)*Camera_X_length-Camera_X_start;

(all ## Untested ##)

does that help ?


Post a reply to this message

From: Jaap
Subject: Re: Math Question
Date: 17 Oct 2005 17:50:00
Message: <web.43541c791fdfabe8a8399d8d0@news.povray.org>
> Camera_X =  sin((FrameCounter-1)*(2*pi)/149)*1195-100
oops, that's 360 deg, while we needed 90 deg, so:

Camera_X =  sin((FrameCounter-1)*(pi/2.0)/149)*1195-100
or:
Camera_X_start  = -100;
Camera_X_end    = 1095;
Camera_X_length = Camera_X_end-Camera_X_start;
Camera_X =
sin((FrameCounter-1)*(pi/2.0)/149)*Camera_X_length-Camera_X_start;

(a #declare pi2 = pi/2.0; at the top may come in handy)


Post a reply to this message

From: Jaap
Subject: Re: Math Question
Date: 17 Oct 2005 17:55:01
Message: <web.43541d1d1fdfabe8a8399d8d0@news.povray.org>
> Camera_X = sin((FrameCounter-1)*(pi/2)/149)*Camera_X_length-Camera_X_start;
I to get some sleep... Fixed the sign at the last Camera_X_start:
  Camera_X =
sin((FrameCounter-1)*(pi/2)/149)*Camera_X_length+Camera_X_start;


Post a reply to this message

From: Chris B
Subject: Re: Math Question
Date: 20 Oct 2005 09:11:57
Message: <4357979d$1@news.povray.org>
"Josh" <s### [at] acom> wrote in message news:4353cdf0$1@news.povray.org...
>> Any good?
>
> Sadly not.  It does seem to be implementing a a sin value
>
> frame 1 = 0
> frame 10 = 749
> frame 100 = 108
> frame 150 = 893
>
> Thanks for trying.  I couldn't even make a guess.
>

Hi Josh,
I should have pointed out that when you take the sine of the number, POV-Ray 
uses Radians by default, so, for this formula you need to use the POV-Ray 
sind() function which is in math.inc (I thought you were just missing the 
underlying mathematics) .

Here's a sample piece of SDL that writes the results into the message 
stream. It renders a blank scene, but if you look at the message stream it 
shows the distance travelled increasing from -100 to 1095 in progressively 
smaller steps.

#include "math.inc"

#local FrameCounter = 1;
#while (FrameCounter<151)
  #local DistanceX = sind((FrameCounter-1)*90/149)*1195-100;
  #debug concat("Frame Count: ",str(FrameCounter,3,3)," 
DistanceX: ",str(DistanceX,3,3),"\n")
  #local FrameCounter = FrameCounter + 1;
#end

In an animation you could also use a slightly simpler version using the 
clock variable as follows:
DistanceX = sind(clock*90)*1195-100;
(because the clock variable passes from 0 to 1 by default when generating a 
sequence of frames).

Hope that's better  :-)

Chris B.


Post a reply to this message

From: ScubaDude
Subject: Re: Math Question
Date: 20 Nov 2005 18:40:00
Message: <web.438108911fdfabe8739122c80@news.povray.org>
"Josh" <s### [at] acom> wrote:
> I've got a Key Frame animation utility I've written.
>
> Unfortunately it only works in straight lines, that is to say it calculates
> the variables for each frame by dividing the starting and ending values by
> the number of frames.
>
> This is fine but I want to be able to start the movement faster and end it
> slower, and vice versa, possibly even have it faster at the beginning and
> and with it slower in the middle.
>
> Example of what I am doing at the moment.
>
> Start Value for Camera X is -100
> End Value for Camera X is 1095
> There are 150 frames, so I increment the Camera X by +7.96 per frame, a
> straight line.
>
> What formular can I use to have the camera start faster and slow to a halt?

I was in the same situation and came up with this macro for use with my
Myst-ripoff elevator (put on hold, like everything else, because of
hurricane Katrina).
********************************************************

// move macro
//
// returns a real value based on the clock, smoothly transitioning from
StartPt to EndPt,
// from StartTime to EndTime following a sine function. usefull for
accelerating an
// object smoothly from StartPt to the mid-point then decelerating it
smoothly to EndPt.
// If clock <= StartPt, StartPt is returned. If clock >= EndPt, EndPt is
returned.
// requires math.inc
//
// inputs:
//   StartPt = real: the initial value
//     EndPt = real: the final value
// StartTime = real: the initial clock time
//   EndTime = real: the final clock time
//
// output:
// ObjMoverNum = real: the value of the variable at a particular clock time.
//
// example 1:
//-----------
// #include "math.inc"
// ObjMover (0, 10, 0.25, 0.75)
// sphere {
//   <ObjMoverNum, 0, 0>, 1
// }
//-----------
// creates a sphere which sits at the origin until clock>0.25, then moves
along the x-axis,
// arriving at <10,0,0> when clock=0.75, then staying at that point until
clock=1.
//
// example 2:
//-----------
// #include "math.inc"
// ObjMover (-30, 30, 0, 1)
// union {
//   cylinder {
//     <0, 0, 0>,
//     <0, -5, 0>,
//     0.1
//   }
//   sphere {
//     <0, -5, 0>, 0.3
//   }
//   rotate <0, 0, ObjMoverNum>
// }
//-----------
// creates a pendulum which swings smoothly from -30 degrees to 30 degrees
around the z-axis
// as the clock moves from 0 to 1.

#macro ObjMover (StartPt, EndPt, StartTime, EndTime)
  #local      Dist = EndPt - StartPt;
  #local  Duration = EndTime - StartTime;
  #local   ClockSc = 0.5 / Duration;
  #local HalfwayPt = (StartPt + EndPt)/2;
  #local   Clocker = ((clock - StartTime) * ClockSc) - 0.25;
  #if (clock>=StartTime)
    #if (clock<=EndTime)
      #declare ObjMoverNum = HalfwayPt+(sind (Clocker*360) * (Dist/2));
    #else
      #declare ObjMoverNum = EndPt;
    #end
  #else
    #declare ObjMoverNum = StartPt;
  #end
#end

********************************************************

Hope you find it handy,

Eric


Post a reply to this message

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