필터 지우기
필터 지우기

How to create 3D block graphic?

조회 수: 10 (최근 30일)
Reuben
Reuben 2016년 3월 3일
답변: Mike Garrity 2016년 3월 3일
In one of my classes we are obtaining accelerometer and magnetometer data from an iphone app, importing it into Matlab, and then plotting the angles between the x,y, and z axis in space to obtain real time data of the phone orientation.
Therefore, I have angles for each time interval. For fun, I want to make a 3D simulation instead of just viewing a plot of the angles vs. time.
More specifically, I am looking to create a block (the size of an iphone) in 3D space and then based on the input data for each time instance, see the block rotate in real time.
This way I can visually confirm that the movements I have made with my phone correspond to the MATLAB simulation with the data.
In order to do this, I would need some way to specify the angle with respect to each axis and have the graphics update at every time interval. I have no MATLAB graphic coding experience. Can anyone help?
Thanks.

답변 (1개)

Mike Garrity
Mike Garrity 2016년 3월 3일
This should give you some ideas on where to start:
w = 2;
h = 5;
d = 1/4;
verts = [-w -h -d; ...
w -h -d; ...
-w h -d; ...
w h -d; ...
-w -h d; ...
w -h d; ...
-w h d; ...
w h d];
faces = [3 4 8 7; ...
4 2 6 8; ...
2 1 5 6; ...
1 3 7 5; ...
7 8 6 5; ...
1 2 4 3];
g = hgtransform;
patch('Vertices',verts,'Faces',faces,'FaceColor',[.75 .75 .75],'Parent',g)
view(3)
box on
axis vis3d
daspect([1 1 1])
for x=linspace(0,2*pi,50)
for y=linspace(0,2*pi,50)
for z=linspace(0,2*pi,50)
g.Matrix = makehgtform('xrotate',x,'yrotate',y,'zrotate',z);
drawnow
end
end
end

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by