Mesh plot of data over a parallelogram grid

조회 수: 13 (최근 30일)
Saavanth Velury
Saavanth Velury 2018년 10월 8일
편집: Nitin Phadkule 2021년 9월 18일
I have a two-dimensional array of numerical values that I am able to create a mesh plot of over a rectangular grid. However, I need a mesh plot of this data over a parallelogram grid instead. The vectors I would like to use to generate this parallelogram are a1 = (1/2,sqrt(3)/2) and a2 = (1/2,-sqrt(3)/2). Is there a way to do this easily? Thank you!

답변 (2개)

KSSV
KSSV 2018년 10월 8일
% Coordinates of parallelogram
P0 = [0. 0.] ; P1 = [1. 0.5] ;
P2 = [0 1] ; P3 = [1. 1.5] ;
C = [P0 ;P1 ; P3 ; P2 ; P0] ;
figure
patch(C(:,1),C(:,2),'b')
M = 50 ;
t = linspace(0,1,M) ;
% generate grid
L1 = [P0(1)+(P1(1)-P0(1))*t ; P0(2)+(P1(2)-P0(2))*t] ;
L2 = [P2(1)+(P3(1)-P2(1))*t ; P2(2)+(P3(2)-P2(2))*t] ;
% Mesh
N = 20 ;
X = zeros(M,N) ;
Y = zeros(M,N) ;
t = linspace(0,1,N) ;
for i = 1:M
X(i,:) = L1(1,i)+(L2(1,i)-L1(1,i))*t ;
Y(i,:) = L1(2,i)+(L2(2,i)-L1(2,i))*t ;
end
figure
hold on
plot(X,Y,'r')
plot(X',Y','r')
  댓글 수: 1
rui Zeng
rui Zeng 2020년 8월 10일
Thank you KSSV, and by using this method we can extend further to connecting irregular shapes by adding more columns for L1 and L2.

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


Nitin Phadkule
Nitin Phadkule 2021년 9월 18일
편집: Nitin Phadkule 2021년 9월 18일
% just sharing if any one needed for 3d points
% filling parallogram between two position vectors,
% can also an be used to plot and find area of vector addition triangle with
% ommision of x3, y3, z3
% p1=[x1 y1 z1]
% p2=[x2 y2 z2]
% P1+p2=[x1+x2 y1+y2 z1+z2]
p1=[1 -2 3]
p1 = 1×3
1 -2 3
p2=[2 2 0]
p2 = 1×3
2 2 0
x3=p1(1)+p2(1)%x1+x2
x3 = 3
y3=p1(2)+p2(2)%y1+y2
y3 = 0
z3=p1(3)+p2(3)%z1+z2
z3 = 3
patch( [0 p1(1) x3 p2(1) ], [0 p1(2) y3 p2(2) ], [0 p1(3) z3 p2(3) ],[1 0 .1] ,'FaceAlpha',.5,'EdgeColor','none')

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by