我有以下数据:
kx = 20;
ky = 20;
k = [kx ky];
PointsL = [
[ 32 0 0] % P1
[387 0 0]
[475 0 0]
[475 30 0]
[602 30 0] % P5
[602 220 0]
[475 220 0]
[475 737 0]
[387 737 0]
[ 32 737 0] % P10
[ 32 555 0]
[ 0 555 0]
[ 0 277 0]
[ 27 277 0]
[ 27 250 0] % P15
[ 0 250 0]
[ 0 57 0]
[ 32 57 0] % P18
];
PointsH = [
[ 32 0 270] % P1
[387 0 270]
[475 0 183]
[475 30 183]
[602 30 183] % P5
[602 220 183]
[475 220 183]
[475 737 183]
[387 737 270]
[ 32 737 270] % P10
[ 32 555 270]
[ 0 555 270]
[ 0 277 270]
[ 27 277 270]
[ 27 250 270] % P15
[ 0 250 270]
[ 0 57 270]
[ 32 57 270] % P18
];
PointsL
是下表面的点 - 全都是z=0
。
PointsH
是较高曲面的点 - 在z轴上可变。
所有这些都代表了房间点。
以下代码绘制3d模型:
plength = size(PointsL,1);
for i=1:plength
if i == 1
pl1 = PointsL(plength,:);
ph1 = PointsH(plength,:);
else
pl1 = PointsL(i-1,:);
ph1 = PointsH(i-1,:);
end
pl2 = PointsL(i,:);
ph2 = PointsH(i,:);
line([pl1(1) pl2(1)], [pl1(2) pl2(2)], [pl1(3) pl2(3)]);
line([ph1(1) ph2(1)], [ph1(2) ph2(2)], [ph1(3) ph2(3)]);
line([pl1(1) ph1(1)], [pl1(2) ph1(2)], [pl1(3) ph1(3)]);
end
p1 = PointsH(2,:);
p2 = PointsH(9,:);
line([p1(1) p2(1)], [p1(2) p2(2)], [p1(3) p2(3)]);
p1 = PointsH(4,:);
p2 = PointsH(7,:);
line([p1(1) p2(1)], [p1(2) p2(2)], [p1(3) p2(3)]);
是否可以获得给定z
值的高度(x,y
值)?
答案 0 :(得分:2)
好的,我想说可以使用TriScatteredInterp()
上的PointsH
轻松完成。我意识到让它产生我想要的东西并不那么简单。我求助于添加额外的点并移动它们以创建正确的插值三角形。
我终于得到了一些可以产生对应于点(a,b)的z值的东西。
这是我最终做的......
epsilon = 1e-8;
PointsL_diff = epsilon*[
[ -1 0 0] % P1
[ 0 -1 0]
[ 0 -1 0]
[ 1 0 0]
[ 0 -1 0] % added
[ 1 -1 0]
[ 1 0 0] % P5
[ 0 -1 0]
[ 1 1 0]
[ 1 1 0]
[ 0 1 0]
[ 1 0 0] % added
[ 0 1 0]
[ -1 0 0] % P10
[ 0 1 0] % added
[ -1 1 0]
[ -1 1 0]
[ -1 0 0]
[ 0 -1 0] % added
[ -1 -1 0]
[ -1 1 0] % P15
[ -1 0 0]
[ 0 1 0] % added
[ -1 -1 0]
[ -1 -1 0] % P18
];
PointsL = [
[ 32 0 0] % P1
[ 32 0 0] % added
[387 0 0]
[475 0 0]
[475 0 0] % added
[475 30 0]
[602 30 0] % P5
[602 30 0] % added
[602 220 0]
[475 220 0]
[475 737 0]
[475 737 0] % added
[387 737 0]
[ 32 737 0] % P10
[ 32 737 0] % added
[ 32 555 0]
[ 0 555 0]
[ 0 277 0]
[ 0 277 0] % added
[ 27 277 0]
[ 27 250 0] % P15
[ 0 250 0]
[ 0 250 0] % added
[ 0 57 0]
[ 32 57 0] % P18
];
PointsH = [
[ 32 0 270] % P1
[387 0 270]
[475 0 183]
[475 30 183]
[602 30 183] % P5
[602 220 183]
[475 220 183]
[475+epsilon 220 183] % added
[475 220+epsilon 183] % added
[475 737 183]
[387 737 270]
[387 220 270] % added
[ 32 737 270] % P10
[ 32 555 270]
[ 0 555 270]
[ 0 277 270]
[ 27 277 270]
[ 27 250 270] % P15
[ 0 250 270]
[ 0 57 270]
[ 32 57 270] % P18
];
% plot bounds
x_min = -200;
x_max = 800;
y_min = -200;
y_max = 800;
newPointsL = PointsL + PointsL_diff;
x = [PointsH(:,1); newPointsL(:,1); x_min; x_max; x_min; x_max];
y = [PointsH(:,2); newPointsL(:,2); y_min; y_min; y_max; y_max];
z = [PointsH(:,3); newPointsL(:,3); 0; 0; 0; 0];
F = TriScatteredInterp(x,y,z); % default is linear interpolation
% find z-value for point (a,b)
a = 100;
b = 200;
z_value = F(a,b)
% generate mesh and plot surface
ti_x = x_min:10:x_max;
ti_y = y_min:10:y_max;
[qx,qy] = meshgrid(ti_x,ti_y);
qz = F(qx,qy);
mesh(qx,qy,qz);
hold on;
plot3(x,y,z,'o');
......这是代码产生的数字:
答案 1 :(得分:0)