POV-Ray : Newsgroups : povray.advanced-users : Some math aid required... Server Time
29 Jul 2024 02:32:29 EDT (-0400)
  Some math aid required... (Message 5 to 14 of 24)  
<<< Previous 4 Messages Goto Latest 10 Messages Next 10 Messages >>>
From: David Wallace
Subject: Re: Some math aid required...
Date: 10 Feb 2004 11:11:27
Message: <402902af@news.povray.org>
"sascha" <sas### [at] userssourceforgenet> wrote in message
news:4028e647$1@news.povray.org...
> Ah... someone was quicker :-)
>
> Of course I meant "tangents", not "normals" in my posting...

The 2nd derivative is the normal.


Post a reply to this message

From: Tim Nikias v2 0
Subject: Re: Some math aid required...
Date: 10 Feb 2004 12:08:53
Message: <40291025$1@news.povray.org>
> simplified:
>
> 3*(P2 - P1 + (P1 - 2*P2 - P3)*2*t + (P2*3 + P3*3 + P4 - P1)*t^2)

Simplified? ;-)

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.

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!

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 12:10:56
Message: <402910a0@news.povray.org>
[some complicated Math stuff abd derivative, Bernstein polynomials etc]
SNIP
> I hope this helps.

I did. Though that part about diffenciating the Bernstein polynomials, that
was a little above my head. Still, the other approach works fine and seems
to return actual normals, not just approximations. At least looks like that.

Regards and thanks a lot,
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 12:28:22
Message: <402914b6@news.povray.org>
Ah, I take that back. It just approximates the normals, it doesn't properly
calculate them. I'll try to do something with that differenciating thingy
you mentioned at the end and return here later.

Regards,
Tim

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


Post a reply to this message

From: sascha
Subject: Re: Some math aid required...
Date: 10 Feb 2004 12:34:42
Message: <40291632$1@news.povray.org>
You're right, it should give you the correct values for the tangents.

It follows from the deCasteljau algorithm (do a google for it) which can be used to
compute positions and tangents on a bezier curve.

regards,
-sascha

Tim Nikias v2.0 wrote:
> [some complicated Math stuff abd derivative, Bernstein polynomials etc]
> SNIP
> 
>>I hope this helps.
> 
> 
> I did. Though that part about diffenciating the Bernstein polynomials, that
> was a little above my head. Still, the other approach works fine and seems
> to return actual normals, not just approximations. At least looks like that.
> 
> Regards and thanks a lot,
> Tim
>


Post a reply to this message

From: sascha
Subject: Re: Some math aid required...
Date: 10 Feb 2004 12:44:41
Message: <40291889$1@news.povray.org>
No, it should work. Here's a part of a code I once wrote when playing with bezier
curves. What do you need the tangents for? Perhaps it's necessary to normalize them...

#default {
	finish { ambient 1 }
}

#declare curve_size = 0.05;
#declare point_size = 0.20;
#declare col = color rgb <1,1,1>;

camera {
	orthographic
	location <0,0,-30>
	look_at 0
}

#macro drawBezierCurve(p0,p1,p2,p3)
	#local s = 0;
	#while (s <= 1)
		#local p = bezier(p0,p1,p2,p3,s);
		#local n = dbezier(p0,p1,p2,p3,s);
		sphere {
			p,curve_size
			pigment { color col }
		}
		cylinder {
			p,p+vnormalize(n)*5,curve_size/2
			pigment { color col }
		}
		
		#local s = s + 1/50;
	#end
#end

#macro bezier(p0,p1,p2,p3,s)
	#local B0 = (1 - s) * (1 - s) * (1 - s);
	#local B1 = 3 * s * (1 - s) * (1 - s);
	#local B2 = 3 * s * s * (1 - s);
	#local B3 = s * s * s;
	p0 * B0 + p1 * B1 + p2 * B2 + p3 * B3
#end

#macro bezier2(p0,p1,p2,s)
	#local B0 = (1 - s) * (1 - s);
	#local B1 = 2 * s * (1 - s);
	#local B2 = s * s;
	p0 * B0 + p1 * B1 + p2 * B2
#end

#macro dbezier(p0,p1,p2,p3,s)
	#local n0 = p1 - p0;
	#local n1 = p2 - p1;
	#local n2 = p3 - p2;
	bezier2(n0,n1,n2,s)
#end


#macro drawPoint(p)
	sphere {
		p,point_size
		pigment { col }
	}
#end

#macro drawLine(a,b)
	cylinder {
		a,b,curve_size
		pigment { col }
	}
#end

#macro setColor(c)
	#declare col = color rgb c;
#end
	
#if (true)
	#declare A = <-10,-5>;
	#declare B = <-5,5>;
	#declare C = <5,5>;
	#declare D = <10,-5>;
	
	setColor(<1,0,0>)
	drawPoint(A)
	drawPoint(B)
	drawPoint(C)
	drawPoint(D)
	
	setColor(<0,0,1>)
	drawBezierCurve(A,B,C,D)
#end


Post a reply to this message

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

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

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