How to create a secondary Cartesian coordinate system (three perpendicular coordinate axes) in Matlab?
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi, is it possible to create a secondary Cartesian coordinate system (i.e. the three mutually perpendicular coordinate axes) with origin at one of the three objects in this figure? If Yes, how? Any command or example?
0 commentaires
Réponse acceptée
Adam Danz
le 22 Août 2021
Modifié(e) : Adam Danz
le 23 Août 2021
To add the additional axis lines,
box on
% Or
box(ax, 'on') % ax is the axis handle
but I didn't understand this part: with origin at one of the three objects
Update
figure()
tiledlayout(1,2,'padding','none')
ax1 = nexttile;
xyz = [.5, .5, .5];
plot3(ax1, xyz(1), xyz(2), xyz(3), 'o', 'MarkerSize', 14)
grid(ax1, 'on')
axis(ax1, 'equal')
xlim(ax1, [0,1])
ylim(ax1, [0,1])
zlim(ax1, [0,1])
ax1.XRuler.FirstCrossoverValue = xyz(2); % y
ax1.XRuler.SecondCrossoverValue = xyz(3); % z
ax1.YRuler.FirstCrossoverValue = xyz(1); % x
ax1.YRuler.SecondCrossoverValue = xyz(3); % z
ax1.ZRuler.FirstCrossoverValue = xyz(1); % x
ax1.ZRuler.SecondCrossoverValue = xyz(2); % y
% Axis labels will also move with the axes
% xlabel(ax1, 'X axis')
% ylabel(ax1, 'Y axis')
% zlabel(ax1, 'Z axis')
title(ax1, 'Origin at xyz coordinate')
ax2 = nexttile;
xyz = [.5, .5, .5];
plot3(ax2, xyz(1), xyz(2), xyz(3), 'o', 'MarkerSize', 14)
grid(ax2, 'on')
axis(ax2, 'equal')
xlim(ax2, [0,1])
ylim(ax2, [0,1])
zlim(ax2, [0,1])
ax2.XRuler.FirstCrossoverValue = xyz(2); % y
ax2.YRuler.FirstCrossoverValue = xyz(1); % x
ax2.ZRuler.FirstCrossoverValue = xyz(1); % x
ax2.ZRuler.SecondCrossoverValue = xyz(2); % y
title(ax2, 'Origin on XY plane')
% Axis labels will also move with the axes
% xlabel(ax2, 'X axis')
% ylabel(ax2, 'Y axis')
% zlabel(ax2, 'Z axis')
If all you're looking for is reference lines without the ticks, you can use xline() and yline() to add the x and y ref lines. There is no zline() so you'll have to use plot3 something related. Note that xline and yline lines will update when the axis limits change but that won't happen with the plot3 line. Also note that the xline and yline lines are partially transparent by default. You can set the alpha levels to 1 to remove transparency or you can set the transparency of the z-line to match the x & y lines by adding a 4th value to the RGB color (ie, set(..., 'Color', [0 0 0 .4]))
figure()
ax = gca();
xyz = [.5, .5, .5];
plot3(ax, xyz(1), xyz(2), xyz(3), 'o', 'MarkerSize', 14)
grid(ax, 'on')
axis equal
xlim(ax, [0,1])
ylim(ax, [0,1])
zlim(ax, [0,1])
xline(ax, xyz(1), 'k--', 'XAxis') % see xline properties to control label placement
yline(ax, xyz(2), 'k--', 'YAxis')
hold(ax,'on')
plot3(ax, xyz([1,1]), xyz([2,2]), zlim(ax), 'k--')
title(ax, 'line objects')
5 commentaires
Adam Danz
le 22 Août 2021
No problem.
I just added another example of the crossover approach with the x and y axis lines along the XY plane.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Axes Appearance dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!