How to draw circles in an arbitrary plane

How to draw circles in an arbitrary plane



I would like to generate the following image of TikZ:



The closest resemblance on the examples is this post. However, I am not sure how to add the circles in the plane of the cubes. Any help is appreciated.





Welcome to TeX.SX! The short answer is that, yes, this is possible but I have to warn you that questions of the form "Please draw this for me" that show no effort on the part of OP, often don't get answered. You will get more help if you post some code showing what you have tried and give a minimal working example. A quick search on TeX.SX for drawing functions (with tikz or pstricks) will give you an idea of where to start from.
– Andrew
Aug 22 at 11:51





@Andrew Even though I agree with you to a large extent, I somehow cannot refrain from making a comment. If the OP would have just copied the code under the link, not disclosed its source, and posted it as his MWE, he would be drowning in upvotes. I personally like an honest reference and an honest "I am not sure how to add the circles in the plane of the cubes" better than the alternative which one sometimes encounters. I think the OP has done his homework, i.e. done some research, and asked a very clear question.
– marmot
Aug 22 at 18:42





@marmot In an ideal world the OP would post the code they found and give the link. The problem, as always, with external links is that they are likely to disappear at some point, significantly weakening the question.
– Andrew
Aug 22 at 20:41






@Andrew I fully agree with that statement, but given the world we live in I would like to argue that the present question is actually quite nice. It is clear and honest. Of course, like in most posts, there is room for improvement.
– marmot
Aug 22 at 21:29





@Andrew, thank you for the comments! I hadn't thought of the longevity of the post and the problem external posts may have in the long run. Any future posts will take this into account.
– Sid
Aug 23 at 8:44




1 Answer
1


documentclass[tikz,border=3.14mm]standalone
usetikzlibrary3d,decorations.markings,calc
usepackagetikz-3dplot
makeatletter % https://tex.stackexchange.com/a/48776/121799
tikzoptioncanvas is xy plane at z%
deftikz@plane@originpgfpointxyz00#1%
deftikz@plane@xpgfpointxyz10#1%
deftikz@plane@ypgfpointxyz01#1%
tikz@canvas@is@plane

makeatother

begindocument
foreach X in -50
tdplotsetmaincoords110X
begintikzpicture
%path[use as bounding box] (-6,-3) rectangle (6,5);
%node[anchor=north west] at (-6,5) X,xtest,ytest;
beginscope[tdplot_main_coords]
% ray in the back
draw [thick,blue,postaction=decorate,decoration=markings,mark=at position 0.2
with arrowstealth;] (-6,0,0) -- (0,0,0);
% back
filldraw[cyan,fill opacity=0.3] (-0.5,-2,-2) -- (-0.5,2,-2) -- (-0.5,2,2)
-- (-0.5,-2,2) -- cycle;
% bottom
filldraw[cyan,fill opacity=0.3] (0,-2,-2) -- (-0.5,-2,-2) -- (-0.5,2,-2)
-- (0,2,-2) -- cycle;
% right
filldraw[cyan,fill opacity=0.1] (0,2,-2) -- (-0.5,2,-2) -- (-0.5,2,2)
-- (0,2,2) -- cycle;
% left
filldraw[cyan,fill opacity=0.3] (0,-2,-2) -- (-0.5,-2,-2) -- (-0.5,-2,2)
-- (0,-2,2) -- cycle;
% top
filldraw[cyan,fill opacity=0.1] (0,-2,2) -- (-0.5,-2,2) -- (-0.5,2,2)
-- (0,2,2) -- cycle;
%front
filldraw[cyan,fill opacity=0.1] (0,-2,-2) -- (0,2,-2) -- (0,2,2)
-- (0,-2,2) -- cycle;
% ray in front
draw[thick,blue] (0,0,0) -- (8,0,0);
beginscope[canvas is yz plane at x=8,xscale=-1,transform shape]
draw[gray] (-4,0) -- (4,0);
draw[gray] (0,-4) -- (0,4);
draw[red,thick] (0,0) circle (2);
node[circle,fill,red,inner sep=2pt] (A) at (45:2);
node[circle,fill,red,inner sep=2pt] (B) at (-135:2);
draw[gray] (A) circle (4.5pt) (B) circle (4.5pt);
draw[gray,shorten >=1.5pt,shorten <=1.5pt] (A)--(B);
endscope
draw[red] (A) -- (0,0,0) (B) -- (0,0,0);
endscope
endtikzpicture

foreach X in -50
tdplotsetmaincoords110X
begintikzpicture
%path[use as bounding box] (-6,-3) rectangle (6,5);
%node[anchor=north west] at (-6,5) X,xtest,ytest;
beginscope[tdplot_main_coords]
% ray in the back
draw [thick,blue,postaction=decorate,decoration=markings,mark=at position 0.2
with arrowstealth;] (-6,0,0) -- (0,0,0);
% back
filldraw[cyan,fill opacity=0.3] (-0.5,-2,-2) -- (-0.5,2,-2) -- (-0.5,2,2)
-- (-0.5,-2,2) -- cycle;
% bottom
filldraw[cyan,fill opacity=0.3] (0,-2,-2) -- (-0.5,-2,-2) -- (-0.5,2,-2)
-- (0,2,-2) -- cycle;
% right
filldraw[cyan,fill opacity=0.1] (0,2,-2) -- (-0.5,2,-2) -- (-0.5,2,2)
-- (0,2,2) -- cycle;
% left
filldraw[cyan,fill opacity=0.3] (0,-2,-2) -- (-0.5,-2,-2) -- (-0.5,-2,2)
-- (0,-2,2) -- cycle;
% top
filldraw[cyan,fill opacity=0.1] (0,-2,2) -- (-0.5,-2,2) -- (-0.5,2,2)
-- (0,2,2) -- cycle;
%front
filldraw[cyan,fill opacity=0.1] (0,-2,-2) -- (0,2,-2) -- (0,2,2)
-- (0,-2,2) -- cycle;
% ray in front
draw[thick,blue] (0,0,0) -- (8,0,0);
beginscope[canvas is yz plane at x=8,xscale=-1,transform shape]
draw[gray] (-5,0) -- (5,0);
draw[gray] (0,-4) -- (0,4);
draw[red,thick] (1,0) circle (2);
draw[red,thick] (-1,0) circle (2);
node[circle,fill,red,inner sep=2pt] (A) at ($(1,0)+(45:2)$) ;
node[circle,fill,red,inner sep=2pt] (B) at ($(-1,0)+(-135:2)$) ;
draw[gray] (A) circle (4.5pt) (B) circle (4.5pt);
draw[gray,shorten >=1.5pt,shorten <=1.5pt] (A)--(B);
endscope
draw[red] (A) -- (0,0,0) (B) -- (0,0,0);
endscope
endtikzpicture

foreach X in -50
tdplotsetmaincoords110X
begintikzpicture
%path[use as bounding box] (-6,-3) rectangle (6,5);
%node[anchor=north west] at (-6,5) X,xtest,ytest;
beginscope[tdplot_main_coords]
% ray in the back
draw [thick,blue,postaction=decorate,decoration=markings,mark=at position 0.2
with arrowstealth;] (-6,0,0) -- (0,0,0);
% back
filldraw[cyan,fill opacity=0.3] (-0.5,-2,-2) -- (-0.5,2,-2) -- (-0.5,2,2)
-- (-0.5,-2,2) -- cycle;
% bottom
filldraw[cyan,fill opacity=0.3] (0,-2,-2) -- (-0.5,-2,-2) -- (-0.5,2,-2)
-- (0,2,-2) -- cycle;
% right
filldraw[cyan,fill opacity=0.1] (0,2,-2) -- (-0.5,2,-2) -- (-0.5,2,2)
-- (0,2,2) -- cycle;
% left
filldraw[cyan,fill opacity=0.3] (0,-2,-2) -- (-0.5,-2,-2) -- (-0.5,-2,2)
-- (0,-2,2) -- cycle;
% top
filldraw[cyan,fill opacity=0.1] (0,-2,2) -- (-0.5,-2,2) -- (-0.5,2,2)
-- (0,2,2) -- cycle;
%front
filldraw[cyan,fill opacity=0.1] (0,-2,-2) -- (0,2,-2) -- (0,2,2)
-- (0,-2,2) -- cycle;
% ray in front
draw[thick,blue] (0,0,0) -- (8,0,0);
beginscope[canvas is yz plane at x=8,xscale=-1,transform shape]
draw[gray] (-5,0) -- (5,0);
draw[gray] (0,-4) -- (0,4);
draw[red,thick] (2,0) circle (2);
draw[red,thick] (-2,0) circle (2);
node[circle,fill,red,inner sep=2pt] (A) at ($(2,0)+(45:2)$) ;
node[circle,fill,red,inner sep=2pt] (B) at ($(-2,0)+(-135:2)$) ;
draw[gray] (A) circle (4.5pt) (B) circle (4.5pt);
draw[gray,shorten >=1.5pt,shorten <=1.5pt] (A)--(B);
endscope
draw[red] (A) -- (0,0,0) (B) -- (0,0,0);
endscope
endtikzpicture

foreach X in -50
tdplotsetmaincoords110X
begintikzpicture
%path[use as bounding box] (-6,-3) rectangle (6,5);
%node[anchor=north west] at (-6,5) X,xtest,ytest;
beginscope[tdplot_main_coords]
% ray in the back
draw [thick,blue,postaction=decorate,decoration=markings,mark=at position 0.2
with arrowstealth;] (-6,0,0) -- (0,0,0);
% back
filldraw[cyan,fill opacity=0.3] (-0.5,-2,-2) -- (-0.5,2,-2) -- (-0.5,2,2)
-- (-0.5,-2,2) -- cycle;
% bottom
filldraw[cyan,fill opacity=0.3] (0,-2,-2) -- (-0.5,-2,-2) -- (-0.5,2,-2)
-- (0,2,-2) -- cycle;
% right
filldraw[cyan,fill opacity=0.1] (0,2,-2) -- (-0.5,2,-2) -- (-0.5,2,2)
-- (0,2,2) -- cycle;
% left
filldraw[cyan,fill opacity=0.3] (0,-2,-2) -- (-0.5,-2,-2) -- (-0.5,-2,2)
-- (0,-2,2) -- cycle;
% top
filldraw[cyan,fill opacity=0.1] (0,-2,2) -- (-0.5,-2,2) -- (-0.5,2,2)
-- (0,2,2) -- cycle;
%front
filldraw[cyan,fill opacity=0.1] (0,-2,-2) -- (0,2,-2) -- (0,2,2)
-- (0,-2,2) -- cycle;
% ray in front
draw[thick,blue] (0,0,0) -- (8,0,0);
beginscope[canvas is yz plane at x=8,xscale=-1,transform shape]
draw[gray] (-5,0) -- (5,0);
draw[gray] (0,-4) -- (0,4);
% draw[red,thick] (1,0) circle (2);
% draw[red,thick] (-1,0) circle (2);
node[circle,fill,red,inner sep=2pt] (A) at (2.5,0) ;
node[circle,fill,red,inner sep=2pt] (B) at (-2.5,0) ;
draw[gray] (A) circle (4.5pt) (B) circle (4.5pt);
%draw[gray,shorten >=1.5pt,shorten <=1.5pt] (A)--(B);
endscope
draw[red] (A) -- (0,0,0) (B) -- (0,0,0);
endscope
endtikzpicture

enddocument



enter image description here



And the nowadays mandatory animation can't be missing.


documentclass[tikz,border=3.14mm]standalone
usetikzlibrary3d,decorations.markings,calc
usepackagetikz-3dplot
makeatletter % https://tex.stackexchange.com/a/48776/121799
tikzoptioncanvas is xy plane at z%
deftikz@plane@originpgfpointxyz00#1%
deftikz@plane@xpgfpointxyz10#1%
deftikz@plane@ypgfpointxyz01#1%
tikz@canvas@is@plane

makeatother

begindocument
foreach Z in 0,0.075,...,4
pgfmathsetmacroXmin(Z,2)
pgfmathsetmacroYmin(4-Z,2)
tdplotsetmaincoords110-50
begintikzpicture
%path[use as bounding box] (-6,-3) rectangle (6,5);
%node[anchor=north west] at (-6,5) X,xtest,ytest;
beginscope[tdplot_main_coords]
% ray in the back
draw [thick,blue,postaction=decorate,decoration=markings,mark=at position 0.2
with arrowstealth;] (-6,0,0) -- (0,0,0);
% back
filldraw[cyan,fill opacity=0.3] (-0.5,-2,-2) -- (-0.5,2,-2) -- (-0.5,2,2)
-- (-0.5,-2,2) -- cycle;
% bottom
filldraw[cyan,fill opacity=0.3] (0,-2,-2) -- (-0.5,-2,-2) -- (-0.5,2,-2)
-- (0,2,-2) -- cycle;
% right
filldraw[cyan,fill opacity=0.1] (0,2,-2) -- (-0.5,2,-2) -- (-0.5,2,2)
-- (0,2,2) -- cycle;
% left
filldraw[cyan,fill opacity=0.3] (0,-2,-2) -- (-0.5,-2,-2) -- (-0.5,-2,2)
-- (0,-2,2) -- cycle;
% top
filldraw[cyan,fill opacity=0.1] (0,-2,2) -- (-0.5,-2,2) -- (-0.5,2,2)
-- (0,2,2) -- cycle;
%front
filldraw[cyan,fill opacity=0.1] (0,-2,-2) -- (0,2,-2) -- (0,2,2)
-- (0,-2,2) -- cycle;
% ray in front
draw[thick,blue] (0,0,0) -- (8,0,0);
beginscope[canvas is yz plane at x=8,xscale=-1,transform shape]
draw[gray] (-5,0) -- (5,0);
draw[gray] (0,-4) -- (0,4);
draw[red,thick] (X,0) circle (Y);
draw[red,thick] (-X,0) circle (Y);
node[circle,fill,red,inner sep=2pt] (A) at ($(X,0)+(45:Y)$) ;
node[circle,fill,red,inner sep=2pt] (B) at ($(-X,0)+(-135:Y)$) ;
draw[gray] (A) circle (4.5pt) (B) circle (4.5pt);
draw[gray,shorten >=1.5pt,shorten <=1.5pt] (A)--(B);
endscope
draw[red] (A) -- (0,0,0) (B) -- (0,0,0);
endscope
endtikzpicture
enddocument



enter image description here





+1! You don't have to define canvas is xy plane at z, it's defined in the 3d library.
– Max
Aug 22 at 12:06


canvas is xy plane at z


3d





@Max Thanks! I know that it is defined there but the definition is wrong. I am not using this very canvas here but decided to carry the correct definition with me in order to avoid the complications I have experienced here, and to spare others to go through that.
– marmot
Aug 22 at 12:11





Ah I've never encountered that bug! Thanks for the heads-up
– Max
Aug 22 at 12:14





So the plane of the image is selected through tikzoption?
– Sid
Aug 22 at 13:42





@Sid Is there a tikzoption? The plane is selected/defined through beginscope[canvas is yz plane at x=8,xscale=-1,transform shape] (xscale=-1 is just for convenience), and the view angles are specified in tdplotsetmaincoords110-50. Thanks for updating the title of your nice question!
– marmot
Aug 22 at 13:44


tikzoption


beginscope[canvas is yz plane at x=8,xscale=-1,transform shape]


xscale=-1


tdplotsetmaincoords110-50






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

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

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế