% Cartesian Coordinates
% 2021/11/22 by T. Hirano
clear; clc;
%
fig = figure;
hold on;
xmin=-2; xmax=2;
ymin=-2; ymax=2;
zmin=-2; zmax=2;
axis([xmin xmax ymin ymax zmin zmax]);
pbaspect([1 1 1]);
axis off;
view(60,20);
camzoom(1.7);
% Draw axes
quiver3(-2,0,0,4,0,0,0,'k','filled'); % x-axis
quiver3(0,-2,0,0,4,0,0,'k','filled'); % y-axis
quiver3(0,0,-2,0,0,4,0,'k','filled'); % z-axis
text(0,0,0,'O');
text(xmax,0,0,'x');
text(0,ymax,0,'y');
text(0,0,zmax,'z');
%
x = 1;
y = 0.5;
z = 1.5;
r=sqrt(x^2+y^2+z^2);
quiver3(0,0,0,x,y,z,0,'r','filled'); % Position Vector
% Unit vectors
quiver3(x,y,z,r/3,0,0,0,'b','filled'); % x
quiver3(x,y,z,0,r/3,0,0,'b','filled'); % y
quiver3(x,y,z,0,0,r/3,0,'b','filled'); % z
text(x+r/3,y,z,'x\^');
text(x,y+r/3,z,'y\^');
text(x,y,z+r/3,'z\^');
% Aux. lines
l1_1=line([0 0 x x x 0 0 x x],[y 0 0 0 y y y y 0],[z z z 0 0 0 z z z]);
l1_2=line([0 x x],[0 y y],[0 0 z]);
l1_1.LineStyle = '--';
l1_2.LineStyle = '--';
l1_1.Color = [0.5 0.5 0.5];
l1_2.Color = [0.5 0.5 0.5];
