Cesium中的樣條插值
在cesium里,提供了三種樣條插值方法,LinearSpline,CatmullRomSpline,HermiteSpline。
在具體的實例上,可以使用樣條插值法利用已知的控制點,插值出一系列的點,用於平滑曲線,特別是在路徑的追朔重演。
下面,我們分別介紹這三種樣條插值的使用方法以及效果。
LinearSpline(線性樣條)
線性樣條從效果上看,是把所有控制點一一連線,並在連線上做定點取值
1、設置幾個控制點,並添加到場景中,聚焦視角
-
var controls = [
-
Cesium.Cartesian3.fromDegrees( 110, 10),
-
Cesium.Cartesian3.fromDegrees( 111, 11),
-
Cesium.Cartesian3.fromDegrees( 112, 9),
-
Cesium.Cartesian3.fromDegrees( 114, 10),
-
Cesium.Cartesian3.fromDegrees( 113, 8)
-
];
-
for (var i = 0; i < controls.length; i++) {
-
viewer.entities. add({
-
position: controls[i],
-
point: {
-
color: Cesium.Color.RED,
-
pixelSize: 10
-
}
-
});
-
}
-
viewer.zoomTo(viewer.entities);
2、創建LinearSpline對象
-
var spline = new Cesium.LinearSpline({
-
times: [0.0, 0.25, 0.5, 0.75, 1],
-
points: controls
-
});
3、插值100個點
-
var positions = [];
-
for (var i = 0; i <= 100; i++) {
-
var cartesian3 = spline.evaluate(i / 100);
-
positions.push(cartesian3);
-
viewer.entities. add({
-
position: cartesian3,
-
point: {
-
color: Cesium.Color.YELLOW,
-
pixelSize: 6
-
}
-
});
-
}
4、將插值所有的點繪制成線