如何在Matlab中围绕3D点绘制3D边界框?例如在3D点(20,3,10)周围绘制立方体(15x15x15);该点应位于立方体的内部和中心。
答案 0 :(得分:0)
你想盒子的六边是半透明的吗?如果是这样,您可以使用以下内容:
% 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
如果你希望六面完全透明,你可以重复上面的代码,但将FaceAlpha
设置为0.0
而不是0.3