Quantcast
Channel: Math.NET Numerics - Math.NET
Viewing all articles
Browse latest Browse all 224

Cubic-spline interpolator to fit osculating circles

$
0
0

@DavidRutten wrote:

Initially posted this on StackOverflow... but not sure if that was a good idea.


How does one go about calculating the proper n-th order coefficients for a Math.NET cubic spline such that a collection of sorted circles become osculating circles?

The image below shows what I've got so far:

  • Crimson dots are the interpolation points (already sorted left to right).
  • Teal dots are the associated circle centre points.
  • Black dashes are the implied osculating circles.
  • Orange curve is the (wrong) cubic I'm getting right now (though it seems to be correct just to the right of each crimson dot).

enter image description here

The x array needs to have one more element than the c0, c1, etc. arrays, and I don't know what extra value to put in. Plus I have no idea whether my second order coefficients are correct, let alone what the third order coefficients are supposed to be.

Code from screenshot (with osculating spelled correctly):

public static CubicSpline OsculatingCubic(Point3d[] points, Point3d[] circles)
{
  double[] x = new double[points.Length + 1]; // How to deal with the +1?
  double[] c0 = new double[points.Length];
  double[] c1 = new double[points.Length];
  double[] c2 = new double[points.Length];
  double[] c3 = new double[points.Length];

  for (int i = 0; i < points.Length; i++)
  {
    x[i] = points[i].X;

    Vector3d tan = circles[i] - points[i];
    tan.Rotate(0.5 * Math.PI, Vector3d.ZAxis);
    if (tan.X < 0)
      tan.Reverse();

    c0[i] = points[i].Y;
    c1[i] = tan.Y / Math.Max(tan.X, 1e-32);
    c2[i] = 1.0 / (points[i].DistanceTo(circles[i]));
    if (circles[i].Y < points[i].Y)
      c2[i] = -c2[i];

    c3[i] = 0; // What should the third order coefficient be?
  }
  x[x.Length - 1] = x[x.Length - 2] + 1; // This cannot be right.

  return new CubicSpline(x, c0, c1, c2, c3);
}

Posts: 4

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 224

Trending Articles