3d emulation with tikz
3d emulation with tikz
I am trying to draw a 3d arbitrary volume using tikz
.
The 2d equivalent is like(courtesy: this):
tikz
beginframe
begintikzpicture
pgfmathsetseed3
draw[fill=blue!70] plot [smooth cycle, samples=8,domain=1:8]
(x*360/8+5*rnd:0.5cm+1cm*rnd) node at (0,0) ;
endtikzpicture
endframe
Is it possible to give it a 3d feeling? like a diffused lighting effect or something?
2 Answers
2
Here is an option using shade
and the ball
preset
shade
ball
documentclass[tikz,margin=0.5cm]standalone
begindocument
begintikzpicture
pgfmathsetseed3
shade [ball color=blue!70] plot [smooth cycle, samples=8,domain=1:8]
(x*360/8+5*rnd:0.5cm+1cm*rnd);
endtikzpicture
enddocument
Some more examples
documentclass[tikz,margin=0.5cm]standalone
begindocument
begintikzpicture
pgfmathsetmacroS3
foreach X in 1,...,3
foreach Y in 1,...,3
beginscope[shift=(S*X,S*Y)]
shade [ball color=blue!70] plot [smooth cycle, samples=8,domain=1:8]
(x*360/8+5*rnd:0.5cm+1cm*rnd);
endscope
endtikzpicture
enddocument
A very small addendum to Milo's great answer: sometimes you want the bright spot not to be where shade[ball color=...]...
puts it. You could either define your own shading, or, what is perhaps simpler, clip a circle with a shifted center against that shape. The following animation is supposed to give you an idea what's possible. In the end, you will have to decide on your own what looks realistic, or switch to asymptote
, which computes realistic shadings for you.
shade[ball color=...]...
asymptote
documentclass[tikz,margin=0.5cm]standalone
begindocument
foreach X in 1,2,...,42
begintikzpicture
pgfmathsetseedX
path[use as bounding box] (-4,-4) rectangle (4,4);
clip plot [smooth cycle, samples=8,domain=1:8]
(x*360/8+5*rnd:0.5cm+1cm*rnd);
shade [ball color=blue!70] (0.5+rnd,-0.5+rnd) circle (3cm);
endtikzpicture
enddocument
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
But avoid …
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.