使用cesiumjs画了一个立方体,在立方体里增加了一根倾斜的柱子。但是我想要这个柱子的弯曲部分是在下面。直的部分在上面,就是现在的效果反转过来。试了将数组反转,不行。还有没有其他办法了。以下是代码:
this.height = Math.abs(this.maxZ - this.minZ); // 计算立方体的高度
const position = Cesium.Cartesian3.fromDegrees(this.resultPoints[0][0][0], this.resultPoints[0][0][1], 0); // 设置立方体的位置,顶部为0米(地面)
const dimensions = new Cesium.Cartesian3(4000, 2000, this.height); // 设置立方体的长、宽、高(单位:米)
const customColor = new Cesium.Color(0.0, 1.9, 0.0, 0.0);
// 立方体
const entity = this.viewer.entities.add({
position: position,
box: {
dimensions: dimensions,
material: Cesium.Color.GREEN.withAlpha(0.5),
outline: true,
outlineColor: customColor,
heightReference: Cesium.HeightReference.RELATIVE_TO_GROUND
}
});
// 设置立方体底部0米到400米为红色
const redBoxPosition = Cesium.Cartesian3.fromDegrees(this.resultPoints[0][0][0], this.resultPoints[0][0][1], 0); // 设置红色部分的位置,底部为0米,顶部为400米
const redBoxDimensions = new Cesium.Cartesian3(4000, 2000, 400); // 设置红色部分的长、宽、高(单位:米)
this.viewer.entities.add({
position: redBoxPosition,
box: {
dimensions: redBoxDimensions,
material: Cesium.Color.GHOSTWHITE.withAlpha(0.5),
heightReference: Cesium.HeightReference.RELATIVE_TO_GROUND
}
});
var resultPoints = [
[115.26323062877529, 35.681207787016405, 3059.986815], // 地面
[115.2638059522679, 35.67938304240898, 2678.59475],
[115.26403347831253, 35.678906718443876, 1000], // 顶端
];
resultPoints.reverse();
for (let i = 0; i < resultPoints.length - 1; i++) {
const points = [resultPoints[i], resultPoints[i + 1]];
this.createSlopedCylinder(points);
}
createSlopedCylinder(coords) {
const positions = coords.map(coord => Cesium.Cartesian3.fromDegrees(coord[0], coord[1], coord[2]));
this.viewer.entities.add({
name: 'Sloped Cylinder',
polylineVolume: {
length: 2059.986815,
positions: positions,
shape: this.computeCircle(20), // 增加柱子的直径
material: Cesium.Color.RED.withAlpha(0.5),
outline: true,
outlineColor: Cesium.Color.RED,
}
});
},
computeCircle(radius) {
const positions = [];
for (let i = 0; i < 360; i++) {
const radians = Cesium.Math.toRadians(i);
positions.push(new Cesium.Cartesian2(Math.cos(radians) * radius, Math.sin(radians) * radius));
}
return positions;
},