【问题标题】:How to plot a surface over a constrained domain?如何在受限域上绘制曲面?
【发布时间】:2019-11-18 03:38:05
【问题描述】:

我将如何绘制曲面:

z=(1+x^2)/(1+y^2) 覆盖区域|x|+|y|<=2 ?

我无法将曲面限制在菱形/正方形区域。

【问题讨论】:

标签: matlab plot 3d matlab-figure surface


【解决方案1】:

这是一个简单的例子:

% Create a grid in X and Y:
[XX,YY] = meshgrid(-2:0.01:2);

% Evaluate Z according to the equation:
ZZ = (1+XX.^2) ./ (1+YY.^2);

% Introduce constraints using NaN
XX( abs(XX) + abs(YY) > 2 ) = NaN;

% Plot:
figure(); surf(XX,YY,ZZ, 'EdgeColor','interp');

产生:

【讨论】:

    【解决方案2】:

    NaN 技巧不尊重域的真实边界(在建议的答案中,精细采样隐藏了边界的粗糙度)。最好是自己生成参数化曲面,像这样(我故意用大步来突出等参数曲线)

    % create a grid in the parameters domain
    [U,V] = meshgrid(-1:0.2:1);
    
    % compute actual (X,Y) values in the domain
    X = U-V;
    Y = U+V;
    
    % Evaluate Z according to the equation:
    Z = (1+X.^2) ./ (1+Y.^2);
    
    % Plot:
    figure(); surf(X,Y,Z, 'EdgeColor','interp');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-13
      • 2019-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-15
      相关资源
      最近更新 更多