Spline Curve Horizontal and Vertical Extent (Span, Bounding Rectangle)
©2006 Darel Rex Finley.  This complete article, unmodified, may be freely distributed for educational purposes.



spline curve extent

In this figure, we see a simple, three-point spline curve with hard corners Sx,Sy and Ex,Ey (black), and spline corner a,b (blue).  The grey rectangle represents the horizontal and vertical extent (bounding rect) of the curve.  In this particular case, the left and bottom coordinates of the rectangle are easy to find, but what about the top and right?

The math to solve this problem is simple, but deriving it is a time-consuming chore.  I'll leave the derivation for another day, but if you want to try it yourself, it's based on the formulas found in the polyspline page.  If you just need to find the extent of a spline curve in your own code, here's how:

double splineXMax(double Sx, double a, double Ex) {

  double  c=Sx-a, d=c+Ex-a, F, X, max=Sx ;

  if (Ex>Sx) max=Ex;
  if (d!=0.) {
    F=c/d;
    if (F>0. && F<1.) {
      X=Sx-c*F; if (X>max) max=X; }}

  return max; }



double splineXMin(double Sx, double a, double Ex) {

  double  c=Sx-a, d=c+Ex-a, F, X, min=Sx ;

  if (Ex<Sx) min=Ex;
  if (d!=0.) {
    F=c/d;
    if (F>0. && F<1.) {
      X=Sx-c*F; if (X<min) min=X; }}

  return min; }



double splineYMax(double Sy, double b, double Ey) {

  double  c=Sy-b, d=c+Ey-b, F, Y, max=Sy ;

  if (Ey>Sy) max=Ey;
  if (d!=0.) {
    F=c/d;
    if (F>0. && F<1.) {
      Y=Sy-c*F; if (Y>max) max=Y; }}

  return max; }



double splineYMin(double Sy, double b, double Ey) {

  double c=Sy-b, d=c+Ey-b, F, Y, min=Sy ;

  if (Ey<Sy) min=Ey;
  if (d!=0.) {
    F=c/d;
    if (F>0. && F<1.) {
      Y=Sy-c*F; if (Y<min) min=Y; }}

  return min; }


Send me an e-mail!

Does the brace style in the above code sample freak you out?  Click here to see it explained in a new window.

Quicksort  |  Point in polygon  |  Mouseover menus  |  Gyroscope  |  Osmosis  |  Polarizer experiment  |  Gravity table equilibrium  |  Calculus without calculus  | Overlapping maze