POV-Ray : Newsgroups : povray.advanced-users : Some math aid required... Server Time
29 Jul 2024 00:32:58 EDT (-0400)
  Some math aid required... (Message 15 to 24 of 24)  
<<< Previous 10 Messages Goto Initial 10 Messages
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

From: Christopher James Huff
Subject: Re: Some math aid required...
Date: 11 Feb 2004 08:33:53
Message: <cjameshuff-1E9AC1.08341411022004@news.povray.org>
In article <402### [at] hotmailcom>,
 andrel <a_l### [at] hotmailcom> wrote:

> 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 :).

The one at the very end? That was in the original equation:
P1*(1 - t)^3 +
P2*3*(1 - t)^2*t -
P3*3*t^2*(1 - t) +
P4*t^3

If that's wrong, than the original equation is too. If you're talking 
about something in that term, the Maxima result is: 3*P2*(1 - t)^2 - 
6*P2*(1 - t)*t
=
3*P2*((1 - t)^2 - 2*(1 - t)*t)
=
3*P2*(-2*(1 - t)*t + (1 - t)^2)

Which agrees with my result.
As for training, I'm currently slogging my way through Calculus II, and 
am mainly self-taught. I'm still mainly teaching myself, due to the fact 
that the instructor can't speak clear English or write legibly. I'm also 
taking Numeric Analysis, which may cover splines later this semester.


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

a():=0.1; b():=0.9; c():=0.2; d():=1;
(Defined as functions because I couldn't figure out how to define them 
as variables in Maxima...damned annoying program, with practically 
useless documentation.)

f(t):=a()*(1 - t)^3 + b()*3*(1 - t)^2*t - c()*3*t^2*(1 - t) + d()*t^3;

fd(t):=3*(b() - a() + (a() - 2*b() - c())*2*t + (b()*3 + c()*3 + d() - 
a())*t^2);

tgt(t, p):= (t - p)*fd(p) + f(p);

plot2d([f(t), tgt(t, 0.2), tgt(t, 0.5), tgt(t, 0.9)], [t, 0, 1]);

-- 
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: 11 Feb 2004 09:19:40
Message: <402A39BB.7010809@hotmail.com>
Christopher James Huff wrote:
> In article <402### [at] hotmailcom>,
>  andrel <a_l### [at] hotmailcom> wrote:
> 
> 
>>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 :).
> 
> 
> The one at the very end? That was in the original equation:
> P1*(1 - t)^3 +
> P2*3*(1 - t)^2*t -
> P3*3*t^2*(1 - t) +
> P4*t^3
> 
> If that's wrong, than the original equation is too. 
Sorry, I did not check all your equations, I should have.
You are absolutely right here, your original equation
is wrong. There should not be a minus there either ;)

> If you're talking 
> about something in that term, the Maxima result is: 
I had never heard of Maxima, just googled it.
Perhaps I give it a try someday.
off-topic: Mostly I do the math required for POV by hand.
For years I did not do as much math as I do now. Sometimes
I even try to convince people that POV is an interesting
kind of application for learning math at a highschool level.
You often want to achieve some goal and the only way to do
it is sit down and do the equations. Along the same line,
if someone asked me why that should learn math at highschool
one of my answers is: to be able to create realworld
objects in POV!
	Andrel


Post a reply to this message

From: Christopher James Huff
Subject: Re: Some math aid required...
Date: 11 Feb 2004 11:48:18
Message: <cjameshuff-576C46.11483911022004@news.povray.org>
In article <402### [at] hotmailcom>,
 andrel <a_l### [at] hotmailcom> wrote:

> > If that's wrong, than the original equation is too. 
> Sorry, I did not check all your equations, I should have.
> You are absolutely right here, your original equation
> is wrong. There should not be a minus there either ;)

Well, that would explain why my equation works for finding tangents to 
it, but yours doesn't. Thought it looked odd...


> off-topic: Mostly I do the math required for POV by hand.

Mostly I program the computer to do it for me. I'm terrible at that kind 
of thing, always making arithmetic errors and simple little stuff like 
that...at least it wasn't me this time.


> For years I did not do as much math as I do now. Sometimes
> I even try to convince people that POV is an interesting
> kind of application for learning math at a highschool level.
> You often want to achieve some goal and the only way to do
> it is sit down and do the equations. Along the same line,
> if someone asked me why that should learn math at highschool
> one of my answers is: to be able to create realworld
> objects in POV!

It is a very good way of learning how the math applies to and relates to 
the real world, or at least approximations of it.

-- 
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: Tor Olav Kristensen
Subject: Re: Some math aid required...
Date: 11 Feb 2004 12:59:20
Message: <402a6d78@news.povray.org>
Tim Nikias v2.0 wrote:
> so, I've got the following formula to calculate Bezier-Splines:
...
> Anyways, I need to calculate the direction/tangent of the spline at any
> given position.
...

I suggest that you go googling for "Frenet Frames"

Look for web pages similar to this norwegian one:

http://tinyurl.com/27xap


Tor Olav


Post a reply to this message

<<< Previous 10 Messages Goto Initial 10 Messages

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