4

I am trying to graph this image (where the sphere on the right is the unit sphere x^2+y^2+z^2=1) enter image description here

The image of the hyperboloid by N is {(x,y,z)\in Sphere : -sqrt(2) < z < sqrt(2)}, it is exactly what I tried to graph on the right: a sphere intersected by two planes.

I found these posts how-to-graph-a-hyperboloid-of-a-leaf-with-intersections-using-tikzpicture-enviro and pgfplots-quadrics, but failed to compile them my way or at least something nice. I was thinking of graphing them separately then taking them to Inkscape to edit them (cheating a bit), could someone help me? If the axes do not come out there is no problem.

Actually I would like to know if it is possible to graph any coordinate surface (x, y, z) with its normal vectors given by N(x, y, z). Because I would like to do the same as above but now for z=sin(y) e^x.

Upgrade: Thanks to @NguyenVanChi1998 I was able to make the graph I wanted for both graphs, here I show what I did for the second z=sin(y) e^x, since the first appears as the answer of @NguyenVanChi1998,

settings.render=8;
import graph3;
import palette;

currentprojection=orthographic(1,1,0.3);
//currentlight.background = gray(0.7);

typedef triple newtriple(pair);
// https://en.wikipedia.org/wiki/Hyperboloid
newtriple f(real a, real b, real c)
{
  return new triple(pair k){
    real u=k.x,v=k.y;
    real x,y,z;
    x=-a*u;
    y=b*v;
    z=c*exp(u)*sin(v);
    return (x,y,z);
  };
}
triple F(pair z){ return f(1,1,1)(z); }

// Gauss map
triple g(pair z)
{
  real u=z.x, v=z.y;
  real x,y,z;
  x=exp(u)*sin(v);
  y=exp(u)*cos(v);
  z=sqrt(1+exp(2*u));
  return -7*(x,y,-1)/z;
}

// https://trecs.se/hyperboloidOfOneSheet.php
path3 vector(pair z) {
  real u=z.x, v=z.y;
  real a=1, b=1, c=1;
  real x,y,z;
  x=-b*c*exp(u)*sin(v);
  y=-a*c*exp(u)*cos(v);
  z=a*b*sqrt(1+exp(2*u));
  return O--(-(x,y,-1)/z);
}

size(13cm);

surface sf=surface(F,(-10,-12),(3,6),40,Spline);
//sf.colors(palette(sf.map(zpart),Rainbow()));
draw(sf,RGB(0,153,216),render(merge=true));
add(vectorfield(vector,F,(-10,-12),(3,6),20,50,red,render(merge=true)));
//xaxis3(Label("$x$",BeginPoint),0,7,Arrow3);
draw(Label("$x$",EndPoint),(12,0,0)--(-12,0,0),Arrow3);
yaxis3(Label("$y$",EndPoint),0,12,Arrow3);
zaxis3(Label("$z$",EndPoint),-18,22,Arrow3);
label("$\mathcal{H}$",(-.5,5.5,18),dir(45));

transform3 t=shift(20*(Y-X));
surface sg=surface(g,(-2.5,-5),(5,5),20,Spline);
//sg.colors(palette(sg.map(zpart),Rainbow()));
draw(t*sg,RGB(236, 125, 44),render(merge=true));
label("$N\left(\mathcal{H} \right)$",t*(-.5,6,6),dir(45));
draw(Label("$x$",EndPoint),t*((0,0,0)--(12,0,0)),Arrow3);
draw(Label("$y$",EndPoint),t*((0,0,0)--(0,12,0)),Arrow3);
draw(Label("$z$",EndPoint),t*((0,0,0)--(0,0,13)),Arrow3);
//dot(Label("$(0,0,1)$",black),t*(0,0,7),dir(135),white+5bp);

draw(Label("$N$",Relative(.5),N),subpath((0,0,0)--t*(0,0,0),0.4,0.6),Arrow3);

output:

enter image description here

6
  • You wrote " where the sphere on the right is the unit sphere x^2+y^2=1)", I think ``x^2+y^2+z^2=1''. I do not understand two number sqrt(2) and -sqrt(2) on the z - axis. Nov 25, 2021 at 1:10
  • @minhthien_2016 Thank you very much if you are right it was a typing error. Regarding z=sqrt(2) and z=-sqrt(2), what I tried to do is: A unitary sphere intersected with two planes, and the part between said planes is painted. (I'll edit my question to clarify that topic in more detail.)
    – Zaragosa
    Nov 25, 2021 at 1:17
  • I think, If radius of the sphere equal to R=1, the the plane perpendicular to z - axis has the equation z = h, where -1<h<1. Nov 25, 2021 at 1:19
  • I already edited it, I hope it is better understood.
    – Zaragosa
    Nov 25, 2021 at 1:23
  • 1
    you can see here for the sphere. Nov 25, 2021 at 1:32

3 Answers 3

9
+150

NOTE that: I don't know either what I am drawing. :)

Drawing 3D image in Asymptote is a difficult problem for both my knowledge and my computer (it is weak).

You can add mesh for surface. You can also draw two surface separately (can be done on http://asymptote.ualberta.ca/).

You must have a parametrization of your surface to use the command vectorfield.

I am happy if one of top asymptote answerers has a better solution, certainly.

This is my try, this code is compiled with asy -f png -render=8 <name file>.asy.


import graph3;
import palette;

currentprojection=orthographic(1,1,0.3);
currentlight.background = gray(.7);
//currentlight=nolight;

typedef triple newtriple(pair);
// https://en.wikipedia.org/wiki/Hyperboloid
newtriple f(real a, real b, real c)
{
  return new triple(pair k){
    real u=k.x,v=k.y;
    real x,y,z;
    x=a*cosh(v)*cos(u);
    y=b*cosh(v)*sin(u);
    z=c*sinh(v);
    return (x,y,z);
  };
}
triple F(pair z){ return f(1,1,1)(z); }

// Gauss map
triple g(pair z)
{
  real u=z.x, v=z.y;
  triple U=(-cosh(v)*sin(u),cosh(v)*cos(u),0);
  triple V=(sinh(v)*cos(u),sinh(v)*sin(u),cosh(v));
  return cross(U,V)/abs(cross(U,V));
}

// https://trecs.se/hyperboloidOfOneSheet.php
path3 vector(pair z) {
  real u=z.x, v=z.y;
  real a=1, b=1, c=1;
  real x,y,z;
  x=-b*c*cosh(v)^2*cos(u);
  y=-a*c*cosh(v)^2*sin(u);
  z=a*b*sinh(v)*cosh(v);
  return O--(-(x,y,z)/sqrt(x^2+y^2+z^2));
}

picture pic, pic1, pic2, pic3;
size(pic1,300);
size(pic2,300);

surface sf=surface(F,(0,-1.5),(2pi,1.5),40,Spline);
sf.colors(palette(sf.map(zpart),Rainbow()));
draw(pic1,sf,render(merge=true));
label(pic1,"$(\mathcal{H})$",(-1,2.2,2.7),dir(45));
add(pic1,vectorfield(vector,F,(0,-1.5),(2pi,1.5),10,0.5,red,render(merge=true)));
xaxis3(pic1,Label("$x$",EndPoint),0,3.5,Arrow3);
yaxis3(pic1,Label("$y$",EndPoint),0,3.5,Arrow3);
zaxis3(pic1,Label("$z$",EndPoint),0,3,Arrow3);
pair z=(pi/7,-0.5);
dot(pic1,"$P$",F(z),dir(90),black+5bp);
draw(pic1,Label("$N(P)$",EndPoint),shift(F(z))*vector(z),blue,Arrow3);

surface sg=surface(g,(0,-1.5),(2pi,1.5),20,Spline);
sg.colors(palette(sg.map(zpart),Rainbow()));
draw(pic2,sg,render(merge=true));
label(pic2,"$N\left(\mathcal{H} \right)$",(-.5,0.5,0.8),dir(45));
dot(pic2,Label("$\frac{1}{\sqrt{2}}$",blue),(0,0,1/sqrt(2)),dir(45),green+5bp);
xaxis3(pic2,Label("$x$",EndPoint),0,1.5,Arrow3);
yaxis3(pic2,Label("$y$",EndPoint),0,1.5,Arrow3);
zaxis3(pic2,Label("$z$",EndPoint),0,1,Arrow3);

add(pic,pic1.fit(),(0,0),20W);
add(pic,pic2.fit(),(0,0),20E);
draw(pic3,Label("$N$",MidPoint,LeftSide),(-20,0)--(20,0),Arrow);
add(pic,pic3.fit());
add(pic.fit(),Fill(gray(.7)));

enter image description here or

settings.render=8;
import graph3;
import palette;

currentprojection=orthographic(1,1,0.3);
currentlight.background = gray(.7);

typedef triple newtriple(pair);
// https://en.wikipedia.org/wiki/Hyperboloid
newtriple f(real a, real b, real c)
{
  return new triple(pair k){
    real u=k.x,v=k.y;
    real x,y,z;
    x=a*cosh(v)*cos(u);
    y=b*cosh(v)*sin(u);
    z=c*sinh(v);
    return (x,y,z);
  };
}
triple F(pair z){ return f(1,1,1)(z); }

// Gauss map
triple g(pair z)
{
  real u=z.x, v=z.y;
  triple U=(-cosh(v)*sin(u),cosh(v)*cos(u),0);
  triple V=(sinh(v)*cos(u),sinh(v)*sin(u),cosh(v));
  return cross(U,V)/abs(cross(U,V));
}

// https://trecs.se/hyperboloidOfOneSheet.php
path3 vector(pair z) {
  real u=z.x, v=z.y;
  real a=1, b=1, c=1;
  real x,y,z;
  x=-b*c*cosh(v)^2*cos(u);
  y=-a*c*cosh(v)^2*sin(u);
  z=a*b*sinh(v)*cosh(v);
  return O--(-(x,y,z)/sqrt(x^2+y^2+z^2));
}

size(9cm);

surface sf=surface(F,(0,-1.5),(2pi,1.5),40,Spline);
//sf.colors(palette(sf.map(zpart),Rainbow()));
draw(sf,RGB(0,153,216),render(merge=true));
label("$(\mathcal{H})$",(-1,2.2,2.7),dir(45));
add(vectorfield(vector,F,(0,-1.5),(2pi,1.5),10,0.5,red,render(merge=true)));
xaxis3(Label("$x$",EndPoint),0,3.5,Arrow3);
yaxis3(Label("$y$",EndPoint),0,3.5,Arrow3);
zaxis3(Label("$z$",EndPoint),0,3,Arrow3);
pair z=(pi/7,-1);
dot("$P$",F(z),dir(70),black+3bp);
draw(Label("$N(P)$",EndPoint,LeftSide),shift(F(z))*vector(z),blue,Arrow3);

transform3 t=shift(5*(Y-X));
surface sg=surface(g,(0,-1.5),(2pi,1.5),20,Spline);
sg.colors(palette(sg.map(zpart),Rainbow()));
draw(t*sg,render(merge=true));
label("$N\left(\mathcal{H} \right)$",t*(-.5,0.5,0.8),dir(45));
dot(Label("$\frac{1}{\sqrt{2}}$",blue),t*(0,0,1/sqrt(2)),dir(135),green+2bp);
draw(Label("$x$",EndPoint),t*((0,0,0)--(3,0,0)),Arrow3);
draw(Label("$y$",EndPoint),t*((0,0,0)--(0,3,0)),Arrow3);
draw(Label("$z$",EndPoint),t*((0,0,0)--(0,0,3)),Arrow3);

draw(Label("$N$",Relative(.5),N),subpath((0,0,0)--t*(0,0,0),0.4,0.6),Arrow3);

enter image description here

An additional code,

hyperbolic paraboloid : z = xy

settings.render=8;
import graph3;
import palette;

currentprojection=orthographic(1,0.2,1);
currentlight.background = gray(.7);
size(8cm,5cm,false);

// https://mathworld.wolfram.com/HyperbolicParaboloid.html
triple f(pair k){
    real u=k.x,v=k.y;
    return (u,v,u*v);
}

// Gauss map
triple g(pair z)
{
  real u=z.x, v=z.y;
  triple U=(1,0,v);
  triple V=(0,1,u);
  return cross(U,V)/abs(cross(U,V));
}
// https://trecs.se/hyperbolicParaboloid.php
path3 vector(pair z) {
  real u=z.x, v=z.y;
  return O--((-v,-u,1)/sqrt(u^2+v^2+1));
}

surface sf=surface(f,(-2,-2),(2,2),40,Spline);
sf.colors(palette(sf.map(zpart),Rainbow()));
draw(sf,render(merge=true));
add(vectorfield(vector,f,(-2,-2),(2,2),10,0.5,red,render(merge=true)));

xaxis3(Label("$x$",EndPoint),-3,3,Arrow3);
yaxis3(Label("$y$",EndPoint),-3,3,Arrow3);
zaxis3(Label("$z$",EndPoint),-3,4,Arrow3);

enter image description here

and its Gauss map

// ...
surface sg=surface(g,(-2,-2),(2,2),40,Spline);
sg.colors(palette(sg.map(zpart),Rainbow()));
draw(sg,render(merge=true));

xaxis3(Label("$x$",EndPoint),-2,2,Arrow3);
yaxis3(Label("$y$",EndPoint),-2,2,Arrow3);
zaxis3(Label("$z$",EndPoint),-2,2,Arrow3);

enter image description here

8
  • Wooow I loved your answer, I have copied and pasted in asymptote.ualberta.ca the hyperbolic paraboloid and it works excellent, but I have had problems with the first one, the hyperboloid, please could you put the precise code to compile or is it my machine that does not support it? On the other hand, can I put a color of my preference to those surfaces? I wanted to change it to a color rgb = {0,153,216} but couldn't. Sorry for the questions but Asymptote is super new to me, and I find it amazing.
    – Zaragosa
    Nov 28, 2021 at 11:23
  • @Zaragosa The second code can be rotated on asymptote.ualberta.ca Nov 28, 2021 at 12:16
  • Thank you very much, your answer is excellent! One last question without much importance: I updated my question, how can I enlarge the length of the vector of z=sin(y) e^x?
    – Zaragosa
    Nov 28, 2021 at 16:05
  • @Zaragosa, Considering to replace: size(13cm); by size(500,350,false);, add(vectorfield(vector,F,(-10,-12),(3,6),20,50,red,render(merge=true))); by add(vectorfield(vector,F,(-10,-12),(3,6),10,2.5,red,render(merge=true)));, surface sg=surface(g,(-2.5,-5),(5,5),20,Spline); by surface sg=surface(g,(-10,-12),(3,6),20,Spline);. Why do I change like that? I think you can answer it. Learning 3D Asymptote is a difficult problem but possible. Nov 28, 2021 at 16:45
  • 1
    @Zaragosa To improve the quality of your picture, you can increase from 8 to 16 or 20 ... And downloading a png on asymptote.ualberta.ca. However, if you have a strong computer, you will learn 3D Asymptote easily and efficiently. Nov 28, 2021 at 16:55
5

Not sure if I fully understand the question because I do not understand what is wrong with the posts you link to. Nonetheless, the following may go in the right direction.

\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}
\begin{tikzpicture}[>=stealth]
 \begin{axis}[hide axis]
  \addplot3 [surf,shader=interp,z buffer=sort,domain=0:360,domain y=-1:1] 
   ({cos(x)*cosh(y)},{sin(x)*cosh(y)},{sinh(y)});
  \draw[->] (1,0,0) -- (2,0,0);
  \draw[->] (0,-1,0) -- (0,-2,0);
 \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

3
  • It is not that the aforementioned post is wrong, what happens is that I want to graph the image that I made by hand above, but I cannot do it by modifying the code that appears there. I have tried but I do not know much and I get an error at the minimum change. That was the reason to open this question.
    – Zaragosa
    Nov 25, 2021 at 0:55
  • 1
    @Zaragosa My statement was not meant to be a criticism. Nevertheless, thanks a lot for clarifying! Anyway, you could perhaps use this or a similar post to clarify what you precisely want to achieve.
    – user255043
    Nov 25, 2021 at 3:46
  • I did not take it as a criticism hehe , I just wanted to make it clear because my English is not very good so I tried to be clear. Thank you very much for your solution, I am seeing how I can connect it with what I have in mind.
    – Zaragosa
    Nov 25, 2021 at 3:53
4

About intersection of a plane and a sphere, you can try this code. Note that, if a sphere has radius R; distance from the center of sphere to the plane is d,then intersection plane and the sphere is a circle has radius r = sqrt(R^2 - d^2).

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{3dtools}% https://github.com/marmotghost/tikz-3dtools
\begin{document}
\begin{tikzpicture}[3d/install view={phi=110,theta=70},line cap=butt,
    line join=round,declare function={R=2.5; d =1.5;r=sqrt(R*R - d*d);},c/.style={circle,fill,inner sep=1pt}] 
    \path
    (0,0,0) coordinate (O)
    (0,0,R)  coordinate (N)
    (0,0,-R)  coordinate (S)
    (0,0,d)  coordinate (O')
    ({r*cos(-30)}, {r*sin(-30)},d)  coordinate (A)
    ;
    \draw[3d/screen coords] (O) circle[radius=R]; 
    \path pic{3d/circle on sphere={R=R,C={(O)}}};
    \path  pic{3d/circle on sphere={R=R,C={(O)},P={(0,0,d)}}};
\path  pic{3d/circle on sphere={R=R,C={(O)},P={(0,0,-d)}}}; 
    \draw[3d/hidden] (S) -- (N) (O) -- (A) node[midway,below]{$ R $} (O') -- (A) node[midway,above]{$ r $};
    \path foreach \p/\g in {O/0,S/0,N/0,A/-90,O'/0}
    {(\p)node[c]{}+(\g:2.5mm) node{$\p$}};
\end{tikzpicture}
\end{document}

enter image description here

About Spherical segment, you can see here.

1
  • Good solution and great suggestion for shading. To graph the hyperboloid I was thinking of graphing it but to cheat a bit, that is, to graph two hyperbolas and make it appear that it is hyperboloid, I will try it but would there be another way? I like ABC's solution but I would also like both graphs to be of the same type or the same characteristics.
    – Zaragosa
    Nov 25, 2021 at 3:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.