How to create 3D block graphic?

11 次查看(过去 30 天)
Reuben
Reuben 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