how to merge 2D and 3D plots with desired positioning
이전 댓글 표시
Hi everybody. I have one 3d cylinder and one 2d circle. I want to plot them together the circle being the fundamental layer of cylinder at z=0. Thank's in advance. Here so far what I have, I can plot them separately. clear all; clc; close all;
P = imread('image.jpg');%
A = P(:,:,2); %select one channel
D = double(A(:,:)); %make it double
r=207;% the circle radius
k = size(D,2); %the z direction
t = 1:k;
theta=linspace(0,2*pi,size(D,1));
[time,angle]= meshgrid(t,theta);
x = r*cos(angle);
y = r*sin(angle);
c = D(:,:);
figure(1)
surface(x,y,time,c)% making cylinder
set(gcf,'Position',[0 0 400 700 ]);
view([-164,-26])
shading interp
sz=size(A); x2=633; y2=529; % center of region
[x1grid, y1grid] = meshgrid(1:sz(2), 1:sz(1));
x1 = x1grid - x2; % offset the origin y1 = y1grid - y2;
circlemask = x1.^2 + y1.^2 > r.^2;
% Use the mask to select part of the image
circle_image = double(A) .* circlemask-double(A);
hold all
figure(2) imagesc(circle_image);% circular part
shading interp
답변 (1개)
Hugo
2013년 7월 2일
0 개 추천
You can use surf as you did with the cylinder. You then might need to define the grid small enough and set the colours outside the circle as NaN instead of zero.
댓글 수: 4
Davit Hakobyan
2013년 7월 2일
Hugo
2013년 7월 2일
surf(x,y,z,c) x,y,z are the positions of the nodes of the grid and c are the colours. You need to specify 'EdgeColor','none', so that they are not drawn.
For moving the surface around, you just need to add a constant value to x, y or z. For rotations, you need to group the points in a 3D matrix and multiply by an appropriate rotation matrix. I suggest you to find what rotation matrices in 3D are in wikipedia if you don't know them, as it is much easier than explain that here.
Davit Hakobyan
2013년 7월 2일
Davit Hakobyan
2013년 7월 2일
카테고리
도움말 센터 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!