3

我有以下数据:

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)]);

3d模型

是否可以获得z给定x,y值的高度(值)?

4

2 回答 2

2

好的,我想说这可以很容易地使用TriScatteredInterp()on完成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');

...这是代码产生的数字:

简单建筑的网格。

于 2012-12-07T22:09:23.677 回答
0

快速通用方式:

尝试Data Cursor图形窗口工具栏中的选项。

而且,如果您想以编程方式执行此操作,请点击此链接

于 2012-12-07T20:11:55.273 回答