Group Abstract Group Abstract

Message Boards Message Boards

Plot a torus knot with ParametricPlot3D?

Posted 9 years ago

Hello everyone, I hope you can explain why I am getting an empty graphic, I happen to be taking the code that Paul Nylander shares on his web page, and when I run it in mathematica I do not get any graphics, here I share a screenshot so that understand my problem better,

graphic obtained

I think the problem is in how it uses ParametricPlot3D, but I hope someone who knows the reason, please explain, thanks in advance.

Image and code from Paul`s page

how make it

Code used for me, this is

normalize[x_] := x/Sqrt[x.x]; 
p[t_] := {(1 + 0.3 Cos[11 t/3]) Cos[t], (1 + 0.3 Cos[11 t/3]) Sin[t], 
  0.3 Sin[11 t/3]};
f[t_, theta_] := 
  Module[{dp = p'[t], ddp = p''[t], tangent, normal1, normal2}, 
   tangent = normalize[dp]; 
   normal1 = normalize[ddp (dp.dp) - dp (dp.ddp)]; 
   normal2 = Cross[tangent, normal1]; 
   p[t] + 0.1 (normal1 Cos[theta] + normal2 Sin[theta])];

ParametricPlot3D[
 Append[f[t, theta], {EdgeForm[], SurfaceColor[Hue[t/(2 Pi)]]}], {t, 
  0, 6 Pi}, {theta, 0, 2 Pi}, PlotPoints -> {360, 15}, 
 Compiled -> False]
POSTED BY: Luis Ledesma
2 Replies
Posted 9 years ago
POSTED BY: Luis Ledesma

Here is the correct one:

p[t_]:={(1+0.3 Cos[11 t/3]) Cos[t],(1+0.3 Cos[11 t/3]) Sin[t],0.3 Sin[11 t/3]};
f[t_,theta_]:=Module[{dp=p'[t],ddp=p''[t],tangent,normal1,normal2},
    tangent=Normalize[dp];
    normal1=Normalize[ddp (dp.dp)-dp (dp.ddp)];
    normal2=Cross[tangent,normal1];
    p[t]+0.1 (normal1 Cos[theta]+normal2 Sin[theta])
];

ParametricPlot3D[f[t,theta],{t,0,6 Pi},{theta,0,2 Pi},ColorFunction->Function[{x,y,z,u,v},Hue[u]],PlotPoints->{160, 20},MaxRecursion->0]

You can't specify the surface color like the website does, perhaps in a VERY old version it was possible. I can't remember that though... You have to use ColorFunction. Note that Normalize is available in the Wolfram Language. Speed can be improved by not repeating the differentiation each time...

POSTED BY: Sander Huisman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard