









 
 




 
 


I'm trying to approximate a quartercircle 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/geometricmodeling/circlesplineapproximation.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 quartercircle 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 POVRay's "cubic" splines are close relatives
of the CatmullRom type.
Post a reply to this message


 
 




 
 


clipka <ano### [at] anonymousorg> wrote:
> POVRay's "cubic" splines are close relatives of the CatmullRom 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


 
 




 
 


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


 
 




 
 


"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 ((1t) + 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_1p_0 and p_3p_2.
The actual tangents are 3(p_1  p_0) and 3(p_3  p_2),
p(t) = (1t)^3xp_0 + 3(1t)^2txp_1 + 3(1t)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 CatmullRom spline sets the first direction point of an equivalent Bezier
spline at p_i to be p_i + (p_(i+1)  p_(i1))/6 (this sets the tangent
to be (p_(i+1)  p_(i1))/2 which is more believable) so the 4 points for
POVRay'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


 
 




 
 


"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 ((1t) + 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_1p_0 and p_3p_2.
> The actual tangents are 3(p_1  p_0) and 3(p_3  p_2),
>
> p(t) = (1t)^3xp_0 + 3(1t)^2txp_1 + 3(1t)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 CatmullRom spline sets the first direction point of an equivalent Bezier
> spline at p_i to be p_i + (p_(i+1)  p_(i1))/6 (this sets the tangent
> to be (p_(i+1)  p_(i1))/2 which is more believable) so the 4 points for
> POVRay'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


 
 




 

