필터 지우기
필터 지우기

Point array to generate meshgrid

조회 수: 4 (최근 30일)
Huiyuan Zheng
Huiyuan Zheng 2023년 12월 15일
편집: Huiyuan Zheng 2023년 12월 18일
I have a point array describing the equal-spacing points in a hexagon, how can I use this array to generate a meshgrid with identical points so that I can use pcolor?

답변 (2개)

Walter Roberson
Walter Roberson 2023년 12월 15일
Xu = uniquetol(X(:) );
Yu = uniquetol(Y(:) );
[Xg, Yg] = meshgid(Xu, Yu);
F = scatteredInterpolant(X(:), Y(:), Z(:)) ;
Zg = F(Xg, Yg);
pcolor(Xg, Yg, Zg);
  댓글 수: 3
Walter Roberson
Walter Roberson 2023년 12월 15일
The locations that are outside of the convex hull of the original points, will interpolate to NaN, and pcolor() displays NaN as transparent.
Huiyuan Zheng
Huiyuan Zheng 2023년 12월 18일
편집: Huiyuan Zheng 2023년 12월 18일
My point array is the points in the following code. While I try to put it in your code, I don't know the result.
I divide the point array into three sections with different orientations so that the hexagonal boudnaries are all smooth. However, the problem is that, there are three blank lines in between each sections. (I delete the boundary to avoid overcounting since the hexagon is a cell in a periodic function.)
q1 = [1/2;sqrt(3)/2]; % lattice vector 1
q2 = [1/2;-sqrt(3)/2]; % lattice vector 2
q3 = -(q1+q2); % the compensated vector
np = 100;
% delete one boundary to avoid repeating calculation
r1 = linspace(0,1,np+1); r1(end) = [];
r2 = linspace(0,1,np+1); r2(1) = [];
[R1,R2] = meshgrid(r1,r2);
section1 = [q2,q3]*[R1(:),R2(:)].';
section2 = [q3,q1]*[R1(:),R2(:)].';
section3 = [q1,q2]*[R1(:),R2(:)].';
points = [section1,section2,section3];
KX1 = reshape(section1(1,:),np,np);
KY1 = reshape(section1(2,:),np,np);
KX2 = reshape(section2(1,:),np,np);
KY2 = reshape(section2(2,:),np,np);
KX3 = reshape(section3(1,:),np,np);
KY3 = reshape(section3(2,:),np,np);
figure; hold on;
pcolor(KX1,KY1,KX1*0+1);
pcolor(KX2,KY2,KX2*0+2);
pcolor(KX3,KY3,KX3*0+3);
shading interp; axis equal;

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


Steven Lord
Steven Lord 2023년 12월 15일
I don't believe pcolor allows you to create elements with more or fewer than 4 sides. What I think you want to do is either create various patch objects or perhaps create an array of polyshape objects and use some of the object functions (rotate, scale, translate) to create an array of polyshape objects to plot.
H = nsidedpoly(6);
plot(H)
axis equal
H(2) = translate(H, 2, 0); % Now H has 2 hexagons
H(3:4) = translate(H, 0, 2); % Now it has 4, both of the previous two translated up 2 units
figure
plot(H)
axis equal
  댓글 수: 1
Huiyuan Zheng
Huiyuan Zheng 2023년 12월 18일
Yes, to plot a filled hexagon uses patch is enough, while what I need is a point array describing the the equal-spacing points inside a hexagon. As you said, it seems forbidden to use a create elements with more or fewer than 4 sides, so I divide it into three sections (you can find it in the discussion of the first answer):
Strictly speaking, I have another requirement, which is to avoid the overcounting the boundary since the hexagon is a cell in a periodic function. That's why I made those modifications in my code. However, the problem is, the pcolor of the three sections are not connected, there is a blank line in between.

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

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by