MATLAB Answers

Adding imported image as texture to 2D patch

조회 수: 5(최근 30일)
Noam Azulay
Noam Azulay 2021년 7월 19일
댓글: Noam Azulay 2021년 7월 29일
Hello,
I have these x,y,z coordinates to create a circular sector (pizza slice shape):
theta=7*pi/18:pi/40:28*pi/45;
x=[1.8235 0.172*cos(theta)+1.8235 1.8235];
y=[0.75 0.172*sin(theta)+0.75 0.75];
z=3*ones(1,12);
I have an imported image (jpg/png) and I want it to appear on this patch. An image of an example of what I mean is attached here.
How can this be done?
I read about the function "imread", and the use of the "surface" function, but didn't manage to accomplish what I am aiming for.

채택된 답변

Harikrishnan Balachandran Nair
Harikrishnan Balachandran Nair 2021년 7월 28일
From my Understanding, you are having an issue in adding an imported image as texture to a circular sector. Using surf function allows you to add texture to your surface, by giving the imported image as the fourth input , and setting the ‘FaceColor’ Property to ‘texture’. To define a circular sector surface, you can calculate the points inside the sector and use it as the grid. You can refer to the following code.
k=0:pi/32:pi/4;
p=0:0.1:1;
X=ones(numel(k),numel(p));
Y=ones(numel(k),numel(p));
for i=1:numel(k)
for j=1:numel(p)
X(i,j)=p(j)*cos(k(i));
Y(i,j)=p(j)*sin(k(i));
end
end
Z=3*ones(numel(k),numel(p));
i=imread('image.jpg');
surf(X,Y,Z,i,'FaceColor','texture','EdgeColor','none');
  댓글 수: 1
Noam Azulay
Noam Azulay 2021년 7월 29일
Thank you! It worked perfectly

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

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by