필터 지우기
필터 지우기

How to display the coordinate system of the figure (UCS icon)?

조회 수: 20 (최근 30일)
yu sh
yu sh 2016년 9월 6일
답변: George Abrahams 2024년 3월 20일
I have a 3D object having irregular shape and volume changing along the axes direction. I want to show the coordinate system icon in the figure associated with that object so that when I will rotate the object it will also change,like available in different CAD/CAE systems. How can I get this in MATLAB?
  댓글 수: 2
Henry Giddens
Henry Giddens 2016년 9월 6일
I normally plot this myself in the corner of the axis using the 'line' and 'text' functions. As long as you use these, and not the annotation, then they will rotate with the associated axis. You wont have the arrowheads however.
I don't know whether it can just be turned on but I have never come across it.
yu sh
yu sh 2016년 9월 6일
Thanks Henry I don't need arrowheads, do you have a written code for it?

댓글을 달려면 로그인하십시오.

채택된 답변

Henry Giddens
Henry Giddens 2016년 9월 6일
편집: Henry Giddens 2016년 9월 9일
Hi yu, Yes I have done it a few times. You should be aware that this will work for me because the scale on each axis is equal. For example:
%before this you have plotted a surface in axis hAx
axis(hAx,'equal')
%Get X, Y and Z data for plotting the axes...
X_range = hAx.XLim(2) - hAx.XLim(1);
X_start = hAx.XLim(1);
X_delta = X_range/20;
Y_delta = (hAx.YLim(2) - hAx.YLim(1))/20;
Y_start = hAx.YLim(1);
Z_delta = (hAx.ZLim(2) - hAx.ZLim(1))/20;
Z_start = hAx.ZLim(1);
X_Line = line(hAx,[X_start+X_delta X_start+X_delta*5],[Y_start+Y_delta Y_start+Y_delta],[Z_start+Z_delta Z_start+Z_delta]); % x Line
Y_Line = line(hAx,[X_start+X_delta X_start+X_delta],[Y_start+Y_delta Y_start+Y_delta*5],[Z_start+Z_delta Z_start+Z_delta]); % Y Line
Z_Line = line(hAx,[X_start+X_delta X_start+X_delta],[Y_start+Y_delta Y_start+Y_delta],[Z_start+Z_delta Z_start+Z_delta*5]); %Z Line
X_text = text(hAx,X_start+X_delta*6,Y_start+Y_delta,Z_start+Z_delta,'x');
Y_text = text(hAx,X_start+X_delta,Y_start+Y_delta*6,Z_start+Z_delta,'y');
Z_text = text(hAx,X_start+X_delta,Y_start+Y_delta,Z_start+Z_delta*6,'z');
You can then play around with how long you want each line, the colors of the lines and text etc... I tend to use linkprop to link the properties of the lines that need to stay the same. If you do not have equal axis scales, this method wont really work...
Henry
  댓글 수: 11
yu sh
yu sh 2016년 9월 9일
Its finally working Henry! I have just removed 'hAx' from the text function and it works perfect. Thanks again it is of great for me. Btw my version is 2015a.
Divin Xavier
Divin Xavier 2021년 1월 8일
편집: Divin Xavier 2021년 1월 8일
Instead of Line command you could use annotation to get the arrow heads (version 2020b)
X_Line = annotation('textarrow',[X_start+X_delta X_start+X_delta*1.5],[Y_start+Y_delta Y_start+Y_delta],'Color','k'); % x Line
Y_Line = annotation('textarrow',[X_start+X_delta X_start+X_delta],[Y_start+Y_delta Y_start+Y_delta*1.5],'Color','k'); % Y Line

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

George Abrahams
George Abrahams 2024년 3월 20일
Heres what I think is a pretty nice solution. The coordinate system bases (arrows) are plotted with my plotframe function on File Exchange.
% The main axes containing the object or data of interest.
axObj = axes;
[ X, Y, Z ] = peaks( 25 );
mesh( axObj, X, Y, Z ./ 3 )
% The small, corner axes containing the coordinate system plot.
axIcon = axes( Position=[0.75 0.75 0.2 0.2] );
plotframe( Parent=axIcon, LabelBasis=true )
% Synchronise the axes cameras.
linkprop( [axObj axIcon], [ "View", "CameraUpVector" ] );
% Some beautification.
set( gcf, Color=axObj.Color )
set( axIcon, CameraViewAngleMode="manual", ...
Color="none", XColor="none", YColor="none", ZColor="none" )
set( [axObj axIcon], DataAspectRatio=[1 1 1], PlotBoxAspectRatio=[1 1 1], View=[50 30] )

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by