POV-Ray : Newsgroups : povray.general : Cubic spline tangents don't have expected effect? : Re: Cubic spline tangents don't have expected effect? Server Time
17 Jun 2024 05:00:58 EDT (-0400)
  Re: Cubic spline tangents don't have expected effect?  
From: kendfrey
Date: 17 Jan 2019 13: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-2023 Persistence of Vision Raytracer Pty. Ltd.