POV-Ray : Newsgroups : povray.object-collection : Sphere Sweep 1.2 Quadratic spline question : Re: Sphere Sweep 1.2 Quadratic spline question Server Time: 26 Oct 2020 13:40:05 GMT
  Re: Sphere Sweep 1.2 Quadratic spline question  
From: Cousin Ricky
Date: 31 Aug 2020 17:22:30
On 2020-08-30 8:04 PM (-4), Bald Eagle wrote:
> I'm using SphereSweep_Approx (SSWP_QUADRATIC_SPLINE ....)
> to draw some SVG data, and I noticed that the control point is intersected by
> the curve, whereas in SVG, they show the curve being inside of the convex hull
> of control points.
> Is this intentional behaviour of the macros?
> Am I doing something wrong, using it improperly?

SVG's quadratic curve uses 2nd order Bézier splines, while 
SSWP_QUADRATIC_SPLINE uses POV-Ray's built-in quadratic spline type, 
which connects the control points with parabolic curves.  They are two 
different spline types.

To get an SVG style quadratic curve, you would need to use 
SSWP_BEZIER_SPLINE, and clone the middle control point:

   SphereSweep_Approx
   ( SSWP_BEZIER_SPLINE,
     array { P1, P2, P2, P3 },
     array { Line, Line, Line, Line}, 100, 0
   )

Unfortunately, the Bézier algorithm in SphereSweep 1.2 does not handle 
such cloning properly.  You'll need to replace macro SSwp__Bezier_calc() 
in spheresweep.inc with the following:

----------[BEGIN CODE]----------
#macro SSwp__Bezier_calc (T, pv_Points, Radii, s_Macro)
   #local sswp_NPts = dimension_size (pv_Points, 1);
   #local sswp_Pt0 = floor (T / 4) * 4; // index of 1st point in segment
   #local sswp_T0 = (T - sswp_Pt0) / 3; // t, within segment
   #local sswp_T1 = 1 - sswp_T0; // 1 - t, within segment
   #if (sswp_T0 > 1 | T < 0 | T >= sswp_NPts)
     SSwp__Report
     ( s_Macro,
       concat
       ( "SSwp__Bezier_calc() was called with T = ", str (T, 0, -1),
         " for ", str (sswp_NPts, 0, 0), " points."
       )
     )
   #end
   #local sswp_MaxR = dimension_size (Radii, 1) - 1;
   #local sswp_Pt = <0,0,0>
   + pow (sswp_T1, 3) * pv_Points [sswp_Pt0]
   + 3 * pow (sswp_T1, 2) * sswp_T0 * pv_Points [sswp_Pt0+1]
   + 3 * sswp_T1 * pow (sswp_T0, 2) * pv_Points [sswp_Pt0+2]
   + pow (sswp_T0, 3) * pv_Points [sswp_Pt0+3];
   #local sswp_R =
     pow (sswp_T1, 3) * Radii [min (sswp_Pt0, sswp_MaxR)]
   + 3 * pow (sswp_T1, 2) * sswp_T0 * Radii [min (sswp_Pt0+1, sswp_MaxR)]
   + 3 * sswp_T1 * pow (sswp_T0, 2) * Radii [min (sswp_Pt0+2, sswp_MaxR)]
   + pow (sswp_T0, 3) * Radii [min (sswp_Pt0+3, sswp_MaxR)];
   <sswp_Pt.x, sswp_Pt.y, sswp_Pt.z, sswp_R>
#end
-----------[END CODE]-----------

> Would it be possible to have an additional, alternative quadratic spline added?

It is under consideration.  In any case, the Bézier algorithm patch will 
definitely be in the next update.

 > Thanks!   :)

No problem!


Post a reply to this message

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