Drawing a 2D square lattice (springs + balls) on a convex surface
I need help with drawing a 2D square lattice made of springs and balls (see the picture) on a convex surface, such as spherical one. Could you please let me know is there a possibility of making this in PSTricks or TikZ? Thanks a lot.
I have linked [1] a related example in PDF with a grid on a spherical surface.
[1] http://www.texample.net/media/tikz/examples/PDF/spherical-and-cartesian-grids.pdf
tikz-pgf pst-coil
add a comment |
I need help with drawing a 2D square lattice made of springs and balls (see the picture) on a convex surface, such as spherical one. Could you please let me know is there a possibility of making this in PSTricks or TikZ? Thanks a lot.
I have linked [1] a related example in PDF with a grid on a spherical surface.
[1] http://www.texample.net/media/tikz/examples/PDF/spherical-and-cartesian-grids.pdf
tikz-pgf pst-coil
1
Welcome to TeX.SX. Questions about how to draw specific graphics that just post an image of the desired result are really not reasonable questions to ask on the site. Please post a minimal compilable document showing that you've tried to produce the image and then people will be happy to help you with any specific problems you may have. See minimal working example (MWE) for what needs to go into such a document.
– Stefan Pinnow
Dec 17 '18 at 10:49
Thank you @Stefan Pinnow. I'll follow your suggestion and I will write a new question tagging this one.
– Savchenko
Dec 17 '18 at 23:24
add a comment |
I need help with drawing a 2D square lattice made of springs and balls (see the picture) on a convex surface, such as spherical one. Could you please let me know is there a possibility of making this in PSTricks or TikZ? Thanks a lot.
I have linked [1] a related example in PDF with a grid on a spherical surface.
[1] http://www.texample.net/media/tikz/examples/PDF/spherical-and-cartesian-grids.pdf
tikz-pgf pst-coil
I need help with drawing a 2D square lattice made of springs and balls (see the picture) on a convex surface, such as spherical one. Could you please let me know is there a possibility of making this in PSTricks or TikZ? Thanks a lot.
I have linked [1] a related example in PDF with a grid on a spherical surface.
[1] http://www.texample.net/media/tikz/examples/PDF/spherical-and-cartesian-grids.pdf
tikz-pgf pst-coil
tikz-pgf pst-coil
edited Dec 17 '18 at 10:48
Stefan Pinnow
19.8k83276
19.8k83276
asked Dec 17 '18 at 10:32
SavchenkoSavchenko
766
766
1
Welcome to TeX.SX. Questions about how to draw specific graphics that just post an image of the desired result are really not reasonable questions to ask on the site. Please post a minimal compilable document showing that you've tried to produce the image and then people will be happy to help you with any specific problems you may have. See minimal working example (MWE) for what needs to go into such a document.
– Stefan Pinnow
Dec 17 '18 at 10:49
Thank you @Stefan Pinnow. I'll follow your suggestion and I will write a new question tagging this one.
– Savchenko
Dec 17 '18 at 23:24
add a comment |
1
Welcome to TeX.SX. Questions about how to draw specific graphics that just post an image of the desired result are really not reasonable questions to ask on the site. Please post a minimal compilable document showing that you've tried to produce the image and then people will be happy to help you with any specific problems you may have. See minimal working example (MWE) for what needs to go into such a document.
– Stefan Pinnow
Dec 17 '18 at 10:49
Thank you @Stefan Pinnow. I'll follow your suggestion and I will write a new question tagging this one.
– Savchenko
Dec 17 '18 at 23:24
1
1
Welcome to TeX.SX. Questions about how to draw specific graphics that just post an image of the desired result are really not reasonable questions to ask on the site. Please post a minimal compilable document showing that you've tried to produce the image and then people will be happy to help you with any specific problems you may have. See minimal working example (MWE) for what needs to go into such a document.
– Stefan Pinnow
Dec 17 '18 at 10:49
Welcome to TeX.SX. Questions about how to draw specific graphics that just post an image of the desired result are really not reasonable questions to ask on the site. Please post a minimal compilable document showing that you've tried to produce the image and then people will be happy to help you with any specific problems you may have. See minimal working example (MWE) for what needs to go into such a document.
– Stefan Pinnow
Dec 17 '18 at 10:49
Thank you @Stefan Pinnow. I'll follow your suggestion and I will write a new question tagging this one.
– Savchenko
Dec 17 '18 at 23:24
Thank you @Stefan Pinnow. I'll follow your suggestion and I will write a new question tagging this one.
– Savchenko
Dec 17 '18 at 23:24
add a comment |
1 Answer
1
active
oldest
votes
Welcome to TeX.SE! Here is a proposal.
documentclass[tikz,border=3.14mm]{standalone}
usetikzlibrary{decorations.pathmorphing}
begin{document}
begin{tikzpicture}
clip (-1,-1) rectangle (11,11);
foreach X in {-2,0,...,10}
{foreach Y in {-2,0,...,10}
{draw[decorate,decoration={coil,aspect=0.5,amplitude=1.5mm, segment
length=1.5mm}] (X,Y) -- ++(0,2) -- ++(2,0);
node[circle,text=white,font=sffamilybfserieslarge,inner
color=blue,outer color=black] at (X,Y) {+};}}
end{tikzpicture}
end{document}
It is straightforward to embed this into a spherical coordinate system. (Big thanks to @caverac for pointing out what the question really is.)
documentclass[tikz,border=3.14mm]{standalone}
usepackage{tikz-3dplot}
usetikzlibrary{decorations.pathmorphing,calc}
makeatletter
%from https://tex.stackexchange.com/a/375604/121799
%along x axis
define@key{x sphericalkeys}{radius}{defmyradius{#1}}
define@key{x sphericalkeys}{theta}{defmytheta{#1}}
define@key{x sphericalkeys}{phi}{defmyphi{#1}}
tikzdeclarecoordinatesystem{x spherical}{% %%%rotation around x
setkeys{x sphericalkeys}{#1}%
pgfpointxyz{myradius*cos(mytheta)}{myradius*sin(mytheta)*cos(myphi)}{myradius*sin(mytheta)*sin(myphi)}}
%along y axis
define@key{y sphericalkeys}{radius}{defmyradius{#1}}
define@key{y sphericalkeys}{theta}{defmytheta{#1}}
define@key{y sphericalkeys}{phi}{defmyphi{#1}}
tikzdeclarecoordinatesystem{y spherical}{% %%%rotation around x
setkeys{y sphericalkeys}{#1}%
pgfpointxyz{myradius*sin(mytheta)*cos(myphi)}{myradius*cos(mytheta)}{myradius*sin(mytheta)*sin(myphi)}}
%along z axis
define@key{z sphericalkeys}{radius}{defmyradius{#1}}
define@key{z sphericalkeys}{theta}{defmytheta{#1}}
define@key{z sphericalkeys}{phi}{defmyphi{#1}}
tikzdeclarecoordinatesystem{z spherical}{% %%%rotation around x
setkeys{z sphericalkeys}{#1}%
pgfpointxyz{myradius*sin(mytheta)*cos(myphi)}{myradius*sin(mytheta)*sin(myphi)}{myradius*cos(mytheta)}}
makeatother % https://tex.stackexchange.com/a/438695/121799
begin{document}
tdplotsetmaincoords{70}{130}
begin{tikzpicture}[tdplot_main_coords]
pgfmathsetmacro{R}{16}
path[clip]
plot[variable=x,domain=2.5:52.5]
(z spherical cs:radius=R,theta=80-2.5,phi=x)
-- plot[variable=x,domain=2.5:52.5]
(z spherical cs:radius=R,theta=80-x,phi=52.5)
-- plot[variable=x,domain=52.5:2.5]
(z spherical cs:radius=R,theta=80-52.5,phi=x)
-- plot[variable=x,domain=52.5:2.5]
(z spherical cs:radius=R,theta=80-x,phi=2.5);
foreach X in {0,5,...,55}
{draw[decorate,decoration={coil,aspect=0.5,amplitude=1.5mm, segment
length=1.5mm}] plot[variable=x,domain=0:55]
(z spherical cs:radius=R,theta=80-X,phi=x);
draw[decorate,decoration={coil,aspect=0.5,amplitude=1.5mm, segment
length=1.5mm}] plot[variable=x,domain=0:55]
(z spherical cs:radius=R,theta=80-x,phi=X);
}
foreach X in {5,10,...,50}
{foreach Y in {5,10,...,50}
{path let p1=($(z spherical cs:radius=R,theta=80-X+1,phi=Y)-(z
spherical cs:radius=R,theta=80-X,phi=Y)$),
p2=($(z spherical cs:radius=R,theta=80-X,phi=Y+1)-(z
spherical cs:radius=R,theta=80-X,phi=Y)$),
n1={veclen(x1,y1)/12},n2={veclen(x2,y2)/12},n3={sqrt(n1*n2)}
in %pgfextra{typeout{X,Y:n1,n2}}
node[scale=n3,transform shape,circle,text=white,font=sffamilybfserieslarge,inner
color=blue,outer color=black] at (z spherical cs:radius=R,theta=80-X,phi=Y) {+};}}
end{tikzpicture}
end{document}
As for your additional request: yes, it is possible. However, things depend on what you really want to achieve in the end. Here I present some example that heavily relies on Fritz's stellar answer. However, when trying to polish it by drawing things on different layers, I encountered unexpected problems. In any case, I have no idea what your real aim is. (See e.g. this great post for additional possibilities.) I would kindly like to ask you to make additional requests in form of a new question, which list all the requirements. Asking questions is free, after all. I leave you with
documentclass[border=3.14mm,tikz]{standalone}
usepackage{pgfplots}
usepackage{xxcolor}
pgfplotsset{compat=1.16}
usetikzlibrary{decorations.pathmorphing,decorations.markings}
% Declare nice sphere shading: http://tex.stackexchange.com/a/54239/12440
pgfdeclareradialshading[tikz@ball]{ball}{pgfqpoint{0bp}{0bp}}{%
color(0bp)=(tikz@ball!0!white);
color(7bp)=(tikz@ball!0!white);
color(15bp)=(tikz@ball!70!black);
color(20bp)=(black!70);
color(30bp)=(black!70)}
makeatother
% Style to set TikZ camera angle, like PGFPlots `view`
tikzset{viewport/.style 2 args={
x={({cos(-#1)*1cm},{sin(-#1)*sin(#2)*1cm})},
y={({-sin(-#1)*1cm},{cos(-#1)*sin(#2)*1cm})},
z={(0,{cos(#2)*1cm})}
}}
% Styles to plot only points that are before or behind the sphere.
pgfplotsset{only foreground/.style={
restrict expr to domain={rawx*CameraX + rawy*CameraY + rawz*CameraZ}{-0.05:100},
}}
pgfplotsset{only background/.style={
restrict expr to domain={rawx*CameraX + rawy*CameraY + rawz*CameraZ}{-100:0.05}
}}
% Automatically plot transparent lines in background and solid lines in foreground
defaddFGBGplot[#1]#2;{
addplot3[#1,only background, opacity=0.25] #2;
addplot3[#1,only foreground] #2;
}
% attempt to do similar things for discrete plots
defaddFGBGSampleplot[#1]#2;{
%addplot3[#1,only background,gray!50] #2;
addplot3[#1,only foreground] #2;
}
newcommand{ViewAzimuth}{-30}
newcommand{ViewElevation}{30}
tikzset{spring/.style={decorate,decoration={coil,aspect=0.5,amplitude=1.5mm, segment
length=1.5mm}}}
% pgfmanual p. 1087
pgfdeclareradialshading{ballshading}{pgfpoint{-10bp}{10bp}}
{color(0bp)=(cyan!15!white); color(9bp)=(cyan!75!white);
color(18bp)=(cyan!70!black); color(25bp)=(cyan!50!black); color(50bp)=(black)}
pgfdeclareplotmark{crystal ball}{pgfpathcircle{pgfpoint{0ex}{0ex}}{2ex}
pgfshadepath{ballshading}{0}
pgfusepath{}}
begin{document}
begin{tikzpicture}
% Compute camera unit vector for calculating depth
pgfmathsetmacro{CameraX}{sin(ViewAzimuth)*cos(ViewElevation)}
pgfmathsetmacro{CameraY}{-cos(ViewAzimuth)*cos(ViewElevation)}
pgfmathsetmacro{CameraZ}{sin(ViewElevation)}
pgfmathsetmacro{R}{12}
path[use as bounding box] (-R,-R) rectangle (R,R); % Avoid jittering animation
% Draw a nice looking sphere
begin{scope}
clip (0,0) circle (R);
begin{scope}[transform canvas={rotate=-20}]
shade [ball color=white] (0,0.5) ellipse (R*1.8 and R*1.5);
end{scope}
end{scope}
begin{axis}[
hide axis,
view={ViewAzimuth}{ViewElevation}, % Set view angle
every axis plot/.style={very thin},
disabledatascaling, % Align PGFPlots coordinates with TikZ
anchor=origin, % Align PGFPlots coordinates with TikZ
viewport={ViewAzimuth}{ViewElevation}, % Align PGFPlots coordinates with TikZ
]
% plot latitude circles
pgfplotsinvokeforeach{-75,-45,...,75}
{addFGBGplot[spring,domain=0:2*pi, samples=51, samples y=1]
({R*cos(#1)*cos(deg(x))}, {R*cos(#1)*sin(deg(x))}, {R*sin(#1)});}
% plot longitude circles
pgfplotsinvokeforeach{0,30,...,150}
{addFGBGplot[spring,domain=0:2*pi, samples=51, samples y=1]
({R*cos(#1)*cos(deg(x))}, {R*sin(#1)*cos(deg(x))}, {R*sin(deg(x))});
}
% plot longitude circles
pgfplotsinvokeforeach{0,30,...,330}
{addFGBGSampleplot[only marks,mark=crystal ball,samples at={-75,-45,...,75}]
({R*cos(#1)*cos(x)}, {R*sin(#1)*cos(x)}, {R*sin(x)});
}
end{axis}
end{tikzpicture}
end{document}
1
I do not believe this solves the problem, OP wanted to draw this on a "(...) convex surface, such as spherical one."
– caverac
Dec 17 '18 at 12:08
1
@caverac Better now?
– marmot
Dec 17 '18 at 12:53
1
Outstanding as always (+1)
– caverac
Dec 17 '18 at 13:01
1
Wow, that was unexpectedly quick - I am impressed. Thank you greatly for the help with this matter. I am not that much familiar with tikz-plots (rather with pstricks), but I shall certainly have to be after this. Is there any possibility to have the lattice spanned across the entire sphere coloured in grey? Many many thanks to @marmot and caverac too.
– Savchenko
Dec 17 '18 at 15:49
1
This answer should be one of the requirements of PhD in TikZ
– Diaa
Dec 17 '18 at 20:26
|
show 6 more comments
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f466183%2fdrawing-a-2d-square-lattice-springs-balls-on-a-convex-surface%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Welcome to TeX.SE! Here is a proposal.
documentclass[tikz,border=3.14mm]{standalone}
usetikzlibrary{decorations.pathmorphing}
begin{document}
begin{tikzpicture}
clip (-1,-1) rectangle (11,11);
foreach X in {-2,0,...,10}
{foreach Y in {-2,0,...,10}
{draw[decorate,decoration={coil,aspect=0.5,amplitude=1.5mm, segment
length=1.5mm}] (X,Y) -- ++(0,2) -- ++(2,0);
node[circle,text=white,font=sffamilybfserieslarge,inner
color=blue,outer color=black] at (X,Y) {+};}}
end{tikzpicture}
end{document}
It is straightforward to embed this into a spherical coordinate system. (Big thanks to @caverac for pointing out what the question really is.)
documentclass[tikz,border=3.14mm]{standalone}
usepackage{tikz-3dplot}
usetikzlibrary{decorations.pathmorphing,calc}
makeatletter
%from https://tex.stackexchange.com/a/375604/121799
%along x axis
define@key{x sphericalkeys}{radius}{defmyradius{#1}}
define@key{x sphericalkeys}{theta}{defmytheta{#1}}
define@key{x sphericalkeys}{phi}{defmyphi{#1}}
tikzdeclarecoordinatesystem{x spherical}{% %%%rotation around x
setkeys{x sphericalkeys}{#1}%
pgfpointxyz{myradius*cos(mytheta)}{myradius*sin(mytheta)*cos(myphi)}{myradius*sin(mytheta)*sin(myphi)}}
%along y axis
define@key{y sphericalkeys}{radius}{defmyradius{#1}}
define@key{y sphericalkeys}{theta}{defmytheta{#1}}
define@key{y sphericalkeys}{phi}{defmyphi{#1}}
tikzdeclarecoordinatesystem{y spherical}{% %%%rotation around x
setkeys{y sphericalkeys}{#1}%
pgfpointxyz{myradius*sin(mytheta)*cos(myphi)}{myradius*cos(mytheta)}{myradius*sin(mytheta)*sin(myphi)}}
%along z axis
define@key{z sphericalkeys}{radius}{defmyradius{#1}}
define@key{z sphericalkeys}{theta}{defmytheta{#1}}
define@key{z sphericalkeys}{phi}{defmyphi{#1}}
tikzdeclarecoordinatesystem{z spherical}{% %%%rotation around x
setkeys{z sphericalkeys}{#1}%
pgfpointxyz{myradius*sin(mytheta)*cos(myphi)}{myradius*sin(mytheta)*sin(myphi)}{myradius*cos(mytheta)}}
makeatother % https://tex.stackexchange.com/a/438695/121799
begin{document}
tdplotsetmaincoords{70}{130}
begin{tikzpicture}[tdplot_main_coords]
pgfmathsetmacro{R}{16}
path[clip]
plot[variable=x,domain=2.5:52.5]
(z spherical cs:radius=R,theta=80-2.5,phi=x)
-- plot[variable=x,domain=2.5:52.5]
(z spherical cs:radius=R,theta=80-x,phi=52.5)
-- plot[variable=x,domain=52.5:2.5]
(z spherical cs:radius=R,theta=80-52.5,phi=x)
-- plot[variable=x,domain=52.5:2.5]
(z spherical cs:radius=R,theta=80-x,phi=2.5);
foreach X in {0,5,...,55}
{draw[decorate,decoration={coil,aspect=0.5,amplitude=1.5mm, segment
length=1.5mm}] plot[variable=x,domain=0:55]
(z spherical cs:radius=R,theta=80-X,phi=x);
draw[decorate,decoration={coil,aspect=0.5,amplitude=1.5mm, segment
length=1.5mm}] plot[variable=x,domain=0:55]
(z spherical cs:radius=R,theta=80-x,phi=X);
}
foreach X in {5,10,...,50}
{foreach Y in {5,10,...,50}
{path let p1=($(z spherical cs:radius=R,theta=80-X+1,phi=Y)-(z
spherical cs:radius=R,theta=80-X,phi=Y)$),
p2=($(z spherical cs:radius=R,theta=80-X,phi=Y+1)-(z
spherical cs:radius=R,theta=80-X,phi=Y)$),
n1={veclen(x1,y1)/12},n2={veclen(x2,y2)/12},n3={sqrt(n1*n2)}
in %pgfextra{typeout{X,Y:n1,n2}}
node[scale=n3,transform shape,circle,text=white,font=sffamilybfserieslarge,inner
color=blue,outer color=black] at (z spherical cs:radius=R,theta=80-X,phi=Y) {+};}}
end{tikzpicture}
end{document}
As for your additional request: yes, it is possible. However, things depend on what you really want to achieve in the end. Here I present some example that heavily relies on Fritz's stellar answer. However, when trying to polish it by drawing things on different layers, I encountered unexpected problems. In any case, I have no idea what your real aim is. (See e.g. this great post for additional possibilities.) I would kindly like to ask you to make additional requests in form of a new question, which list all the requirements. Asking questions is free, after all. I leave you with
documentclass[border=3.14mm,tikz]{standalone}
usepackage{pgfplots}
usepackage{xxcolor}
pgfplotsset{compat=1.16}
usetikzlibrary{decorations.pathmorphing,decorations.markings}
% Declare nice sphere shading: http://tex.stackexchange.com/a/54239/12440
pgfdeclareradialshading[tikz@ball]{ball}{pgfqpoint{0bp}{0bp}}{%
color(0bp)=(tikz@ball!0!white);
color(7bp)=(tikz@ball!0!white);
color(15bp)=(tikz@ball!70!black);
color(20bp)=(black!70);
color(30bp)=(black!70)}
makeatother
% Style to set TikZ camera angle, like PGFPlots `view`
tikzset{viewport/.style 2 args={
x={({cos(-#1)*1cm},{sin(-#1)*sin(#2)*1cm})},
y={({-sin(-#1)*1cm},{cos(-#1)*sin(#2)*1cm})},
z={(0,{cos(#2)*1cm})}
}}
% Styles to plot only points that are before or behind the sphere.
pgfplotsset{only foreground/.style={
restrict expr to domain={rawx*CameraX + rawy*CameraY + rawz*CameraZ}{-0.05:100},
}}
pgfplotsset{only background/.style={
restrict expr to domain={rawx*CameraX + rawy*CameraY + rawz*CameraZ}{-100:0.05}
}}
% Automatically plot transparent lines in background and solid lines in foreground
defaddFGBGplot[#1]#2;{
addplot3[#1,only background, opacity=0.25] #2;
addplot3[#1,only foreground] #2;
}
% attempt to do similar things for discrete plots
defaddFGBGSampleplot[#1]#2;{
%addplot3[#1,only background,gray!50] #2;
addplot3[#1,only foreground] #2;
}
newcommand{ViewAzimuth}{-30}
newcommand{ViewElevation}{30}
tikzset{spring/.style={decorate,decoration={coil,aspect=0.5,amplitude=1.5mm, segment
length=1.5mm}}}
% pgfmanual p. 1087
pgfdeclareradialshading{ballshading}{pgfpoint{-10bp}{10bp}}
{color(0bp)=(cyan!15!white); color(9bp)=(cyan!75!white);
color(18bp)=(cyan!70!black); color(25bp)=(cyan!50!black); color(50bp)=(black)}
pgfdeclareplotmark{crystal ball}{pgfpathcircle{pgfpoint{0ex}{0ex}}{2ex}
pgfshadepath{ballshading}{0}
pgfusepath{}}
begin{document}
begin{tikzpicture}
% Compute camera unit vector for calculating depth
pgfmathsetmacro{CameraX}{sin(ViewAzimuth)*cos(ViewElevation)}
pgfmathsetmacro{CameraY}{-cos(ViewAzimuth)*cos(ViewElevation)}
pgfmathsetmacro{CameraZ}{sin(ViewElevation)}
pgfmathsetmacro{R}{12}
path[use as bounding box] (-R,-R) rectangle (R,R); % Avoid jittering animation
% Draw a nice looking sphere
begin{scope}
clip (0,0) circle (R);
begin{scope}[transform canvas={rotate=-20}]
shade [ball color=white] (0,0.5) ellipse (R*1.8 and R*1.5);
end{scope}
end{scope}
begin{axis}[
hide axis,
view={ViewAzimuth}{ViewElevation}, % Set view angle
every axis plot/.style={very thin},
disabledatascaling, % Align PGFPlots coordinates with TikZ
anchor=origin, % Align PGFPlots coordinates with TikZ
viewport={ViewAzimuth}{ViewElevation}, % Align PGFPlots coordinates with TikZ
]
% plot latitude circles
pgfplotsinvokeforeach{-75,-45,...,75}
{addFGBGplot[spring,domain=0:2*pi, samples=51, samples y=1]
({R*cos(#1)*cos(deg(x))}, {R*cos(#1)*sin(deg(x))}, {R*sin(#1)});}
% plot longitude circles
pgfplotsinvokeforeach{0,30,...,150}
{addFGBGplot[spring,domain=0:2*pi, samples=51, samples y=1]
({R*cos(#1)*cos(deg(x))}, {R*sin(#1)*cos(deg(x))}, {R*sin(deg(x))});
}
% plot longitude circles
pgfplotsinvokeforeach{0,30,...,330}
{addFGBGSampleplot[only marks,mark=crystal ball,samples at={-75,-45,...,75}]
({R*cos(#1)*cos(x)}, {R*sin(#1)*cos(x)}, {R*sin(x)});
}
end{axis}
end{tikzpicture}
end{document}
1
I do not believe this solves the problem, OP wanted to draw this on a "(...) convex surface, such as spherical one."
– caverac
Dec 17 '18 at 12:08
1
@caverac Better now?
– marmot
Dec 17 '18 at 12:53
1
Outstanding as always (+1)
– caverac
Dec 17 '18 at 13:01
1
Wow, that was unexpectedly quick - I am impressed. Thank you greatly for the help with this matter. I am not that much familiar with tikz-plots (rather with pstricks), but I shall certainly have to be after this. Is there any possibility to have the lattice spanned across the entire sphere coloured in grey? Many many thanks to @marmot and caverac too.
– Savchenko
Dec 17 '18 at 15:49
1
This answer should be one of the requirements of PhD in TikZ
– Diaa
Dec 17 '18 at 20:26
|
show 6 more comments
Welcome to TeX.SE! Here is a proposal.
documentclass[tikz,border=3.14mm]{standalone}
usetikzlibrary{decorations.pathmorphing}
begin{document}
begin{tikzpicture}
clip (-1,-1) rectangle (11,11);
foreach X in {-2,0,...,10}
{foreach Y in {-2,0,...,10}
{draw[decorate,decoration={coil,aspect=0.5,amplitude=1.5mm, segment
length=1.5mm}] (X,Y) -- ++(0,2) -- ++(2,0);
node[circle,text=white,font=sffamilybfserieslarge,inner
color=blue,outer color=black] at (X,Y) {+};}}
end{tikzpicture}
end{document}
It is straightforward to embed this into a spherical coordinate system. (Big thanks to @caverac for pointing out what the question really is.)
documentclass[tikz,border=3.14mm]{standalone}
usepackage{tikz-3dplot}
usetikzlibrary{decorations.pathmorphing,calc}
makeatletter
%from https://tex.stackexchange.com/a/375604/121799
%along x axis
define@key{x sphericalkeys}{radius}{defmyradius{#1}}
define@key{x sphericalkeys}{theta}{defmytheta{#1}}
define@key{x sphericalkeys}{phi}{defmyphi{#1}}
tikzdeclarecoordinatesystem{x spherical}{% %%%rotation around x
setkeys{x sphericalkeys}{#1}%
pgfpointxyz{myradius*cos(mytheta)}{myradius*sin(mytheta)*cos(myphi)}{myradius*sin(mytheta)*sin(myphi)}}
%along y axis
define@key{y sphericalkeys}{radius}{defmyradius{#1}}
define@key{y sphericalkeys}{theta}{defmytheta{#1}}
define@key{y sphericalkeys}{phi}{defmyphi{#1}}
tikzdeclarecoordinatesystem{y spherical}{% %%%rotation around x
setkeys{y sphericalkeys}{#1}%
pgfpointxyz{myradius*sin(mytheta)*cos(myphi)}{myradius*cos(mytheta)}{myradius*sin(mytheta)*sin(myphi)}}
%along z axis
define@key{z sphericalkeys}{radius}{defmyradius{#1}}
define@key{z sphericalkeys}{theta}{defmytheta{#1}}
define@key{z sphericalkeys}{phi}{defmyphi{#1}}
tikzdeclarecoordinatesystem{z spherical}{% %%%rotation around x
setkeys{z sphericalkeys}{#1}%
pgfpointxyz{myradius*sin(mytheta)*cos(myphi)}{myradius*sin(mytheta)*sin(myphi)}{myradius*cos(mytheta)}}
makeatother % https://tex.stackexchange.com/a/438695/121799
begin{document}
tdplotsetmaincoords{70}{130}
begin{tikzpicture}[tdplot_main_coords]
pgfmathsetmacro{R}{16}
path[clip]
plot[variable=x,domain=2.5:52.5]
(z spherical cs:radius=R,theta=80-2.5,phi=x)
-- plot[variable=x,domain=2.5:52.5]
(z spherical cs:radius=R,theta=80-x,phi=52.5)
-- plot[variable=x,domain=52.5:2.5]
(z spherical cs:radius=R,theta=80-52.5,phi=x)
-- plot[variable=x,domain=52.5:2.5]
(z spherical cs:radius=R,theta=80-x,phi=2.5);
foreach X in {0,5,...,55}
{draw[decorate,decoration={coil,aspect=0.5,amplitude=1.5mm, segment
length=1.5mm}] plot[variable=x,domain=0:55]
(z spherical cs:radius=R,theta=80-X,phi=x);
draw[decorate,decoration={coil,aspect=0.5,amplitude=1.5mm, segment
length=1.5mm}] plot[variable=x,domain=0:55]
(z spherical cs:radius=R,theta=80-x,phi=X);
}
foreach X in {5,10,...,50}
{foreach Y in {5,10,...,50}
{path let p1=($(z spherical cs:radius=R,theta=80-X+1,phi=Y)-(z
spherical cs:radius=R,theta=80-X,phi=Y)$),
p2=($(z spherical cs:radius=R,theta=80-X,phi=Y+1)-(z
spherical cs:radius=R,theta=80-X,phi=Y)$),
n1={veclen(x1,y1)/12},n2={veclen(x2,y2)/12},n3={sqrt(n1*n2)}
in %pgfextra{typeout{X,Y:n1,n2}}
node[scale=n3,transform shape,circle,text=white,font=sffamilybfserieslarge,inner
color=blue,outer color=black] at (z spherical cs:radius=R,theta=80-X,phi=Y) {+};}}
end{tikzpicture}
end{document}
As for your additional request: yes, it is possible. However, things depend on what you really want to achieve in the end. Here I present some example that heavily relies on Fritz's stellar answer. However, when trying to polish it by drawing things on different layers, I encountered unexpected problems. In any case, I have no idea what your real aim is. (See e.g. this great post for additional possibilities.) I would kindly like to ask you to make additional requests in form of a new question, which list all the requirements. Asking questions is free, after all. I leave you with
documentclass[border=3.14mm,tikz]{standalone}
usepackage{pgfplots}
usepackage{xxcolor}
pgfplotsset{compat=1.16}
usetikzlibrary{decorations.pathmorphing,decorations.markings}
% Declare nice sphere shading: http://tex.stackexchange.com/a/54239/12440
pgfdeclareradialshading[tikz@ball]{ball}{pgfqpoint{0bp}{0bp}}{%
color(0bp)=(tikz@ball!0!white);
color(7bp)=(tikz@ball!0!white);
color(15bp)=(tikz@ball!70!black);
color(20bp)=(black!70);
color(30bp)=(black!70)}
makeatother
% Style to set TikZ camera angle, like PGFPlots `view`
tikzset{viewport/.style 2 args={
x={({cos(-#1)*1cm},{sin(-#1)*sin(#2)*1cm})},
y={({-sin(-#1)*1cm},{cos(-#1)*sin(#2)*1cm})},
z={(0,{cos(#2)*1cm})}
}}
% Styles to plot only points that are before or behind the sphere.
pgfplotsset{only foreground/.style={
restrict expr to domain={rawx*CameraX + rawy*CameraY + rawz*CameraZ}{-0.05:100},
}}
pgfplotsset{only background/.style={
restrict expr to domain={rawx*CameraX + rawy*CameraY + rawz*CameraZ}{-100:0.05}
}}
% Automatically plot transparent lines in background and solid lines in foreground
defaddFGBGplot[#1]#2;{
addplot3[#1,only background, opacity=0.25] #2;
addplot3[#1,only foreground] #2;
}
% attempt to do similar things for discrete plots
defaddFGBGSampleplot[#1]#2;{
%addplot3[#1,only background,gray!50] #2;
addplot3[#1,only foreground] #2;
}
newcommand{ViewAzimuth}{-30}
newcommand{ViewElevation}{30}
tikzset{spring/.style={decorate,decoration={coil,aspect=0.5,amplitude=1.5mm, segment
length=1.5mm}}}
% pgfmanual p. 1087
pgfdeclareradialshading{ballshading}{pgfpoint{-10bp}{10bp}}
{color(0bp)=(cyan!15!white); color(9bp)=(cyan!75!white);
color(18bp)=(cyan!70!black); color(25bp)=(cyan!50!black); color(50bp)=(black)}
pgfdeclareplotmark{crystal ball}{pgfpathcircle{pgfpoint{0ex}{0ex}}{2ex}
pgfshadepath{ballshading}{0}
pgfusepath{}}
begin{document}
begin{tikzpicture}
% Compute camera unit vector for calculating depth
pgfmathsetmacro{CameraX}{sin(ViewAzimuth)*cos(ViewElevation)}
pgfmathsetmacro{CameraY}{-cos(ViewAzimuth)*cos(ViewElevation)}
pgfmathsetmacro{CameraZ}{sin(ViewElevation)}
pgfmathsetmacro{R}{12}
path[use as bounding box] (-R,-R) rectangle (R,R); % Avoid jittering animation
% Draw a nice looking sphere
begin{scope}
clip (0,0) circle (R);
begin{scope}[transform canvas={rotate=-20}]
shade [ball color=white] (0,0.5) ellipse (R*1.8 and R*1.5);
end{scope}
end{scope}
begin{axis}[
hide axis,
view={ViewAzimuth}{ViewElevation}, % Set view angle
every axis plot/.style={very thin},
disabledatascaling, % Align PGFPlots coordinates with TikZ
anchor=origin, % Align PGFPlots coordinates with TikZ
viewport={ViewAzimuth}{ViewElevation}, % Align PGFPlots coordinates with TikZ
]
% plot latitude circles
pgfplotsinvokeforeach{-75,-45,...,75}
{addFGBGplot[spring,domain=0:2*pi, samples=51, samples y=1]
({R*cos(#1)*cos(deg(x))}, {R*cos(#1)*sin(deg(x))}, {R*sin(#1)});}
% plot longitude circles
pgfplotsinvokeforeach{0,30,...,150}
{addFGBGplot[spring,domain=0:2*pi, samples=51, samples y=1]
({R*cos(#1)*cos(deg(x))}, {R*sin(#1)*cos(deg(x))}, {R*sin(deg(x))});
}
% plot longitude circles
pgfplotsinvokeforeach{0,30,...,330}
{addFGBGSampleplot[only marks,mark=crystal ball,samples at={-75,-45,...,75}]
({R*cos(#1)*cos(x)}, {R*sin(#1)*cos(x)}, {R*sin(x)});
}
end{axis}
end{tikzpicture}
end{document}
1
I do not believe this solves the problem, OP wanted to draw this on a "(...) convex surface, such as spherical one."
– caverac
Dec 17 '18 at 12:08
1
@caverac Better now?
– marmot
Dec 17 '18 at 12:53
1
Outstanding as always (+1)
– caverac
Dec 17 '18 at 13:01
1
Wow, that was unexpectedly quick - I am impressed. Thank you greatly for the help with this matter. I am not that much familiar with tikz-plots (rather with pstricks), but I shall certainly have to be after this. Is there any possibility to have the lattice spanned across the entire sphere coloured in grey? Many many thanks to @marmot and caverac too.
– Savchenko
Dec 17 '18 at 15:49
1
This answer should be one of the requirements of PhD in TikZ
– Diaa
Dec 17 '18 at 20:26
|
show 6 more comments
Welcome to TeX.SE! Here is a proposal.
documentclass[tikz,border=3.14mm]{standalone}
usetikzlibrary{decorations.pathmorphing}
begin{document}
begin{tikzpicture}
clip (-1,-1) rectangle (11,11);
foreach X in {-2,0,...,10}
{foreach Y in {-2,0,...,10}
{draw[decorate,decoration={coil,aspect=0.5,amplitude=1.5mm, segment
length=1.5mm}] (X,Y) -- ++(0,2) -- ++(2,0);
node[circle,text=white,font=sffamilybfserieslarge,inner
color=blue,outer color=black] at (X,Y) {+};}}
end{tikzpicture}
end{document}
It is straightforward to embed this into a spherical coordinate system. (Big thanks to @caverac for pointing out what the question really is.)
documentclass[tikz,border=3.14mm]{standalone}
usepackage{tikz-3dplot}
usetikzlibrary{decorations.pathmorphing,calc}
makeatletter
%from https://tex.stackexchange.com/a/375604/121799
%along x axis
define@key{x sphericalkeys}{radius}{defmyradius{#1}}
define@key{x sphericalkeys}{theta}{defmytheta{#1}}
define@key{x sphericalkeys}{phi}{defmyphi{#1}}
tikzdeclarecoordinatesystem{x spherical}{% %%%rotation around x
setkeys{x sphericalkeys}{#1}%
pgfpointxyz{myradius*cos(mytheta)}{myradius*sin(mytheta)*cos(myphi)}{myradius*sin(mytheta)*sin(myphi)}}
%along y axis
define@key{y sphericalkeys}{radius}{defmyradius{#1}}
define@key{y sphericalkeys}{theta}{defmytheta{#1}}
define@key{y sphericalkeys}{phi}{defmyphi{#1}}
tikzdeclarecoordinatesystem{y spherical}{% %%%rotation around x
setkeys{y sphericalkeys}{#1}%
pgfpointxyz{myradius*sin(mytheta)*cos(myphi)}{myradius*cos(mytheta)}{myradius*sin(mytheta)*sin(myphi)}}
%along z axis
define@key{z sphericalkeys}{radius}{defmyradius{#1}}
define@key{z sphericalkeys}{theta}{defmytheta{#1}}
define@key{z sphericalkeys}{phi}{defmyphi{#1}}
tikzdeclarecoordinatesystem{z spherical}{% %%%rotation around x
setkeys{z sphericalkeys}{#1}%
pgfpointxyz{myradius*sin(mytheta)*cos(myphi)}{myradius*sin(mytheta)*sin(myphi)}{myradius*cos(mytheta)}}
makeatother % https://tex.stackexchange.com/a/438695/121799
begin{document}
tdplotsetmaincoords{70}{130}
begin{tikzpicture}[tdplot_main_coords]
pgfmathsetmacro{R}{16}
path[clip]
plot[variable=x,domain=2.5:52.5]
(z spherical cs:radius=R,theta=80-2.5,phi=x)
-- plot[variable=x,domain=2.5:52.5]
(z spherical cs:radius=R,theta=80-x,phi=52.5)
-- plot[variable=x,domain=52.5:2.5]
(z spherical cs:radius=R,theta=80-52.5,phi=x)
-- plot[variable=x,domain=52.5:2.5]
(z spherical cs:radius=R,theta=80-x,phi=2.5);
foreach X in {0,5,...,55}
{draw[decorate,decoration={coil,aspect=0.5,amplitude=1.5mm, segment
length=1.5mm}] plot[variable=x,domain=0:55]
(z spherical cs:radius=R,theta=80-X,phi=x);
draw[decorate,decoration={coil,aspect=0.5,amplitude=1.5mm, segment
length=1.5mm}] plot[variable=x,domain=0:55]
(z spherical cs:radius=R,theta=80-x,phi=X);
}
foreach X in {5,10,...,50}
{foreach Y in {5,10,...,50}
{path let p1=($(z spherical cs:radius=R,theta=80-X+1,phi=Y)-(z
spherical cs:radius=R,theta=80-X,phi=Y)$),
p2=($(z spherical cs:radius=R,theta=80-X,phi=Y+1)-(z
spherical cs:radius=R,theta=80-X,phi=Y)$),
n1={veclen(x1,y1)/12},n2={veclen(x2,y2)/12},n3={sqrt(n1*n2)}
in %pgfextra{typeout{X,Y:n1,n2}}
node[scale=n3,transform shape,circle,text=white,font=sffamilybfserieslarge,inner
color=blue,outer color=black] at (z spherical cs:radius=R,theta=80-X,phi=Y) {+};}}
end{tikzpicture}
end{document}
As for your additional request: yes, it is possible. However, things depend on what you really want to achieve in the end. Here I present some example that heavily relies on Fritz's stellar answer. However, when trying to polish it by drawing things on different layers, I encountered unexpected problems. In any case, I have no idea what your real aim is. (See e.g. this great post for additional possibilities.) I would kindly like to ask you to make additional requests in form of a new question, which list all the requirements. Asking questions is free, after all. I leave you with
documentclass[border=3.14mm,tikz]{standalone}
usepackage{pgfplots}
usepackage{xxcolor}
pgfplotsset{compat=1.16}
usetikzlibrary{decorations.pathmorphing,decorations.markings}
% Declare nice sphere shading: http://tex.stackexchange.com/a/54239/12440
pgfdeclareradialshading[tikz@ball]{ball}{pgfqpoint{0bp}{0bp}}{%
color(0bp)=(tikz@ball!0!white);
color(7bp)=(tikz@ball!0!white);
color(15bp)=(tikz@ball!70!black);
color(20bp)=(black!70);
color(30bp)=(black!70)}
makeatother
% Style to set TikZ camera angle, like PGFPlots `view`
tikzset{viewport/.style 2 args={
x={({cos(-#1)*1cm},{sin(-#1)*sin(#2)*1cm})},
y={({-sin(-#1)*1cm},{cos(-#1)*sin(#2)*1cm})},
z={(0,{cos(#2)*1cm})}
}}
% Styles to plot only points that are before or behind the sphere.
pgfplotsset{only foreground/.style={
restrict expr to domain={rawx*CameraX + rawy*CameraY + rawz*CameraZ}{-0.05:100},
}}
pgfplotsset{only background/.style={
restrict expr to domain={rawx*CameraX + rawy*CameraY + rawz*CameraZ}{-100:0.05}
}}
% Automatically plot transparent lines in background and solid lines in foreground
defaddFGBGplot[#1]#2;{
addplot3[#1,only background, opacity=0.25] #2;
addplot3[#1,only foreground] #2;
}
% attempt to do similar things for discrete plots
defaddFGBGSampleplot[#1]#2;{
%addplot3[#1,only background,gray!50] #2;
addplot3[#1,only foreground] #2;
}
newcommand{ViewAzimuth}{-30}
newcommand{ViewElevation}{30}
tikzset{spring/.style={decorate,decoration={coil,aspect=0.5,amplitude=1.5mm, segment
length=1.5mm}}}
% pgfmanual p. 1087
pgfdeclareradialshading{ballshading}{pgfpoint{-10bp}{10bp}}
{color(0bp)=(cyan!15!white); color(9bp)=(cyan!75!white);
color(18bp)=(cyan!70!black); color(25bp)=(cyan!50!black); color(50bp)=(black)}
pgfdeclareplotmark{crystal ball}{pgfpathcircle{pgfpoint{0ex}{0ex}}{2ex}
pgfshadepath{ballshading}{0}
pgfusepath{}}
begin{document}
begin{tikzpicture}
% Compute camera unit vector for calculating depth
pgfmathsetmacro{CameraX}{sin(ViewAzimuth)*cos(ViewElevation)}
pgfmathsetmacro{CameraY}{-cos(ViewAzimuth)*cos(ViewElevation)}
pgfmathsetmacro{CameraZ}{sin(ViewElevation)}
pgfmathsetmacro{R}{12}
path[use as bounding box] (-R,-R) rectangle (R,R); % Avoid jittering animation
% Draw a nice looking sphere
begin{scope}
clip (0,0) circle (R);
begin{scope}[transform canvas={rotate=-20}]
shade [ball color=white] (0,0.5) ellipse (R*1.8 and R*1.5);
end{scope}
end{scope}
begin{axis}[
hide axis,
view={ViewAzimuth}{ViewElevation}, % Set view angle
every axis plot/.style={very thin},
disabledatascaling, % Align PGFPlots coordinates with TikZ
anchor=origin, % Align PGFPlots coordinates with TikZ
viewport={ViewAzimuth}{ViewElevation}, % Align PGFPlots coordinates with TikZ
]
% plot latitude circles
pgfplotsinvokeforeach{-75,-45,...,75}
{addFGBGplot[spring,domain=0:2*pi, samples=51, samples y=1]
({R*cos(#1)*cos(deg(x))}, {R*cos(#1)*sin(deg(x))}, {R*sin(#1)});}
% plot longitude circles
pgfplotsinvokeforeach{0,30,...,150}
{addFGBGplot[spring,domain=0:2*pi, samples=51, samples y=1]
({R*cos(#1)*cos(deg(x))}, {R*sin(#1)*cos(deg(x))}, {R*sin(deg(x))});
}
% plot longitude circles
pgfplotsinvokeforeach{0,30,...,330}
{addFGBGSampleplot[only marks,mark=crystal ball,samples at={-75,-45,...,75}]
({R*cos(#1)*cos(x)}, {R*sin(#1)*cos(x)}, {R*sin(x)});
}
end{axis}
end{tikzpicture}
end{document}
Welcome to TeX.SE! Here is a proposal.
documentclass[tikz,border=3.14mm]{standalone}
usetikzlibrary{decorations.pathmorphing}
begin{document}
begin{tikzpicture}
clip (-1,-1) rectangle (11,11);
foreach X in {-2,0,...,10}
{foreach Y in {-2,0,...,10}
{draw[decorate,decoration={coil,aspect=0.5,amplitude=1.5mm, segment
length=1.5mm}] (X,Y) -- ++(0,2) -- ++(2,0);
node[circle,text=white,font=sffamilybfserieslarge,inner
color=blue,outer color=black] at (X,Y) {+};}}
end{tikzpicture}
end{document}
It is straightforward to embed this into a spherical coordinate system. (Big thanks to @caverac for pointing out what the question really is.)
documentclass[tikz,border=3.14mm]{standalone}
usepackage{tikz-3dplot}
usetikzlibrary{decorations.pathmorphing,calc}
makeatletter
%from https://tex.stackexchange.com/a/375604/121799
%along x axis
define@key{x sphericalkeys}{radius}{defmyradius{#1}}
define@key{x sphericalkeys}{theta}{defmytheta{#1}}
define@key{x sphericalkeys}{phi}{defmyphi{#1}}
tikzdeclarecoordinatesystem{x spherical}{% %%%rotation around x
setkeys{x sphericalkeys}{#1}%
pgfpointxyz{myradius*cos(mytheta)}{myradius*sin(mytheta)*cos(myphi)}{myradius*sin(mytheta)*sin(myphi)}}
%along y axis
define@key{y sphericalkeys}{radius}{defmyradius{#1}}
define@key{y sphericalkeys}{theta}{defmytheta{#1}}
define@key{y sphericalkeys}{phi}{defmyphi{#1}}
tikzdeclarecoordinatesystem{y spherical}{% %%%rotation around x
setkeys{y sphericalkeys}{#1}%
pgfpointxyz{myradius*sin(mytheta)*cos(myphi)}{myradius*cos(mytheta)}{myradius*sin(mytheta)*sin(myphi)}}
%along z axis
define@key{z sphericalkeys}{radius}{defmyradius{#1}}
define@key{z sphericalkeys}{theta}{defmytheta{#1}}
define@key{z sphericalkeys}{phi}{defmyphi{#1}}
tikzdeclarecoordinatesystem{z spherical}{% %%%rotation around x
setkeys{z sphericalkeys}{#1}%
pgfpointxyz{myradius*sin(mytheta)*cos(myphi)}{myradius*sin(mytheta)*sin(myphi)}{myradius*cos(mytheta)}}
makeatother % https://tex.stackexchange.com/a/438695/121799
begin{document}
tdplotsetmaincoords{70}{130}
begin{tikzpicture}[tdplot_main_coords]
pgfmathsetmacro{R}{16}
path[clip]
plot[variable=x,domain=2.5:52.5]
(z spherical cs:radius=R,theta=80-2.5,phi=x)
-- plot[variable=x,domain=2.5:52.5]
(z spherical cs:radius=R,theta=80-x,phi=52.5)
-- plot[variable=x,domain=52.5:2.5]
(z spherical cs:radius=R,theta=80-52.5,phi=x)
-- plot[variable=x,domain=52.5:2.5]
(z spherical cs:radius=R,theta=80-x,phi=2.5);
foreach X in {0,5,...,55}
{draw[decorate,decoration={coil,aspect=0.5,amplitude=1.5mm, segment
length=1.5mm}] plot[variable=x,domain=0:55]
(z spherical cs:radius=R,theta=80-X,phi=x);
draw[decorate,decoration={coil,aspect=0.5,amplitude=1.5mm, segment
length=1.5mm}] plot[variable=x,domain=0:55]
(z spherical cs:radius=R,theta=80-x,phi=X);
}
foreach X in {5,10,...,50}
{foreach Y in {5,10,...,50}
{path let p1=($(z spherical cs:radius=R,theta=80-X+1,phi=Y)-(z
spherical cs:radius=R,theta=80-X,phi=Y)$),
p2=($(z spherical cs:radius=R,theta=80-X,phi=Y+1)-(z
spherical cs:radius=R,theta=80-X,phi=Y)$),
n1={veclen(x1,y1)/12},n2={veclen(x2,y2)/12},n3={sqrt(n1*n2)}
in %pgfextra{typeout{X,Y:n1,n2}}
node[scale=n3,transform shape,circle,text=white,font=sffamilybfserieslarge,inner
color=blue,outer color=black] at (z spherical cs:radius=R,theta=80-X,phi=Y) {+};}}
end{tikzpicture}
end{document}
As for your additional request: yes, it is possible. However, things depend on what you really want to achieve in the end. Here I present some example that heavily relies on Fritz's stellar answer. However, when trying to polish it by drawing things on different layers, I encountered unexpected problems. In any case, I have no idea what your real aim is. (See e.g. this great post for additional possibilities.) I would kindly like to ask you to make additional requests in form of a new question, which list all the requirements. Asking questions is free, after all. I leave you with
documentclass[border=3.14mm,tikz]{standalone}
usepackage{pgfplots}
usepackage{xxcolor}
pgfplotsset{compat=1.16}
usetikzlibrary{decorations.pathmorphing,decorations.markings}
% Declare nice sphere shading: http://tex.stackexchange.com/a/54239/12440
pgfdeclareradialshading[tikz@ball]{ball}{pgfqpoint{0bp}{0bp}}{%
color(0bp)=(tikz@ball!0!white);
color(7bp)=(tikz@ball!0!white);
color(15bp)=(tikz@ball!70!black);
color(20bp)=(black!70);
color(30bp)=(black!70)}
makeatother
% Style to set TikZ camera angle, like PGFPlots `view`
tikzset{viewport/.style 2 args={
x={({cos(-#1)*1cm},{sin(-#1)*sin(#2)*1cm})},
y={({-sin(-#1)*1cm},{cos(-#1)*sin(#2)*1cm})},
z={(0,{cos(#2)*1cm})}
}}
% Styles to plot only points that are before or behind the sphere.
pgfplotsset{only foreground/.style={
restrict expr to domain={rawx*CameraX + rawy*CameraY + rawz*CameraZ}{-0.05:100},
}}
pgfplotsset{only background/.style={
restrict expr to domain={rawx*CameraX + rawy*CameraY + rawz*CameraZ}{-100:0.05}
}}
% Automatically plot transparent lines in background and solid lines in foreground
defaddFGBGplot[#1]#2;{
addplot3[#1,only background, opacity=0.25] #2;
addplot3[#1,only foreground] #2;
}
% attempt to do similar things for discrete plots
defaddFGBGSampleplot[#1]#2;{
%addplot3[#1,only background,gray!50] #2;
addplot3[#1,only foreground] #2;
}
newcommand{ViewAzimuth}{-30}
newcommand{ViewElevation}{30}
tikzset{spring/.style={decorate,decoration={coil,aspect=0.5,amplitude=1.5mm, segment
length=1.5mm}}}
% pgfmanual p. 1087
pgfdeclareradialshading{ballshading}{pgfpoint{-10bp}{10bp}}
{color(0bp)=(cyan!15!white); color(9bp)=(cyan!75!white);
color(18bp)=(cyan!70!black); color(25bp)=(cyan!50!black); color(50bp)=(black)}
pgfdeclareplotmark{crystal ball}{pgfpathcircle{pgfpoint{0ex}{0ex}}{2ex}
pgfshadepath{ballshading}{0}
pgfusepath{}}
begin{document}
begin{tikzpicture}
% Compute camera unit vector for calculating depth
pgfmathsetmacro{CameraX}{sin(ViewAzimuth)*cos(ViewElevation)}
pgfmathsetmacro{CameraY}{-cos(ViewAzimuth)*cos(ViewElevation)}
pgfmathsetmacro{CameraZ}{sin(ViewElevation)}
pgfmathsetmacro{R}{12}
path[use as bounding box] (-R,-R) rectangle (R,R); % Avoid jittering animation
% Draw a nice looking sphere
begin{scope}
clip (0,0) circle (R);
begin{scope}[transform canvas={rotate=-20}]
shade [ball color=white] (0,0.5) ellipse (R*1.8 and R*1.5);
end{scope}
end{scope}
begin{axis}[
hide axis,
view={ViewAzimuth}{ViewElevation}, % Set view angle
every axis plot/.style={very thin},
disabledatascaling, % Align PGFPlots coordinates with TikZ
anchor=origin, % Align PGFPlots coordinates with TikZ
viewport={ViewAzimuth}{ViewElevation}, % Align PGFPlots coordinates with TikZ
]
% plot latitude circles
pgfplotsinvokeforeach{-75,-45,...,75}
{addFGBGplot[spring,domain=0:2*pi, samples=51, samples y=1]
({R*cos(#1)*cos(deg(x))}, {R*cos(#1)*sin(deg(x))}, {R*sin(#1)});}
% plot longitude circles
pgfplotsinvokeforeach{0,30,...,150}
{addFGBGplot[spring,domain=0:2*pi, samples=51, samples y=1]
({R*cos(#1)*cos(deg(x))}, {R*sin(#1)*cos(deg(x))}, {R*sin(deg(x))});
}
% plot longitude circles
pgfplotsinvokeforeach{0,30,...,330}
{addFGBGSampleplot[only marks,mark=crystal ball,samples at={-75,-45,...,75}]
({R*cos(#1)*cos(x)}, {R*sin(#1)*cos(x)}, {R*sin(x)});
}
end{axis}
end{tikzpicture}
end{document}
edited Dec 17 '18 at 20:23
answered Dec 17 '18 at 11:36
marmotmarmot
101k4117226
101k4117226
1
I do not believe this solves the problem, OP wanted to draw this on a "(...) convex surface, such as spherical one."
– caverac
Dec 17 '18 at 12:08
1
@caverac Better now?
– marmot
Dec 17 '18 at 12:53
1
Outstanding as always (+1)
– caverac
Dec 17 '18 at 13:01
1
Wow, that was unexpectedly quick - I am impressed. Thank you greatly for the help with this matter. I am not that much familiar with tikz-plots (rather with pstricks), but I shall certainly have to be after this. Is there any possibility to have the lattice spanned across the entire sphere coloured in grey? Many many thanks to @marmot and caverac too.
– Savchenko
Dec 17 '18 at 15:49
1
This answer should be one of the requirements of PhD in TikZ
– Diaa
Dec 17 '18 at 20:26
|
show 6 more comments
1
I do not believe this solves the problem, OP wanted to draw this on a "(...) convex surface, such as spherical one."
– caverac
Dec 17 '18 at 12:08
1
@caverac Better now?
– marmot
Dec 17 '18 at 12:53
1
Outstanding as always (+1)
– caverac
Dec 17 '18 at 13:01
1
Wow, that was unexpectedly quick - I am impressed. Thank you greatly for the help with this matter. I am not that much familiar with tikz-plots (rather with pstricks), but I shall certainly have to be after this. Is there any possibility to have the lattice spanned across the entire sphere coloured in grey? Many many thanks to @marmot and caverac too.
– Savchenko
Dec 17 '18 at 15:49
1
This answer should be one of the requirements of PhD in TikZ
– Diaa
Dec 17 '18 at 20:26
1
1
I do not believe this solves the problem, OP wanted to draw this on a "(...) convex surface, such as spherical one."
– caverac
Dec 17 '18 at 12:08
I do not believe this solves the problem, OP wanted to draw this on a "(...) convex surface, such as spherical one."
– caverac
Dec 17 '18 at 12:08
1
1
@caverac Better now?
– marmot
Dec 17 '18 at 12:53
@caverac Better now?
– marmot
Dec 17 '18 at 12:53
1
1
Outstanding as always (+1)
– caverac
Dec 17 '18 at 13:01
Outstanding as always (+1)
– caverac
Dec 17 '18 at 13:01
1
1
Wow, that was unexpectedly quick - I am impressed. Thank you greatly for the help with this matter. I am not that much familiar with tikz-plots (rather with pstricks), but I shall certainly have to be after this. Is there any possibility to have the lattice spanned across the entire sphere coloured in grey? Many many thanks to @marmot and caverac too.
– Savchenko
Dec 17 '18 at 15:49
Wow, that was unexpectedly quick - I am impressed. Thank you greatly for the help with this matter. I am not that much familiar with tikz-plots (rather with pstricks), but I shall certainly have to be after this. Is there any possibility to have the lattice spanned across the entire sphere coloured in grey? Many many thanks to @marmot and caverac too.
– Savchenko
Dec 17 '18 at 15:49
1
1
This answer should be one of the requirements of PhD in TikZ
– Diaa
Dec 17 '18 at 20:26
This answer should be one of the requirements of PhD in TikZ
– Diaa
Dec 17 '18 at 20:26
|
show 6 more comments
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f466183%2fdrawing-a-2d-square-lattice-springs-balls-on-a-convex-surface%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Welcome to TeX.SX. Questions about how to draw specific graphics that just post an image of the desired result are really not reasonable questions to ask on the site. Please post a minimal compilable document showing that you've tried to produce the image and then people will be happy to help you with any specific problems you may have. See minimal working example (MWE) for what needs to go into such a document.
– Stefan Pinnow
Dec 17 '18 at 10:49
Thank you @Stefan Pinnow. I'll follow your suggestion and I will write a new question tagging this one.
– Savchenko
Dec 17 '18 at 23:24