POV-Ray : Newsgroups : povray.advanced-users : subtle behavior of Spline_Trans() macro in transforms.inc Server Time
23 Dec 2024 18:15:23 EST (-0500)
  subtle behavior of Spline_Trans() macro in transforms.inc (Message 1 to 10 of 33)  
Goto Latest 10 Messages Next 10 Messages >>>
From: Kenneth
Subject: subtle behavior of Spline_Trans() macro in transforms.inc
Date: 19 Apr 2009 16:10:00
Message: <web.49eb83fad1b3bb5cf50167bc0@news.povray.org>
I've lately been using the Spline_Trans() macro in transforms.inc, to align some
objects to a spline.  The macro is Spline_Trans(Spline, Time, SkyVector,
ForeSight, Banking). The basic use of this macro is to align the z-axis of a
created object to the 'forward' direction of the spline, at any particular
interpolated point along its surve. And it works very well; but the docs are
not quite clear about the Foresight value. To make the object alignment *exact*
at a particular spline point, it's recommended to set Foresight "close to zero".
SO...my own assumption was that setting it TO zero would be even more exact; but
that's not the case. What actually happens (at 0) is that the object suddenly
flips 90-deg.--it's now aligned at a right-angle to the spline's 'forward'
direction (which is wrong). So indeed the value SHOULD be 'close to zero' but
not zero.

Taking a look at the macro code itself, I *think* I see where this little
discrepancy lies (although I have to admit that I'm unfamiliar with such things
as Matrix and the other math-intensive functions found there.)

If Foresight=0, there are THREE #locals that now equal each other:
Location
LocationNext
LocationPrev

and Forward (also inside the macro) ends up as vnormalize(<0,0,0>). By making
Foresight some non-zero value (even a small one), vnormalize now has an actual
vector direction to work with.

How these things may affect the Matrix, Transform and VProject_Plane stuff there
is beyond me; but Foresight=0 obviously isn't a good recipe for success.
IMHO--and in an ideal world-- the code should be rewritten to be more elegant
and 'all-inclusive,' so to speak--so that a value of zero IS exact alignment.
But I haven't a clue how to do so! Maybe it isn't possible in the macro's
present form, relying--as it indeed needs to-- on the difference between any
two spline-point positions (and feeding that difference to vnormalize, to
create a vector direction.)

Ken W.


Post a reply to this message

From: Warp
Subject: Re: subtle behavior of Spline_Trans() macro in transforms.inc
Date: 19 Apr 2009 16:57:45
Message: <49eb9049@news.povray.org>
Kenneth <kdw### [at] earthlinknet> wrote:
> IMHO--and in an ideal world-- the code should be rewritten to be more elegant
> and 'all-inclusive,' so to speak--so that a value of zero IS exact alignment.

  The value of zero is not exact alignment because a vector of zero size
has no direction. (In practice what you get is a division by zero when
trying to normalize the vector or reorient anything using that vector).

  Two points on the spline gives you an approximation of the direction of
the spline (which is what is used here). The closer the points are to each
other, the more accurate the direction will be. Of course one could hastily
think that you should then use something like 1e-100 as the distance between
the two points to get a very very very accurate direction. However, the
drawback of using two points which are too close to each other is that you
start losing accuracy (due to the limited size of floating point numbers).
Thus using a distance of 1e-100 is not a good idea, as you will most probably
get a larger error than with eg. a distance of 1e-10.

  It is possible in mathematics to calculate the *exact* direction of a
spline, but to do that you need the three partial derivatives of the
spline function at the desired point (and then you can use these three
derivative functions to calculate the accurate direction vector).

  If you really want, you can try that (but first you will need to know
the exact spline function used by POV-Ray, and then you'll have to calculate
its three partial derivatives). However, I doubt you will get any significant
improvement in accuracy compared to the current approximation method using
two points on the spline (due to the limited accuracy of floating point
numbers).

-- 
                                                          - Warp


Post a reply to this message

From: clipka
Subject: Re: subtle behavior of Spline_Trans() macro in transforms.inc
Date: 19 Apr 2009 21:20:00
Message: <web.49ebcc72987a083f1a1b9caf0@news.povray.org>
"Kenneth" <kdw### [at] earthlinknet> wrote:
> How these things may affect the Matrix, Transform and VProject_Plane stuff there
> is beyond me; but Foresight=0 obviously isn't a good recipe for success.
> IMHO--and in an ideal world-- the code should be rewritten to be more elegant
> and 'all-inclusive,' so to speak--so that a value of zero IS exact alignment.

It's fundamentally impossible to do that.

Are you familiar with calculus?

Exact alignment would mean that the current direction would be the tangent to
the spline at the current position.

To compute a tangent to an arbitrary curve defined as f(t) (the value of which
in this case is a vector), you need the derivative f'(t) of that function,
which is defined as:

    f'(t) = lim(d->0) [f(t+d)-f(t)]/d

which is to say, take two *infinitesimally* close points on the function, and
divide the difference between the function values by the difference between the
function parameters.

As you will see, although this is an exact mathematical definition, it doesn't
work with d = 0 because you'd get 0/0, which is nonsense.

Of course even POV-SDL macros cannot overcome fundamental mathematical
limitations.


The only alternative would be to figure out a general formula for f'(t) for the
spline type and parameters in question - but as there is no way to query either
of these from SDL, we're stuck with what the macro does.


Post a reply to this message

From: Warp
Subject: Re: subtle behavior of Spline_Trans() macro in transforms.inc
Date: 20 Apr 2009 01:58:41
Message: <49ec0f11@news.povray.org>
clipka <nomail@nomail> wrote:
> It's fundamentally impossible to do that.

> To compute a tangent to an arbitrary curve defined as f(t) (the value of which
> in this case is a vector), you need the derivative f'(t) of that function,

  I find those two sentences contradictory. First you say that it's
impossible, and immediately after you tell how it's done.

-- 
                                                          - Warp


Post a reply to this message

From: scott
Subject: Re: subtle behavior of Spline_Trans() macro in transforms.inc
Date: 20 Apr 2009 03:26:48
Message: <49ec23b8$1@news.povray.org>
>> To compute a tangent to an arbitrary curve defined as f(t) (the value of 
>> which
>> in this case is a vector), you need the derivative f'(t) of that 
>> function,
>
>  I find those two sentences contradictory. First you say that it's
> impossible, and immediately after you tell how it's done.

Really? Can a macro in POV SDL calculate the exact mathematical derivative 
of a function?  I didn't know that.


Post a reply to this message

From: Warp
Subject: Re: subtle behavior of Spline_Trans() macro in transforms.inc
Date: 20 Apr 2009 04:28:23
Message: <49ec3227@news.povray.org>
scott <sco### [at] scottcom> wrote:
> >> To compute a tangent to an arbitrary curve defined as f(t) (the value of 
> >> which
> >> in this case is a vector), you need the derivative f'(t) of that 
> >> function,
> >
> >  I find those two sentences contradictory. First you say that it's
> > impossible, and immediately after you tell how it's done.

> Really? Can a macro in POV SDL calculate the exact mathematical derivative 
> of a function?  I didn't know that.

  Can a macro calculate points on a spline?

  It's simply a question of creating the macro. I don't see the problem.

  (The only situation where it would really be impossible to get an accurate
direction would be if the spline function does *not* have a derivative at all,
as is the case with some functions in mathematics.)

-- 
                                                          - Warp


Post a reply to this message

From: clipka
Subject: Re: subtle behavior of Spline_Trans() macro in transforms.inc
Date: 20 Apr 2009 04:45:00
Message: <web.49ec3596987a083f1a1b9caf0@news.povray.org>
Warp <war### [at] tagpovrayorg> wrote:
> clipka <nomail@nomail> wrote:
> > It's fundamentally impossible to do that.
>
> > To compute a tangent to an arbitrary curve defined as f(t) (the value of which
> > in this case is a vector), you need the derivative f'(t) of that function,
>
>   I find those two sentences contradictory. First you say that it's
> impossible, and immediately after you tell how it's done.

There's no contradiction in those two sentences unless you erroneously assume
"it" to be a forward reference (which is a very uncommon syntax in English
language :P) to "to compute a tangent..." while in fact it is a reference to
getting the macro to work with 0 as a parameter.


Post a reply to this message

From: clipka
Subject: Re: subtle behavior of Spline_Trans() macro in transforms.inc
Date: 20 Apr 2009 05:05:00
Message: <web.49ec3a86987a083f1a1b9caf0@news.povray.org>
Warp <war### [at] tagpovrayorg> wrote:
> > Really? Can a macro in POV SDL calculate the exact mathematical derivative
> > of a function?  I didn't know that.
>
>   Can a macro calculate points on a spline?
>
>   It's simply a question of creating the macro. I don't see the problem.

Ah, yes? Then go ahead and present your solution, Mr. Smart... pure POV-Ray SDL,
please.


Post a reply to this message

From: Warp
Subject: Re: subtle behavior of Spline_Trans() macro in transforms.inc
Date: 20 Apr 2009 05:35:15
Message: <49ec41d3@news.povray.org>
clipka <nomail@nomail> wrote:
> Warp <war### [at] tagpovrayorg> wrote:
> > > Really? Can a macro in POV SDL calculate the exact mathematical derivative
> > > of a function?  I didn't know that.
> >
> >   Can a macro calculate points on a spline?
> >
> >   It's simply a question of creating the macro. I don't see the problem.

> Ah, yes? Then go ahead and present your solution, Mr. Smart... pure POV-Ray SDL,
> please.

  I don't have the motivation to study exactly which mathematical function
POV-Ray is using for its splines nor calculating its derivatives.

  I don't see the problem you are having. A derivative function is nothing
more than a function. In the exact same way as you can create a macro which
returns values of a function, you can create another macro which returns
values of its derivative function. Because it's just another function.

  If you tell me that the derivative of the spline function can *not* be
calculated because it's one of those functions without a derivative, then
that may be plausible (although you would have to explain why that is so).
However, you write as if creating a macro which returns a vector based on
a derivative function is impossible. I just can't understand what is the
problem you are seeing there.

  Suppose we had the 1-dimensional function x^2 and we wanted to create a
macro which returns the tangent vector at a given point in that function.
Since we know that the derivative of x^2 is 2*x, that's rather trivial to do:

#macro OriginalFunction(X) X*X #end

#macro DirectionAt(X) <1, 2*X> #end

  It's the same thing for the spline, but a bitmore complicated (because
a spline is a 3-dimensional function rather than a 1-dimensional one and
thus you need the three partial derivatives).

-- 
                                                          - Warp


Post a reply to this message

From: clipka
Subject: Re: subtle behavior of Spline_Trans() macro in transforms.inc
Date: 20 Apr 2009 06:10:00
Message: <web.49ec49b4987a083f1a1b9caf0@news.povray.org>
Warp <war### [at] tagpovrayorg> wrote:
>   I don't have the motivation to study exactly which mathematical function
> POV-Ray is using for its splines nor calculating its derivatives.

You do have the motivation throwing smart statements about, but you don't have
any motivation to really investigate the issues you are talking about.

Wise guy.

You don't have to calculate any particular spline's derivative to find out what
the problem is. You just have to look at the macros and SDL statements we're
discussing about, to find out that you're overlooking a much more serious
obstacle.


>   I don't see the problem you are having. A derivative function is nothing
> more than a function. In the exact same way as you can create a macro which
> returns values of a function, you can create another macro which returns
> values of its derivative function. Because it's just another function.

BTW, *I* am not having *any* problem. I'm just describing why a problem the OP
has is inevitable.

Anyway, we are talking about macros. SDL statements, you know?

So how do you get the function value of an arbitrary spline out of POV-Ray?

Rrrright - you use an interface built into the SDL, which lets you use the
spline as a function.

Fine. Now how do you get the derivative value of an arbitrary spline out of
POV-Ray?

Um... yes?

Mind you: The spline type and coefficients are buried in the bowels of POV-Ray.
If you want to get at them from SDL, you need an interface to do that. No
interface - no access to the data. No access to the data - no way to insert the
data into your derivative formula (let alone decide on which formula to use,
because we don't even know the type of the spline).


Now, your turn. Stop blurping and show what you *really* know and understand
about the OP's question.

And no excuses: If you're too lazy to really investigate a certain matter,
better hold your breath about it right from the start.


Post a reply to this message

Goto Latest 10 Messages Next 10 Messages >>>

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