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



enter image description here


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



enter image description here


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



enter image description here



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.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)