简体   繁体   English

如何在 MATLAB 中围绕一个点绘制立方体(3D 框)?

[英]How to draw a cube (3D box) around a point in MATLAB?

How can I draw a 3D bounding box around a 3D point in Matlab?如何在 Matlab 中围绕 3D 点绘制 3D 边界框? eg plotting a cube (15x15x15) around a 3D point (20,3,10);例如,围绕 3D 点 (20,3,10) 绘制立方体 (15x15x15); the point should be in inside and center of the cube.该点应位于立方体的内部和中心。

Do you want the six sides of the box to be semi-transparent?你想让盒子的六个面是半透明的吗? If so, you could use the following:如果是这样,您可以使用以下内容:

% Center point is at coordinate [ax ay az].
ax = 20;  ay = 3;  az = 10;

% Full-width of each side of cube.
w = 15;

% For readability.
h = w/2;

patch_args = { 'FaceColor', 'b', 'FaceAlpha', 0.3 };

% Side #1 of 6.
patch( 'XData', ax+[-h -h  h  h], 'YData', ay+[-h  h  h -h], 'ZData', az+[-h -h -h -h], patch_args{:} )
daspect( [1 1 1] )  % 1:1:1 aspect ratio.
hold on
% Side #2 of 6.
patch( 'XData', ax+[-h -h  h  h], 'YData', ay+[-h  h  h -h], 'ZData', az+[ h  h  h  h], patch_args{:} )
% Side #3 of 6.
patch( 'XData', ax+[-h -h  h  h], 'YData', ay+[ h  h  h  h], 'ZData', az+[-h  h  h -h], patch_args{:} )
% Side #4 of 6.
patch( 'XData', ax+[-h -h  h  h], 'YData', ay+[-h -h -h -h], 'ZData', az+[-h  h  h -h], patch_args{:} )
% Side #5 of 6.
patch( 'XData', ax+[ h  h  h  h], 'YData', ay+[-h -h  h  h], 'ZData', az+[-h  h  h -h], patch_args{:} )
% Side #6 of 6.
patch( 'XData', ax+[-h -h -h -h], 'YData', ay+[-h -h  h  h], 'ZData', az+[-h  h  h -h], patch_args{:} )

% Red dot in middle.
scatter3( ax, ay, az, 'or', 'filled', 'SizeData', 150 )

hold off

If instead you want the six sides to be completely transparent, you could repeat the code above but set FaceAlpha to 0.0 instead of 0.3相反,如果您希望六个面完全透明,您可以重复上面的代码,但将FaceAlpha设置为0.0而不是0.3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM