gpt4 book ai didi

algorithm - Matlab如何计算等高线?

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:30:10 25 4
gpt4 key购买 nike

Matlab 生成等高线的算法是什么?换句话说,它如何将网格上的关卡数据转换成一组线?

我想要的是:

  • 获取位于轮廓上的点的局部标准?
  • 捕获所有等高线的全局程序?

我不需要有关底层代码的详细细节,但一般原则将有助于我解释输出。我在我的研究中使用了 contour(和衍生物),并且想了解在这一步中引入的数值错误。

这看起来是一个非常简单的问题,但我在 Matlab 的文档中找不到解释,也没有在 SO 或网络上的其他地方找到任何内容。如果它毕竟很容易找到,我深表歉意。

最佳答案

来自 MATLAB® - Graphics - R2012a , 从第 5-73 页到第 5-76 页:

The Contouring Algorithm

The contourc function calculates the contour matrix for the other contour functions. It is a low-level function that is not called from the command line. The contouring algorithm first determines which contour levels to draw. If you specified the input vector v, the elements of v are the contour level values, and length(v) determines the number of contour levels generated. If you do not specify v, the algorithm chooses no more than 20 contour levels that are divisible by 2 or 5.

The height matrix Z has associated X and Y matrices that locate each value in Z at the intersection of a row and a column, or these matrices are inferred when they are unspecified. The row and column widths can vary, but typically they are constant (i.e., Z is a regular grid). Before calling contourc to interpolate contours, contourf pads the height matrix with an extra row or column on each edge. It assigns z-values to the added grid cells that are well below the minimum value of the matrix. The padded values enable contours to close at the matrix boundary so that they can be filled with color. When contourc creates the contour matrix, it replaces the x,y coordinates containing the low z-values with NaNs to prevent contour lines that pass along matrix edges from being displayed. This is why contour matrices returned by contourf sometimes contain NaN values. Set the current level, c, equal to the lowest contour level to be plotted within the range [min(Z) max(Z)]. The contouring algorithm checks each edge of every square in the grid to see if c is between the two z values for the edge points. If so, a contour at that level crosses the edge, and a linear interpolation is performed:

t=(c-Z0)/(Z1-Z0)

Z0 is the z value at one edge point, and Z1 is the z value at the other edge point.

Start indexing a new contour line (i=1) for level c by interpolating x and y:

cx(i) = X0+t*(X1-X0)
cy(i) = Y0+t*(Y1-Y0)

Walk around the edges of the square just entered; the contour exits at the next edge with z values that bracket c. Increment i, compute t for the edge, and then compute cx(i) and cy(i), as above. Mark the square as having been visited. Keep checking the edges of each square entered to determine the exit edge until the line(cx,cy) closes on its initial point or exits the grid. If the square being entered is already marked, the contour line closes there. Copy cx, cy, c, and i to the contour line data structure (the matrix returned by contouring functions, described shortly).

Reinitialize cx, cy, and i. Move to an unmarked square and test its edges for intersections; when you find one at level c, repeat the preceding operations. Any number of contour lines can exist for a given level. Clear all the markers, increment the contour level, and repeat until c exceeds max(Z). Extra logic is needed for squares where a contour passes through all four edges (saddle points) to determine which pairs of edges to connect. contour, contour3, and contourf return a two-row matrix that specifies all the contour lines:

C = [ value1 xdata(1) xdata(2)...
numv ydata(1) ydata(2)...]

The first row of the column that begins each definition of a contour line contains the contour value, as specified by v and used by clabel. Beneath that value is the number of (x,y) vertices in the contour line. Remaining columns contain the data for the (x,y) pairs. For example, the contour matrix calculated by C = contour(peaks(3)) is as follows.

enter image description here

The circled values begin each definition of a contour line.

关于algorithm - Matlab如何计算等高线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39274728/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com