1

I have the following equations of motion of a point:

x(t):=r*cos(t^2)$
y(t):=r*sin(t^2)$
z(t):=b*t$

I already calculated the velocities and accelerations but now I would like to plot a path in 3D for this data:

r:5;
b:2;

It should look like a kind of spiral.

I tried various commands to create this 3D plot but none of them worked. All the examples of 3D plots in wxMaxima that I've found are surfaces while in this case, I want to create a curve. Is it possible in this software?

Here are two of the failed attempts:

wxplot3d([x(t), y(t), z(t)], [t, 0, 45]);
wxplot3d([parametric, x(t), y(t), z(t), [t, 0, 45]]);

UPDATE: The command below works but the plot is incorrect for some reason (I attached it as a picture). Is that because of the characteristics of these functions? Do I need some additional input?

wxdraw3d(parametric (x(t), y(t), z(t), t, 0, 45));

enter image description here

UPDATE 2: I tried the following command:

wxdraw3d(nticks = 10, parametric (x(t), y(t), z(t), t, 0, 45));

and the plot looks better (only with nticks=10):

enter image description here

But it's still not what I would expect. Here's a reference plot from a Polish book describing MathCAD use in mechanics (so I can't utilize the code presented there directly):

enter image description here

Maybe the problem lies in the fact that the authors of this book use some tricks ("auxiliary variables scaling the argument of the function") to obtain the plot. But I assume that it's only necessary in MathCAD. I can be wrong though...

If you know how to define a range variable in Maxima, I can try to replicate the approach from the book in Maxima.

UPDATE 3: Here's what was done in the book to obtain that plot using MathCAD:

define auxiliary variables scaling the argument of the function:

M:=1000
K:=0,1.. 45

for which the time domain is given by:

t_k:=k*sqrt(π/M)

define the functions for plotting as:

X_k:=r*cos(((k^2)/M)*π)
Y_k:=r*sin(((k^2)/M)*π)
Z_k:=b*k

And here's my attempt to translate this to Maxima:

M:1000$
assume(k >= 0, k <= 45);
t_k:k*sqrt(%pi/M);
X_k(t_k):=r*cos(((k^2)/M)*%pi);
Y_k(t_k):=r*sin(((k^2)/M)*%pi);
Z_k(t_k):=b*k;
wxdraw3d(nticks = 10, parametric (X_k(t_k), Y_k(t_k), Z_k(t_k), t_k, 0, 45));

Unfortunately, I get the following error:

draw3d (parametric): non defined variable

That's likely because of the way k was defined. Can such a range variable be defined differently in Maxima?

FEA-eng
  • 106
  • 6
  • 1
    Try `wxdraw3d (parametric (x(t), y(t), z(t), t, tmin, tmax))` i.e. `wxdraw3d` instead of `wxplot3d` -- `draw` is an add-on package which has some plotting functions which are different from the built-in stuff. – Robert Dodier May 11 '22 at 19:25
  • Thank you. I tried `wxdraw3d(parametric (x(t), y(t), z(t), t, 0, 45));` and it works but the plot is incorrect for some reason. I will update my original question since I can't add images here. – FEA-eng May 12 '22 at 08:11
  • 1
    Oh, I think the problem is that the number of points at which the function is evaluated is fixed for `draw3d(parametric(...))`. Try `wxdraw3d (nticks = nnn, parametric (...))` where nnn = 100 or 1000 or something. I think `parametric` should use adaptive plotting, so that's a bit of a shortcoming; I'll create a feature request ticket about that. – Robert Dodier May 12 '22 at 16:28
  • Thank you. I used this command but the plot still doesn't look right, unfortunately. When I increase the number of nticks, it becomes more messy. With 10 it's not that bad but still doesn't resemble the reference plot from a book meant for MathCAD users. I updated my original question again to include these plots. I will appreciate any further help. – FEA-eng May 14 '22 at 10:36
  • 1
    It looks to me like draw3d is working okay and the unexpected behavior comes from the argument t^2 in sin and cos. Note that if t goes from 0 to 45, then t^2 goes from 0 to about 2000, i.e., many, many full periods of sin and cos. I think that's the mess you are seeing. When the upper limit for t is much smaller, I get a nice picture, e.g.: `draw3d (nticks=nnn, parametric (x(t), y(t), z(t), t, 0, t1)), nnn=1000, t1=sqrt(10*%pi);` It's not exactly the same as the figure you showed, so I wonder if they were working with somewhat different parameters. – Robert Dodier May 14 '22 at 18:08
  • Right, the plot is really nice then. I updated my original question once again to include the tweaks done in the book to obtain that plot using MathCAD. – FEA-eng May 15 '22 at 11:13

1 Answers1

3

I've adapted the code you showed and it seems to work okay with some modifications.

r:5;
b:2;
M:1000$
X(k):=r*cos(((k^2)/M)*%pi);
Y(k):=r*sin(((k^2)/M)*%pi);
Z(k):=b*k;
draw3d(nticks = 1000, parametric (X(k), Y(k), Z(k), k, 0, 45));

The major changes are that foo_k := ... in the MathCAD code is translated as foo(k) := ... in Maxima, and that the plotting variable is k (which is constructed to vary much more slowly than t) instead of t or t(k).

Also I increased nticks by a lot, and cut out the mention of t_k since it doesn't come into the picture now.

By the way, I think if you say draw3d in wxMaxima, it will launch an external viewer instead of embedding an image in the notebook (with wxdraw2d, I think). You can drag with the mouse to rotate the plot in the external viewer, I think. That's helpful with 3-d plots. I could be mistaken about how to launch the viewer, since I don't use wxMaxima very much.

Robert Dodier
  • 16,905
  • 2
  • 31
  • 48
  • Thank you so much. The plot now looks very similar to what is presented in the book. I'm not 100% sure if it's exactly the same but it seems to be (the difference in axis adjustment may cause some visual discrepancy). – FEA-eng May 16 '22 at 10:21