We want to make a 3D plot of values that are calculated by GNU Octave. It only shows us the axes of the graph, no dots. When making a normal 2D plot (i.e. plot (x,y)) everything works normally. The code we used was:
t=0;
dt = 0.1;
x=0;
y=0;
z=0;
vx=40;
vy=15;
vz=15;
m=0.43;
g=9.81;
rho=0.9982;
Cw=0.47;
A=0.03789;
while (z>=0)
Fwlx = 0.5*Cw*A*rho*(vx)^2;
Fwly = 0.5*Cw*A*rho*(vy)^2;
Fwlz = 0.5*Cw*A*rho*(vz)^2;
Fz = m*g;
Fresx = -Fwlx;
Fresy = -Fwly;
Fresz = -Fwlz-Fz;
ax = Fresx/m;
ay = Fresy/m;
az = Fresz/m;
vx = vx + ax*dt;
vy = vy + ay*dt;
vz = vz + az*dt;
x = x + vx*dt;
y = y + vy*dt;
z = z + vz*dt;
t = t + dt;
plot3 (x,y,z)
hold on
end
EDIT 15-Oct-2024: A change has been pushed to Octave's plot3 code that will have it behave similarly to plot, creating a graph with a single data point and the markertype set to .
. This will take effect in Octave 10.
This is (unexpectedly) due to the way you are collecting and plotting data 1 point at a time. At least in Octave 9.2.0, plot() defaults to having a point marker for 1 element plots, plot3() has marker type set to 'none'
If you collect the data points and plot them all at once, it links the data points with lines and you can see the trajectory. Alternatively, setting a plot/marker style can make the original approach more visible. E.g.,:
simply adding a format to the plot3 command:
`plot3(x,y,z, 'r*')
shows me the following:
or, if I change the script to something like the following, it will plot all of the points together after the loop:
t=0;
dt = 0.1;
x=0;
y=0;
z=0;
vx=40;
vy=15;
vz=15;
m=0.43;
g=9.81;
rho=0.9982;
Cw=0.47;
A=0.03789;
xp = yp = zp = [];
while (z>=0)
Fwlx = 0.5*Cw*A*rho*(vx)^2;
Fwly = 0.5*Cw*A*rho*(vy)^2;
Fwlz = 0.5*Cw*A*rho*(vz)^2;
Fz = m*g;
Fresx = -Fwlx;
Fresy = -Fwly;
Fresz = -Fwlz-Fz;
ax = Fresx/m;
ay = Fresy/m;
az = Fresz/m;
vx = vx + ax*dt;
vy = vy + ay*dt;
vz = vz + az*dt;
x = x + vx*dt;
y = y + vy*dt;
z = z + vz*dt;
t = t + dt;
xp(end+1) = x;
yp(end+1) = y;
zp(end+1) = z;
end
plot3 (xp,yp, zp)
regarding whether or note this might be a bug, note that a simple 1 data point plot with clearly visible data:
A = plot(1,1)
get(A)
...
linestyle = -
linewidth = 0.5000
marker = .
markeredgecolor = auto
markerfacecolor = none
markersize = 6
...
but with a 3d plot:
plot3(1,1,1)
get(A)
...
linestyle = -
linewidth = 0.5000
marker = none
markeredgecolor = auto
markerfacecolor = none
markersize = 6
...
Note the marker = none
setting for the 3D plot. plot()
has marker = none
for data with more than one point, so I suspect there was a conscious decision to changes this behavior for n = 1. plot3() does not do this.
It is worth noting that while Octave is designed with intent to be m-code compatible with Matlab, the plot
and plot3
in Matlab both behave like plot3
in Octave, where a plot with n=1 is treated no differently than one with n>1. They have the default properties for a line plot, with a single solid line and no marker points.