MATLAB Answers

fill/patch for a piecewise-linear closed contour/polygon

12 ビュー (過去 30 日間)
Ilya 2014 年 2 月 10 日
編集済み: Ilya 2014 年 2 月 11 日
I've tried to use the function fill(X,Y,C) with the set of data specified in the attached m-file (contour_draft.m). The data (XY coordinates) represents a piecewise-linear closed contour, that can be also considered as a polygon with very many sides (since every point can be considered as a polygon vertex, if the points don't lie on the same line).
The contour has three "sides". The two straight lines are in the bottom left, and one "curve" spans from bottom left to the upper right corner of the figure. The joint points of any side with other sides (shown in green) are present in the XY-coordinates of any two adjacent sides (i.e. any two adjacent sides have their common point in their XY-coordinates lists). Then the XY-coordinates of the sides were concantenated in the correct order (i.e. green vertex to green vertex), but somehow the fill-funtion prefers to fill a triangle instead of the full contour.
Is there a way to enforce fill() (or patch()) to fill the whole contour?


Ilya 2014 年 2 月 11 日
編集済み: Ilya 2014 年 2 月 11 日
Yes, in fact, if a piecewise-linear contour is defined properly (i.e. the sides' points coordinates vectors are concatenated at the common vertices, and the beginning coordinates in the total coordinates' array are equal to the end coordinates), it can be filled with no problem.
I've generated false data in the beginning.
The correct operation is shown below:
The file with the correct coordinates array is also attached.

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2014 年 2 月 10 日
If you can put all the vertices together in a patch() then you can set the FaceColor property of the patch in order to fill it.
  2 件のコメント
Walter Roberson
Walter Roberson 2014 年 2 月 10 日
Questions should be left in place; a "It was a problem with my data" answer is fine it that proves to be the case.


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by