HermiteSpline doesn't work...

Hi!

I put this code in Hellow World examples of Cesium:

var polyline = new Cesium.Polyline();
   polyline.setPositions(ellipsoid.cartographicArrayToCartesianArray([
   Cesium.Cartographic.fromDegrees(-75.10, 39.57),
   Cesium.Cartographic.fromDegrees(-80.12, 25.46)
]));
primitives.add(polyline);

and doesn't work. I get the error:

TypeError: Object [object Object] has no method 'update' (on line 72)

71 function tick() {
72 scene.render();
73 Cesium.requestAnimationFrame(tick);
74 }

So I put it:

var polylines = new Cesium.PolylineCollection();
var polyline = polylines.add();
polyline.setPositions(ellipsoid.cartographicArrayToCartesianArray([
   Cesium.Cartographic.fromDegrees(-75.10, 39.57),
   Cesium.Cartographic.fromDegrees(-80.12, 25.46)
]));
primitives.add(polylines);

and works!

Now I want to creat a HermiteSpline:

var controlPoints = [
    {point: new Cesium.Cartesian3(1235398.0, -4810983.0, 4146266.0), time: 0.0},
    {point: new Cesium.Cartesian3(1372574.0, -5345182.0, 4606657.0), time: 1.5},
    {point: new Cesium.Cartesian3(-757983.0, -5542796.0, 4514323.0), time: 3.0},
    {point: new Cesium.Cartesian3(-2821260.0, -5248423.0, 4021290.0), time: 4.5},
    {point: new Cesium.Cartesian3(-2539788.0, -4724797.0, 3620093.0), time: 6.0}
];
var spline = new Cesium.HermiteSpline(controlPoints);

but I get the same error above :frowning:
Please, help me!

Hi,

Are you sure you are getting the same error? If so, do you have “var polyline = new Cesium.Polyline()” somewhere else instead of “var polylines = new Cesium.PolylineCollection()” and “var polyline = polylines.add()?”

Based on the tests, your HermiteSpline code looks good.

Patrick

“var polyline = new Cesium.Polyline()” doesn’t work anyway and “new Cesium.HermiteSpline()” neither.

I’m testing in Sandcastle of Cesium on my local address:
http://localhost/cesium/Apps/Sandcastle/index.html?src=Hello%20World.html

Thanks for respond! And sorry for my poor English…

Looks to me like we don’t have any visualizers for HermiteSpline. I know we can interpolate using them, but can we actually display one directly like a Polyline? I don’t see the code for that…

      --Ed.

You can display a Hermite spline by evaluating the spline at a given time. Here’s some example pseudo-code:

var controlPoints = [
{ point: point0, time: startTime },
{ point: point1, time: startTime + delta },
{ point: point2, time: startTime + 2.0 * delta },
{ point: point3, time: startTime + 3.0 * delta }


];
var spline = new HermiteSpline(controlPoints);

var positions = ;

for (var i = startTime; i < endTime; i += granularity) {

positions.push(spline.evaluate(i));

}

var polylines = new PolylineCollection();

var polyline = polylines.add();

polyline.setPositions(positions);

primitives.add(polylines);

The curve will become smoother as the granularity approaches zero.

-Dan

Thanks, Dan!

Now it works!