POV-Ray : Newsgroups : povray.general : Cubic spline tangents don't have expected effect? Server Time: 19 Feb 2019 23:37:51 GMT
  Cubic spline tangents don't have expected effect? (Message 1 to 6 of 6)  
From: kendfrey
Subject: Cubic spline tangents don't have expected effect?
Date: 17 Jan 2019 13:10:00
Message: <web.5c407b748844a7763ca35f5e0@news.povray.org>
I'm trying to approximate a quarter-circle with a cubic spline, but I'm not
getting the results I expected.

Here is my scene file: https://pastebin.com/SyUgKkHx

Based on this paper, the correct value for k should be about 0.552:
https://www.mechanicalexpressions.com/explore/geometric-modeling/circle-spline-approximation.pdf

However, in my example, that value is too low, and k seems to be about 2.313
instead.

What's going on here?


Post a reply to this message

From: clipka
Subject: Re: Cubic spline tangents don't have expected effect?
Date: 17 Jan 2019 13:49:08
Message: <5c4087d4$1@news.povray.org>
Am 17.01.2019 um 14:07 schrieb kendfrey:
> I'm trying to approximate a quarter-circle with a cubic spline, but I'm not
> getting the results I expected.

Buyer beware: There are different breeds of cubic (i.e 3rd order 
polynomial) splines, which differ in how the control points are 
translated into polynom coefficients. The article is about cubic splines 
of the Bezier type, while POV-Ray's "cubic" splines are close relatives 
of the Catmull-Rom type.


Post a reply to this message

From: kendfrey
Subject: Re: Cubic spline tangents don't have expected effect?
Date: 17 Jan 2019 14:25:00
Message: <web.5c408f38f0b41c833ca35f5e0@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:
> POV-Ray's "cubic" splines are close relatives of the Catmull-Rom type.

Thanks, I can see the similarities now that it's been pointed out.

However, it does appear to be calculated differently. My goal is to create the
equivalent to the bezier spline in the paper, but as I have no idea how the
spline is actually calculated, I don't know how to convert it.


Post a reply to this message

From: kendfrey
Subject: Re: Cubic spline tangents don't have expected effect?
Date: 17 Jan 2019 14:40:00
Message: <web.5c4092e1f0b41c833ca35f5e0@news.povray.org>
WolframAlpha has suggested the expression 8*sqrt(2)-9 based on my approximation,
and it seems accurate to 10 digits, so I'll use it. I have no idea where the
expression comes from, though.


Post a reply to this message

From: JimT
Subject: Re: Cubic spline tangents don't have expected effect?
Date: 17 Jan 2019 17:55:00
Message: <web.5c40c051f0b41c83be7517870@news.povray.org>
"kendfrey" <nomail@nomail> wrote:
> WolframAlpha has suggested the expression 8*sqrt(2)-9 based on my approximation,
> and it seems accurate to 10 digits, so I'll use it. I have no idea where the
> expression comes from, though.

The Bezier spline is based on the identity ((1-t) + t)^3 = 1

Given two endpoints, p_0 and p_3 and two "direction" points, p_1 and p_2 which
give the tangents at the end points in the directions of p_1-p_0 and p_3-p_2.
The actual tangents are 3(p_1 - p_0) and 3(p_3 - p_2),

p(t) = (1-t)^3xp_0 + 3(1-t)^2txp_1 + 3(1-t)t^2xp_2 + t^3xp_3

For an approximation to a  circle,

p_0 = (1,0), p_1 = (1,a), p_2 = (a,1), p_3 = (0,1)

A simple determination of a comes from putting p(1/2) = (1/sqrt(2),1/sqrt(2)),
though this isn't the best least squares approximation.

Just calculating the x component,

1/sqrt(2) = 1/8 + 3/8 + 3a/8, a = 8(sqrt(2) - 1)/6 = 0.5522847498

A Catmull-Rom spline sets the first direction point of an equivalent Bezier
spline  at p_i to be p_i + (p_(i+1) - p_(i-1))/6 (this sets the tangent
to be (p_(i+1) - p_(i-1))/2 which is more believable) so the 4 points for
POV-Ray's sphere sweep are, as you say,

p_(-1) = (0,-k), p_0 = (1,0), p_1 = (0,1) and p_2 = (-k,0). The spline
goes from p_0 to p_1. Thus the direction point for the equivalent Bezier
spline will be (1,(1+k)/6).

Setting the y component, (1+k)/6 equal to the y component of the Bezier
direction point, which is just a = 0.5522847498, we get k = 2.313708499

I use single Bezier spline segments quite a lot since I find the placement
of the direction points at least partly intuitive.


Post a reply to this message

From: kendfrey
Subject: Re: Cubic spline tangents don't have expected effect?
Date: 17 Jan 2019 18:50:00
Message: <web.5c40cd86f0b41c833ca35f5e0@news.povray.org>
"JimT" <nomail@nomail> wrote:
> "kendfrey" <nomail@nomail> wrote:
> > WolframAlpha has suggested the expression 8*sqrt(2)-9 based on my approximation,
> > and it seems accurate to 10 digits, so I'll use it. I have no idea where the
> > expression comes from, though.
>
> The Bezier spline is based on the identity ((1-t) + t)^3 = 1
>
> Given two endpoints, p_0 and p_3 and two "direction" points, p_1 and p_2 which
> give the tangents at the end points in the directions of p_1-p_0 and p_3-p_2.
> The actual tangents are 3(p_1 - p_0) and 3(p_3 - p_2),
>
> p(t) = (1-t)^3xp_0 + 3(1-t)^2txp_1 + 3(1-t)t^2xp_2 + t^3xp_3
>
> For an approximation to a  circle,
>
> p_0 = (1,0), p_1 = (1,a), p_2 = (a,1), p_3 = (0,1)
>
> A simple determination of a comes from putting p(1/2) = (1/sqrt(2),1/sqrt(2)),
> though this isn't the best least squares approximation.
>
> Just calculating the x component,
>
> 1/sqrt(2) = 1/8 + 3/8 + 3a/8, a = 8(sqrt(2) - 1)/6 = 0.5522847498
>
> A Catmull-Rom spline sets the first direction point of an equivalent Bezier
> spline  at p_i to be p_i + (p_(i+1) - p_(i-1))/6 (this sets the tangent
> to be (p_(i+1) - p_(i-1))/2 which is more believable) so the 4 points for
> POV-Ray's sphere sweep are, as you say,
>
> p_(-1) = (0,-k), p_0 = (1,0), p_1 = (0,1) and p_2 = (-k,0). The spline
> goes from p_0 to p_1. Thus the direction point for the equivalent Bezier
> spline will be (1,(1+k)/6).
>
> Setting the y component, (1+k)/6 equal to the y component of the Bezier
> direction point, which is just a = 0.5522847498, we get k = 2.313708499
>
> I use single Bezier spline segments quite a lot since I find the placement
> of the direction points at least partly intuitive.

It clicked!

The biggest barrier was that I was assuming the control points were tangent
vectors relative to the origin, rather than to the other points. Now that I've
been corrected, the math falls nicely into place.

The only thing that's still confusing is the factor of 3 in the conversion. I'll
assume that's just a minor detail due to the form of the equations, and not
worry about it.

Thanks very much for the clarity!


Post a reply to this message

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