Trefoil knot inside Torus

Instructions - Part I:
Open GeoGebra in your desktop. Activate 2d and 3d graphics. You will be able to create a Torus with a trefoil knot inside. This is done using vector calculus, which requires lots of computations for the software, so you will need to have a powerful computer. The picture below shows an example of the result.
Instructions - Part II
In the 2d graphics, create a button with the following GGB Script:[br][br]#First define the components of the trefoil knot curve (it could be another curve in space R^3)[br][br]rx(x)=(2 + cos(3 / 2 x)) cos(x)[br]ry(x)=(2 + cos(3 / 2 x)) sin(x)[br]rz(x)=sin(3 / 2 x)[br][br]SetVisibleInView(rx,1,false)[br]SetVisibleInView(ry,1,false)[br]SetVisibleInView(rz,1,false)[br][br]SetVisibleInView(rx,-1,false)[br]SetVisibleInView(ry,-1,false)[br]SetVisibleInView(rz,-1,false)[br][br]##[br][br]#This defines the curve. To plot it write true below.[br][br]r=Curve(rx(t),ry(t),rz(t), t, 0, 4π)[br][br]SetVisibleInView(r,-1,false)[br][br]##[br][br]#Calculate the derivative of each component of the curve and the norm[br][br]drx(x)=Derivative(rx)[br]dry(x)=Derivative(ry)[br]drz(x)=Derivative(rz)[br][br]SetVisibleInView(drx,1,false)[br]SetVisibleInView(dry,1,false)[br]SetVisibleInView(drz,1,false)[br][br]SetVisibleInView(drx,-1,false)[br]SetVisibleInView(dry,-1,false)[br]SetVisibleInView(drz,-1,false)[br][br]norma(x)=sqrt(drx(x)^2+dry(x)^2+drz(x)^2)[br][br]SetVisibleInView(norma,1,false)[br]SetVisibleInView(norma,-1,false)[br][br]##[br][br]#Now calculate the tangent vector[br][br]Trx(x)=drx/norma[br]Try(x)=dry/norma[br]Trz(x)=drz/norma[br][br]SetVisibleInView(Trx,1,false)[br]SetVisibleInView(Try,1,false)[br]SetVisibleInView(Trz,1,false)[br][br]SetVisibleInView(Trx,-1,false)[br]SetVisibleInView(Try,-1,false)[br]SetVisibleInView(Trz,-1,false)[br][br]#Now calculate the normal vector[br][br]dTrx(x)=Derivative(Trx)[br]dTry(x)=Derivative(Try)[br]dTrz(x)=Derivative(Trz)[br][br]SetVisibleInView(dTrx,1,false)[br]SetVisibleInView(dTry,1,false)[br]SetVisibleInView(dTrz,1,false)[br][br]SetVisibleInView(dTrx,-1,false)[br]SetVisibleInView(dTry,-1,false)[br]SetVisibleInView(dTrz,-1,false)[br][br]normaT(x)=sqrt((dTrx)^2+(dTry)^2+(dTrz)^2)[br][br]SetVisibleInView(normaT,1,false)[br]SetVisibleInView(normaT,-1,false)[br][br]Nrx(x)=dTrx/normaT[br]Nry(x)=dTry/normaT[br]Nrz(x)=dTrz/normaT[br][br][br]SetVisibleInView(Nrx,1,false)[br]SetVisibleInView(Nry,1,false)[br]SetVisibleInView(Nrz,1,false)[br][br]SetVisibleInView(Nrx,-1,false)[br]SetVisibleInView(Nry,-1,false)[br]SetVisibleInView(Nrz,-1,false)[br][br]##[br][br]#Now calculate the binormal vector[br][br]Brx(x)=Try*Nrz-Trz*Nry[br]Bry(x)=Trz*Nrx-Trx*Nrz[br]Brz(x)=Trx*Nry-Try*Nrx[br][br][br]SetVisibleInView(Brx,1,false)[br]SetVisibleInView(Bry,1,false)[br]SetVisibleInView(Brz,1,false)[br][br]SetVisibleInView(Brx,-1,false)[br]SetVisibleInView(Bry,-1,false)[br]SetVisibleInView(Brz,-1,false)[br][br]##[br][br]#The components of the surface is defined here[br][br]radius=(1/2)[br][br]gx(x,y)=rx(x)+radius*(Nrx(x)*cos(y)+Brx(x)*sin(y))[br]gy(x,y)=ry(x)+radius*(Nry(x)*cos(y)+Bry(x)*sin(y))[br]gz(x,y)=rz(x)+radius*(Nrz(x)*cos(y)+Brz(x)*sin(y))[br][br]SetVisibleInView(gx,1,false)[br]SetVisibleInView(gy,1,false)[br]SetVisibleInView(gz,1,false)[br][br]SetVisibleInView(gx,-1,false)[br]SetVisibleInView(gy,-1,false)[br]SetVisibleInView(gz,-1,false)[br][br]#If you want to plot the surface uncomment the following line[br]#surfaceKnot=Surface( gx(u,v), gy(u,v), gz(u,v), u, 0, 4 pi, v, 0, 2 pi )[br][br]value=2/3 pi[br][br]#We need to define the norm separately considering the point "f(value)"[br][br]normgf2(x,y)=(gx(x,y) -rx(value))^2+(gy(x,y)-ry(value))^2+(gz(x,y)-rz(value))^2[br][br]SetVisibleInView(normgf2,-1,false)[br][br]#Finally, the surface that defines the torus with a trefoil knot. We use an inversion to the sphere and consider a point on the curve (knot).[br][br]torusKnot=Surface((gx(t,theta)-rx(value))/normgf2(t,theta),(gy(t,theta)-ry(value))/normgf2(t,theta), (gz(t,theta)-rz(value))/normgf2(t,theta), t, 0, 4 pi, theta, 0, 2 pi)
Comments
There might be a more efficient method to do all this in GeoGebra. If you find one, let me know: j.ponce@uq.edu.au[br][br]Another version that runs faster (online and in desktop) is here: [url=https://ggbm.at/Y2TqvqjK]Trefoil knot inside Torus II[/url]

Information: Trefoil knot inside Torus