POV-Ray : Newsgroups : povray.advanced-users : Some math aid required... Server Time
29 Jul 2024 00:23:23 EDT (-0400)
  Some math aid required... (Message 11 to 20 of 24)  
<<< Previous 10 Messages Goto Latest 10 Messages Next 4 Messages >>>
From: Tim Nikias v2 0
Subject: Re: Some math aid required...
Date: 10 Feb 2004 12:59:45
Message: <40291c11@news.povray.org>
Hm, the differenciating formulas at the end don't seem to work, I get pretty
weird results with that... I'll look if Chris's formula works. And if that
doesn't do it, I'll have to fumble around a little more, I guess.

Regards,
Tim

-- 
"Tim Nikias v2.0"
Homepage: <http://www.nolights.de>
Email: tim.nikias (@) nolights.de


Post a reply to this message

From: Tim Nikias v2 0
Subject: Re: Some math aid required...
Date: 10 Feb 2004 13:10:21
Message: <40291e8d@news.povray.org>
Okay, it DOES work. Made a mistake somewhere, should've double checked
before dropping the idea... Anyways, thanks, works fine now. (I'm a little
tired at the moment, had to get up early for an exam, but now I'm back to
POVing, yay! :-)

Regards,
Tim

-- 
"Tim Nikias v2.0"
Homepage: <http://www.nolights.de>
Email: tim.nikias (@) nolights.de


Post a reply to this message

From: Christopher James Huff
Subject: Re: Some math aid required...
Date: 10 Feb 2004 14:22:13
Message: <cjameshuff-D9DE5C.14223410022004@news.povray.org>
In article <40291025$1@news.povray.org>,
 "Tim Nikias v2.0" <tim.nikias (@) nolights.de> wrote:

> > simplified:
> >
> > 3*(P2 - P1 + (P1 - 2*P2 - P3)*2*t + (P2*3 + P3*3 + P4 - P1)*t^2)
> 
> Simplified? ;-)

A simplified version of:

P1*3*(1 - t)^2*(-1) + P2*3*(2*(1 - t)*(-1)*t + (1 - t)^2) - P3*3*(2*t*(1 
- t) - t^2) + P4*3*t^2


> Uhm... Well, Sascha's approach worked quite well (now I just have to get it
> work with more than one segment, but that's not the difficult part). To be
> honest, I didn't really understand where you went with the derivative. Was a
> long time ago that I had algebra in school, so I can't check if it's correct
> or not, and since it looked so complicated, I took a first go with Sascha's
> formula.

Well, as far as I can tell, the second method Sascha gave is identical 
to the one I gave, though expressed a bit differently. I'm not sure 
what's going on with the first method...but I think it's mathematically 
equivalent, just a shortcut. I'm going to have to look at it further...


> Still, enlighten me about this part:
> 
> > The tangent line at point p would be:
> > x*f'(p) - p*f'(p) + f(p)
> > where f() is the spline function, and f'() is its derivative.
> 
> So, instead of using t, you want me to put a point into a function? What's
> x? I got a little confused here and am not really sure what you were trying
> to tell me. Thanks for the effort though!

Instead of using t for what?
You asked for a tangent line to a spline segment and gave an equation 
for that segment. f() is that equation, f'() is the derivative I gave. 
The equation I gave is the equation for a line tangent to the spline at 
t == p, with x being the horizontal axis. x*f'(p) - p*f'(p) + f(p) gives 
a line tangent to f() at f(p).

To find a line tangent to a curve at a given point, you need to know the 
slope of the curve at that point. The slope is just the rate of change, 
the first derivative of the function. x*f'(p) is a line through (0, 0) 
parallel to the tangent line. Subtract p*f'(p) so it equals 0 at (p, 0), 
under the desired point, and add f(p) to bring it up to the curve at 
that point. The final equation would be:
x*f'(p) - p*f'(p) + f(p) == (x - p)*f'(p) + f(p) ==

(x - p)*3*(P2 - P1 + (P1 - 2*P2 - P3)*2*p + (P2*3 + P3*3 + P4 - 
P1)*p^2)) + P1*(1 - p)^3 + P2*3*(1 - p)^2*p - P3*3*p^2*(1 - p) + P4*p^3

Where p is the point along the spline where you want the tangent line. 
The result of this equation is the height at x of the line tangent to 
the spline at p.

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: <chr### [at] tagpovrayorg>
http://tag.povray.org/


Post a reply to this message

From: Christopher James Huff
Subject: Re: Some math aid required...
Date: 10 Feb 2004 14:23:23
Message: <cjameshuff-0EC0A1.14234510022004@news.povray.org>
In article <402902af@news.povray.org>,
 "David Wallace" <dar### [at] earthlinknet> wrote:

> > Of course I meant "tangents", not "normals" in my posting...
> 
> The 2nd derivative is the normal.

And the first derivative is the tangent. Sascha just got the terms 
switched.

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: <chr### [at] tagpovrayorg>
http://tag.povray.org/


Post a reply to this message

From: andrel
Subject: Re: Some math aid required...
Date: 10 Feb 2004 14:42:24
Message: <402933DF.9090504@hotmail.com>
> The slope of the tangent is simply the derivative, the rate of change at 
> the given point. Unless I've screwed up the math somewhere, that would 
> be:
> 
> P1*3*(1 - t)^2*(-1) +
> P2*3*(2*(1 - t)*(-1)*t + (1 - t)^2) -
> P3*3*(2*t*(1 - t) - t^2) +
> P4*3*t^2
> 
> simplified:
> 
> 3*(P2 - P1 + (P1 - 2*P2 - P3)*2*t + (P2*3 + P3*3 + P4 - P1)*t^2)
> 
> (somebody want to check that?)
3*(P2 - P1 + (P1 - 2*P2 + P3)*2*t + (-P1 + P2*3 - P3*3 + P4)*t^2)

	Andrel


Post a reply to this message

From: Christopher James Huff
Subject: Re: Some math aid required...
Date: 10 Feb 2004 15:22:15
Message: <cjameshuff-90A371.15223610022004@news.povray.org>
In article <402### [at] hotmailcom>,
 andrel <a_l### [at] hotmailcom> wrote:

> > 3*(P2 - P1 + (P1 - 2*P2 - P3)*2*t + (P2*3 + P3*3 + P4 - P1)*t^2)
> > 
> > (somebody want to check that?)
> 3*(P2 - P1 + (P1 - 2*P2 + P3)*2*t + (-P1 + P2*3 - P3*3 + P4)*t^2)

Well, that doesn't work. The resulting lines are close, but not quite 
tangent. My results look right, any errors are small ones.

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: <chr### [at] tagpovrayorg>
http://tag.povray.org/


Post a reply to this message

From: Tim Nikias v2 0
Subject: Re: Some math aid required...
Date: 10 Feb 2004 15:34:26
Message: <40294052$1@news.povray.org>
> Well, as far as I can tell, the second method Sascha gave is identical
> to the one I gave, though expressed a bit differently. I'm not sure
> what's going on with the first method...but I think it's mathematically
> equivalent, just a shortcut. I'm going to have to look at it further...

It works, now that I've cleaned the code and found some stupid mistakes I
made... As I understand it, instead of interpolating between four points
with a cubic, I interpolate with three points with a squared function. I
guess there's some more fundamental background behind this (perhaps googling
Bernstein might help, who knows), but I'm not in the mood right now to dig
into math. Perhaps tomorrow, when I'm less lazy and getting more and excited
with Povray again.

SNIP [some Math Stuff]

Ah, now I understood what you were aiming at. Yes, that should work, too.
But honestly, that "shortcut", as you called it, looks nice and slick in
code, whereas the "simplified" model looks pretty ugly. Unless... Taking a
long shot here, but I guess you could adjust the formula so that it ends up
looking like the one Sascha gave...

Ah well, tomorrow is time for math-fun. Today, my brain is already spent
(well, most of it).

Regards,
Tim
-- 
"Tim Nikias v2.0"
Homepage: <http://www.nolights.de>
Email: tim.nikias (@) nolights.de


Post a reply to this message

From: Christopher James Huff
Subject: Re: Some math aid required...
Date: 10 Feb 2004 16:17:44
Message: <cjameshuff-F597F7.16180510022004@news.povray.org>
In article <40294052$1@news.povray.org>,
 "Tim Nikias v2.0" <tim.nikias (@) nolights.de> wrote:

> It works, now that I've cleaned the code and found some stupid mistakes I
> made... As I understand it, instead of interpolating between four points
> with a cubic, I interpolate with three points with a squared function.

Well, yes, the derivative of the cubic spline is a quadratic function. 
It doesn't interpolate between those three points though...its value at 
one of those points is not the value of that point, it is the slope of 
the tangent line at that point. It appears to be something like a 
quadratic interpolation of the tangents formed by the control points...


> Ah, now I understood what you were aiming at. Yes, that should work, too.
> But honestly, that "shortcut", as you called it, looks nice and slick in
> code, whereas the "simplified" model looks pretty ugly. Unless... Taking a
> long shot here, but I guess you could adjust the formula so that it ends up
> looking like the one Sascha gave...

Again, that was only a simplified expression of the equation of the 
derivative. The term "simplified" has nothing to do with how simple it 
is compared to other solutions.


B0(t) = (1 - t)^2
B1(t) = 2*t*(1 - t)
B2(t) = t^2

n0 = p1 - p0
n1 = p2 - p1
n2 = p3 - p2

n(t) = n0*B0(t) + n1*B1(t) + n2*B2(t)
=
(p1 - p0)*(1 - t)^2 + (p2 - p1)*2*t*(1 - t) + (p3 - p2)*t^2

But this does not work at all...

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: <chr### [at] tagpovrayorg>
http://tag.povray.org/


Post a reply to this message

From: sascha
Subject: Re: Some math aid required...
Date: 11 Feb 2004 03:05:23
Message: <4029e243$1@news.povray.org>
Christopher James Huff wrote:

> B0(t) = (1 - t)^2
> B1(t) = 2*t*(1 - t)
> B2(t) = t^2
> 
> n0 = p1 - p0
> n1 = p2 - p1
> n2 = p3 - p2
> 
> n(t) = n0*B0(t) + n1*B1(t) + n2*B2(t)
> =
> (p1 - p0)*(1 - t)^2 + (p2 - p1)*2*t*(1 - t) + (p3 - p2)*t^2
> 
> But this does not work at all...
> 

Sure it does!

Take a look at the image at http://192.94.226.61/decasteljau.png

it shows a bezier curve defined by p0,p1,p2,p3 and the deCasteljau construction
of point P at t = 3/4 (just as an example).

The tangent through P is, as we can see, the vector b - a.

Ok, let's take a closer look:

first, let's construct the points x,y and z

x = p0(1-t) + p1t
y = p1(1-t) + p2t
z = p2(1-t) + p3t

now we can construct a and b

a = x(1-t) + yt =
  = p0(1-t)^2 + p1t(1-t) + p1(1-t)t + p2t^2 =
  = p0(1-t)^2 + p1*2t(1-t) + p2t^2

b = y(1-t) + zt =
  = p1(1-t)^2 + p2t(1-t) + p2(1-t)t + p3t^2 =
  = p1(1-t)^2 + p2*2t(1-t) + p3t^2

our tangent is b - a =
  = p1(1-t)^2 + p2*2t(1-t) + p3t^2 - p0(1-t)^2 - p1*2t(1-t) - p2t^2 =
  = (p1-p0)(1-t)^2 + (p2-p1)*2t(1-t) + (p3-p2)t^2

Q.E.D


Post a reply to this message

From: andrel
Subject: Re: Some math aid required...
Date: 11 Feb 2004 04:19:54
Message: <4029F379.9060901@hotmail.com>
Christopher James Huff wrote:
> In article <402### [at] hotmailcom>,
>  andrel <a_l### [at] hotmailcom> wrote:
> 
> 
>>>3*(P2 - P1 + (P1 - 2*P2 - P3)*2*t + (P2*3 + P3*3 + P4 - P1)*t^2)
>>>
>>>(somebody want to check that?)
>>
>>3*(P2 - P1 + (P1 - 2*P2 + P3)*2*t + (-P1 + P2*3 - P3*3 + P4)*t^2)
> 
> 
> Well, that doesn't work. The resulting lines are close, but not quite 
> tangent. 

Are you sure? I have used this myself and when I used it
the tangents were correct. Note also the symmetries in the
coefficient, the binomial coeeficients and the nice alternating
signs. I think the original error may be in the line:
 > P2*3*(2*(1 - t)*(-1)*t + (1 - t)2) -
In my deriviation the final '-' is a '+'. BTW, I derived the
equations in the same way as you did. Well, of course, we both
have the same sort of math training I suspect :).

completely aside:
I had to compute the tangents when trying to
understand where some of my apparently discontinuous
normals in bezier patches come from. To check what I
would expect against the POV source I  manually
constructed a subdivision in smooth triangles. For
this I needed the local normal in the vertices of the
subdivided patch. The result was nearly identical to
the POV version and remaining differences the result
of round off errors. Conclusion: there is nothing
wrong with mor mine nor POVs calculations. I only
still have these images with discontinuous normals
in bezier patches that I can prove to be continuous.
In short: I an still absolutely confused about this.
But that is life I suspect :)
To be continued someday, but todat I have to work
a bit first.

 > My results look right, any errors are small ones.
 >
What equations did you use in the end?


Post a reply to this message

<<< Previous 10 Messages Goto Latest 10 Messages Next 4 Messages >>>

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