需要解决的问题
- 根据(x,y,z) 点集得到其拟合函数
- 绘制三维曲面
- 在三维曲面上绘制指定的点
解决方案
函数拟合
使用MATLAB fitting curve tool中的多项式拟合解决函数拟合的需求
绘制三维曲面
采用ECharts GL实现B端的绘制,ECharts安装代码如下:
<script src="lib/echarts.min.js"></script>
<script src="lib/echarts-gl.min.js"></script>
使用ECharts提供的series-surface
,基础配置代码示例如下:
<script>
option = {
tooltip: {},
backgroundColor: '#fff',
visualMap: {
show: false,
min: -1,
max: 1,
inRange: {
color: ['#313695', '#4575b4', '#74add1', '#abd9e9', '#e0f3f8', '#ffffbf', '#fee090', '#fdae61', '#f46d43', '#d73027', '#a50026']
}
},
xAxis3D: {
type: 'value',
min: 1000,
max: 8000,
},
yAxis3D: {
type: 'value'
min: 30,
max: 80,
},
zAxis3D: {
type: 'value'
min: 0.6,
max: 1.0,
},
grid3D: {
viewControl: {
// projection: 'orthographic'
}
},
series: [{
type: 'surface',
wireframe: {
// show: false
},
equation: {
x: {
step: 500,
min: 1000,
max: 8000,
},
y: {
step: 50,
min: 30,
max: 80,
},
z: function (x, y) {
if (Math.abs(x) < 0.1 && Math.abs(y) < 0.1) {
return '-';
}
return Math.sin(x * Math.PI) * Math.sin(y * Math.PI);
}
}
}]
}
</script>
在三维曲面上绘制点
使用ECharts GL提供的series-scatter3D
,基础配置代码示例如下:
{
name: '工况点',
type: 'scatter3D',
symbol: 'pin',
symbolSize: 20,
zlevel: -9,
itemStyle: {
borderWidth: 1,
borderColor: '#000'
},
label: {
show: true,
// formatter: '{a}: {c}',
formatter: function (params) {
return params.seriesName +
'\n\nx:\t' + params.data[0] + '\tkW' +
'\ny:\t' + params.data[1] + '\tm' +
'\nz:\t' + params.data[2];
},
},
data: [[x, y, z]],
}