Processing math: 100%
TecnoStats

Interpolating arbitrary points in 2D and 3D


Introduction

Along this section, we are going to build interpolation curves, based on cubic splines, passing through a set of arbitrary points spread in space.

First step is to load package interpol,

load("interpol")$

Since we want to show graphical results with the VTK graphics library, let us also load package draw and set the corresponding draw renderer,

load("draw") $
draw_renderer: vtk $

Interpolation in 2D

Generate a set of n = 5 random points,

n: 5 $
p: makelist(makelist(random(10),2), n);

[[9,0],[9,4],[7,6],[9,9],[3,9]]

Extract the x coordinates and interpolate them by cubic splines,

cs1: cspline(map(first,p), varname=t);

(27t328+81t22827t14+9)charfun2(t,,2)+(69t3281035t228+2469t1418397)charfun2(t,4,)+(121t328+1245t2282091t14+12017)charfun2(t,3,4)+(79t328555t228+87t21497)charfun2(t,2,3)

Function charfun_2 returns 1 if the first argument belongs to the interval defined by the other two arguments.

Now, the same procedure with the y coordinates

cs2: cspline(map(second,p), varname=t);

(37t356+111t256+75t284)charfun2(t,,2)+(51t356765t256+1887t287027)charfun2(t,4,)+(87t356+891t2561425t28+4027)charfun2(t,3,4)+(73t356549t256+105t41387)charfun2(t,2,3)

Let's plot our results,

draw2d(
  point_type = circle,
  points(p),
  nticks     = 70,
  color      = red,
  parametric(cs1,cs2, t, 1, n)) $
gr1

If we want to interpolate at t=2.5,

ev([cs1,cs2], t=2.5);

[7.665178571428569,5.006696428571427]

Interpolation in 3D

Just as in the 2D example, let Maxima generate n = 5 random points in the three dimensional world,

n: 5 $
p: makelist(makelist(random(10),3), n);

[[2,2,4],[5,4,1],[9,5,8],[3,5,5],[0,6,9]]

Extract the x, y, and z coordinates,

cs1: cspline(map(first,p),varname=t) $
cs2: cspline(map(second,p),varname=t) $
cs3: cspline(map(third,p),varname=t) $

Plot the parametric curve passing through the random points,

draw3d(
  point_type = sphere,
  point_size = 0.5,
  points(p),
  line_type  = tube,
  color      = yellow,
  line_width = 0.1,
  parametric(cs1,cs2,cs3, t, 1, 5)) $
gr2

Interpolation at t=2.5,

ev([cs1,cs2,cs3], t=2.5);

[7.790178571428569,4.674107142857142,4.707589285714292]


© 2016, TecnoStats.