# How to color TriSurf faces ?

조회 수: 61 (최근 30일)
Dr. Seis 2014년 12월 5일
댓글: Dr. Seis 2014년 12월 29일
So... I think I understand how each triangular surface gets colored, for example:
% Pretend X, Y, and Z defined above
Tri = delaunay(X,Y);
C = Z;
trisurf(Tri,X,Y,Z,C)
However, it doesn't make sense (to me) why to require C to be the same size as X, Y, or Z. It would make more sense (to me) to write the trisurf function such that the C vector be the same length as Tri so that each face (i.e., defined by the indices in each row of Tri) can be colored according to some property of that specific face (e.g., the dip angle or dip direction of the face)?
Is there a work-around I am not aware of to get the desired effect? Or do I need to make my own copy of the TriSurf function and modify from there?

댓글을 달려면 로그인하십시오.

### 채택된 답변

Dr. Seis 2014년 12월 8일
편집: Dr. Seis 2014년 12월 8일
There is a way to get the desired effect without modifying TriSurf function, using above example:
% Pretend X, Y, and Z defined above
Tri = delaunay(X,Y);
% Pretend function TriDip exists that takes X,Y,Z and Tri(angulation) info &
% returns a column vector (same length as Tri) with angle of dip for each triangle
% patch defined by each row of Tri (i.e., vertex indices of single triangle patch)
C_Tri = TriDip(X,Y,Z,Tri);
hh = trisurf(Tri,X,Y,Z);
% Additional bit to control color of each patch individually
set(gca,'CLim',[min(C_Tri), max(C_Tri)]);
set(hh,'FaceColor','flat',...
'FaceVertexCData',C_Tri,...
'CDataMapping','scaled');
I borrowed the above bits from the Matlab help page for patch (which I wasn't aware of when I posted this question). A lot more helpful coloring options for patch type objects are available on that page, too.
{RANT} Even though this work-around example is available to get the desired effect, I still do not get why the default usage of this function should expect that the C vector should be the same length/size as X, Y, or Z. Why would someone (the majority of the time) want to color the patch surface according to a value associated with one of its three vertices? [Still not clear what one of three vertices is used to identify how patch gets colored.] Seems (to me) to be a much harder way of controlling the property each face gets colored with. {/RANT}
Hopefully someone that knows more than I can clarify.

댓글을 달려면 로그인하십시오.

### 추가 답변 (1개)

Darin 2014년 12월 20일
RE RANT: It all depends on what you are trying to do. One of the most common applications of triangulation is to connect sparse/irregular samples of a continuous function (well water depth, for example) into a surface, which is more convenient with the default behavior. In that case, you can think of the color at the vertices as the sampled value of the function. trisurf with 'Edgecolor', 'none', 'facecolor', 'interp' gives about as credible a version of the raw data as is available. When the points aren't too close together, it can be useful to overlay a plot of dots at the sample points. You could, of course, interpolate the data to a fixed grid (interp2) or form a gridded surface with gridfit to beat down sampling errors, but neither will preserve the full fidelity of the raw samples in a way that scales as you zoom in, which trisurf will. All that said, any default can be a problem when you are trying to do something else. Ergo, options... which might be a bit lacking for your desires.
Curious: What is it you are doing that the Cvalue is a characteristic of the surface, rather than of the verticies (as above)? Depending on the answer, you might be able to use the vornoi diagram dual, which has a vertex to the circumcneter of each face, and triangulates those. In essence, you could interpolate from face to face, rather than from vertex to vertex. This does lose information about the face edges, so it may or may not be suitable for your needs.
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
Dr. Seis 2014년 12월 29일
Hi Darin, I am doing what I gave as an example in my answer above - trying to plot the dip angle & dip direction onto the face of each Delaunay triangle. My answer above solves my problem, so no need to go into different methods (for now).

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Polygons에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by