POV-Ray : Newsgroups : povray.general : I need math help Server Time
19 Nov 2024 13:46:02 EST (-0500)
  I need math help (Message 1 to 10 of 11)  
Goto Latest 10 Messages Next 1 Messages >>>
From: =Bob=
Subject: I need math help
Date: 5 Mar 2002 16:52:31
Message: <3c853e1f@news.povray.org>
I need a formula to slowly adjust one value to
another value over a known period. For example,
I have an increment value of 1 and I want that
value to decrease until it's 0 (or some other
value as needed, 0 for now). And I must reach
the known period (length in this case).

So I would be doing something like:

somelen = 62;
incval = 1;
someotherval = ?

for (x=0;x<somelen;x+=incval)
    {
    incval -= someotherval;
    if (incval <= 0)
        break;
    }

I need x to achieve "somelen" and "incval" to
achieve the value of 0 at about the same time,
give or take a bit.

How do I calculate "someotherval" ?
Thanks for your help.
=Bob=


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: I need math help
Date: 5 Mar 2002 18:45:42
Message: <3C855736.7D202442@hotmail.com>
=Bob= wrote:
> 
> I need a formula to slowly adjust one value to
> another value over a known period. For example,
> I have an increment value of 1 and I want that
> value to decrease until it's 0 (or some other
> value as needed, 0 for now). And I must reach
> the known period (length in this case).
> 
> So I would be doing something like:
> 
> somelen = 62;
> incval = 1;
> someotherval = ?
> 
> for (x=0;x<somelen;x+=incval)
>     {
>     incval -= someotherval;
>     if (incval <= 0)
>         break;
>     }
> 
> I need x to achieve "somelen" and "incval" to
> achieve the value of 0 at about the same time,
> give or take a bit.
> 
> How do I calculate "someotherval" ?
> Thanks for your help.

Since you're asking in povray.general,
I'll answer with a POV script:

#declare StartValue = 31;
#declare EndValue = 3;
#declare NrOfSteps = 10;

#declare dValue = (EndValue - StartValue)/NrOfSteps;
#declare Step = 0;
#while (Step <= NrOfSteps)
  #declare X = StartValue + Step*dValue;
  #debug "\n"
  #debug str(X, 0, -1)
  #declare Step = Step + 1;
#end // while
#debug "\n"


Tor Olav


Post a reply to this message

From: =Bob=
Subject: Re: I need math help
Date: 5 Mar 2002 20:00:45
Message: <3c856a3d$1@news.povray.org>
Hi Tor,

Thanks for responding. How would I know
how many steps (NrOfSteps) to use? Or am
I missing something? What I'm trying to achieve
is to decrease a value over a known length in
an unkown number of steps.

Thanks for your help!
=Bob=

"Tor Olav Kristensen" <tor### [at] hotmailcom> wrote in message
news:3C855736.7D202442@hotmail.com...

[My post deleted]

: Since you're asking in povray.general,
: I'll answer with a POV script:
:
: #declare StartValue = 31;
: #declare EndValue = 3;
: #declare NrOfSteps = 10;
:
: #declare dValue = (EndValue - StartValue)/NrOfSteps;
: #declare Step = 0;
: #while (Step <= NrOfSteps)
:   #declare X = StartValue + Step*dValue;
:   #debug "\n"
:   #debug str(X, 0, -1)
:   #declare Step = Step + 1;
: #end // while
: #debug "\n"
:
: Tor Olav


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: I need math help
Date: 5 Mar 2002 20:34:05
Message: <3C857095.EFBD2FDF@hotmail.com>
=Bob= wrote:
> 
> Hi Tor,
> 
> Thanks for responding. How would I know
> how many steps (NrOfSteps) to use? Or am
> I missing something? What I'm trying to achieve
> is to decrease a value over a known length in
> an unkown number of steps.

E.g.:

If your known length is e.g. 3.14 meter
(i.e. the difference between StartValue
and EndValue equals 3.14) and you want to
decrease the X value for every millimetre,
then just use 3140 steps.

(3.14m = 3140mm)


> Thanks for your help!

You're welcome.


Tor Olav

> "Tor Olav Kristensen" <tor### [at] hotmailcom> wrote in message
news:3C855736.7D202442@hotmail.com...
> 
> [My post deleted]
> 
> : Since you're asking in povray.general,
> : I'll answer with a POV script:
> :
> : #declare StartValue = 31;
> : #declare EndValue = 3;
> : #declare NrOfSteps = 10;
> :
> : #declare dValue = (EndValue - StartValue)/NrOfSteps;
> : #declare Step = 0;
> : #while (Step <= NrOfSteps)
> :   #declare X = StartValue + Step*dValue;
> :   #debug "\n"
> :   #debug str(X, 0, -1)
> :   #declare Step = Step + 1;
> : #end // while
> : #debug "\n"
> :
> : Tor Olav


Post a reply to this message

From: =Bob=
Subject: Re: I need math help
Date: 5 Mar 2002 23:50:56
Message: <3c85a030$1@news.povray.org>
Hi Tor,

Thanks again for helping me. I think either I didn't
explain my needs correctly, or I don't understand
how to implement your suggestions for my case.

Here's my scenario:

I have 62 meters over which I must move an object.
It is currently moving at 1 meter per sec.
I want to come to a complete stop when I get to 62 meters.
I want to gradually slow down for the duration of those 62 meters.
I have no idea how many steps it will take.

The magic number for this example is about 0.008009

As I subtract the magic number from the current
increment value (starting at 1), when I reach the 62
meter mark, the increment value is very close to 0.

Code snippet kluge:
================================
#declare len = 62;
#declare inc = 1;
#declare currpos = 0;
#declare incChg = 0.008009;  // how do I calculate this number?
#declare nStepCt = 0;

#while (currpos <= len & inc >= incChg)
   #debug concat("CurrPos: ",str(currpos,0,-1),"  Inc: ",str(inc,0,-1),"\n")
   #declare inc = inc - incChg;
   #declare currpos = currpos + inc;
   #declare nStepCt = nStepCt + 1;
#end // while

#debug concat("Steps: ",str(nStepCt,0,-1)," incChg: ",str(incChg,0,-1),"\n")
==================================
This takes 124 steps to complete.

How do I calculate the value of "incChg" ?
Maybe there's a better way to do this?
Thanks again for your kind help...
=Bob=


Post a reply to this message

From: Randy Hawley
Subject: Re: I need math help
Date: 6 Mar 2002 00:52:47
Message: <3C85AF4F.76F919D7@iquest.net>
Bob,

I think what you are asking for is to have a value decay to some arbitrary
limit.  You will then need to evaluate the current value at some regular
interval, but you don't know ahead of time what the interval will be.

I guess what I see this working out to be is a curve that at the intial point of
the problem has some derivative that is not zero.  At the final point, its
derivative is zero.

What kind of a curve you use to figure this out is dependent on what kind of
motion you want the object to have.

A "simple" deceleration will generate a straight line, the velocity dropping
steadily as you appoach the end point.

More gradual deceleration, more like a car braking with most of the slowing done
in the late part of the path, would be more like a parabola.

This kind of motion is well described in the  Clock Mod Tutorial .  You should
check it out.

Randy

=Bob= wrote:

> Hi Tor,
>
> Thanks again for helping me. I think either I didn't
> explain my needs correctly, or I don't understand
> how to implement your suggestions for my case.
>
> Here's my scenario:
>
> I have 62 meters over which I must move an object.
> It is currently moving at 1 meter per sec.
> I want to come to a complete stop when I get to 62 meters.
> I want to gradually slow down for the duration of those 62 meters.
> I have no idea how many steps it will take.
>
> The magic number for this example is about 0.008009
>
> As I subtract the magic number from the current
> increment value (starting at 1), when I reach the 62
> meter mark, the increment value is very close to 0.
>
> Code snippet kluge:
> ================================
> #declare len = 62;
> #declare inc = 1;
> #declare currpos = 0;
> #declare incChg = 0.008009;  // how do I calculate this number?
> #declare nStepCt = 0;
>
> #while (currpos <= len & inc >= incChg)
>    #debug concat("CurrPos: ",str(currpos,0,-1),"  Inc: ",str(inc,0,-1),"\n")
>    #declare inc = inc - incChg;
>    #declare currpos = currpos + inc;
>    #declare nStepCt = nStepCt + 1;
> #end // while
>
> #debug concat("Steps: ",str(nStepCt,0,-1)," incChg: ",str(incChg,0,-1),"\n")
> ==================================
> This takes 124 steps to complete.
>
> How do I calculate the value of "incChg" ?
> Maybe there's a better way to do this?
> Thanks again for your kind help...
> =Bob=


Post a reply to this message


Attachments:
Download 'us-ascii' (3 KB)

From: =Bob=
Subject: Re: I need math help
Date: 6 Mar 2002 08:48:12
Message: <3c861e1c@news.povray.org>
Hi Randy,

Thanks, I downloaded the Clock Mod Tutorial and
will see if it provides me with what I need. Your
kind help is much appreciated.

Have a great day!
=Bob=

> "Randy Hawley" <rha### [at] iquestnet>
> wrote in message
> news:3C85AF4F.76F919D7@iquest.net...
>
> Bob,
> I think what you are asking for is to have a
> value decay to some arbitrary limit.  You
> will then need to evaluate the current value
> at some regular interval, but you don't know
> ahead of time what the interval will be.
> I guess what I see this working out to be is a
> curve that at the intial point of the problem
> has some derivative that is not zero.  At the
> final point, its derivative is zero.
>
> What kind of a curve you use to figure this
> out is dependent on what kind of motion you
> want the object to have.
>
> A "simple" deceleration will generate a
> straight line, the velocity dropping steadily
> as you appoach the end point.
>
> More gradual deceleration, more like a car
> braking with most of the slowing done in the
> late part of the path, would be more like a
> parabola.
>
> This kind of motion is well described in the
> Clock Mod Tutorial .  You should check it
> out.
> Randy


Post a reply to this message

From: =Bob=
Subject: Re: I need math help, partial solution
Date: 6 Mar 2002 13:05:58
Message: <3c865a86$1@news.povray.org>
Well, here's what works if one value is zero and the
other is a positive number:

#declare TotalLen = 62;
#declare StartVal = 1;
#declare EndVal = 0;
#declare nRange = EndVal - StartVal;

#if (nRange != 0)
    #declare nSteps = ((TotalLen / abs(nRange)) * 2) + 1;
    #declare ChgVal = nRange / nSteps;
#else
    #declare ChgVal = 0;
#end

Then subtract ChgVal from StartVal for every iteration. When
StartVal reaches EndVal, TotalLen is achieved.

The problem is, I want it to be able to work for an ending
or starting value that's not zero, like starting at 4 and stopping
at 2. Why does it only work for values that either start or end
at zero? It works if StartVal = 0 and EndVal = 10 and such.

Thanks for your help.
Have a great day!
=Bob=


Post a reply to this message

From: chaps
Subject: Re: I need math help
Date: 6 Mar 2002 13:59:18
Message: <3c866706$1@news.povray.org>
Hi Bob,
what I understand is that you want to perform an animation were an object is
going from point A to point B, decelerating to a full stop.

This as an infinite number of solutions. Lets take the simplest path: a
straight path with constant deceleration. in this case the path is given by



were A is acceleration, V is velocity when time is 0, X is position when
time is 0, x is position when time is equal to t.

You give the starting point X and an end point (0 in your example). The
equation show that you still need to define 2 values before being able to
calculate position at any time:
        initial speed and total duration,
or     initial speed and deceleration,
or     deceleration and total duration.

the first case seems to be relevent, that means that we say that initial
speed is V, and total duration is T. In order to be more general, let's say
that at the end (t = T) the position is Xe.


so

it is possible to calculate this constant, and then evaluate at each
animation step:

t = t + T/nbstep


Hope it will help you.

Chaps

"=Bob=" <bob### [at] threestrandscom> wrote in message
news:3c853e1f@news.povray.org...
> I need a formula to slowly adjust one value to
> another value over a known period. For example,
> I have an increment value of 1 and I want that
> value to decrease until it's 0 (or some other
> value as needed, 0 for now). And I must reach
> the known period (length in this case).
>
> So I would be doing something like:
>
> somelen = 62;
> incval = 1;
> someotherval = ?
>
> for (x=0;x<somelen;x+=incval)
>     {
>     incval -= someotherval;
>     if (incval <= 0)
>         break;
>     }
>
> I need x to achieve "somelen" and "incval" to
> achieve the value of 0 at about the same time,
> give or take a bit.
>
> How do I calculate "someotherval" ?
> Thanks for your help.
> =Bob=
>
>
>


Post a reply to this message

From: =Bob=
Subject: Re: I need math help
Date: 6 Mar 2002 16:47:27
Message: <3c868e6f@news.povray.org>
Thanks chaps,

That's what I needed. Sorry to have been so
confusing in my request everyone.

Have a great day!
=Bob=

"chaps" <cha### [at] yahoocom> wrote in message news:3c866706$1@news.povray.org...
: Hi Bob,
: what I understand is that you want to perform an animation were an object is
: going from point A to point B, decelerating to a full stop.
: This as an infinite number of solutions. Lets take the simplest path: a
: straight path with constant deceleration. in this case the path is given by


[deleted for brevity]


Post a reply to this message

Goto Latest 10 Messages Next 1 Messages >>>

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