How to create 3D block graphic?

13 visualizaciones (últimos 30 días)
Reuben
Reuben el 3 de Mzo. de 2016
Respondida: Mike Garrity el 3 de Mzo. de 2016
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.

Respuestas (1)

Mike Garrity
Mike Garrity el 3 de Mzo. de 2016
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

Categorías

Más información sobre MATLAB Mobile en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by