tikz add tag
4 years ago Anonymous 1123

I want to draw sphere with centre at O(0,0,0) and passing the point A(2,3,6). I tried

I can not get the result. Where is wrong in that code?

Top Answer
4 years ago user 3.14159

The veclen function only takes two arguments. However, it is possible to define pgf functions that take arbitrarily many arguments. Existing examples include the max function, which in its original version also was restricted to two arguments. Using the the definition of max I define a function Veclen which takes arbitrarily many arguments.

Screen Shot 2020-08-05 at 11.26.39 AM.png

Please note that the currently existing function veclen has other deficiencies. It cannot be switched to fpu mode. It may thus be worthwhile to place a feature request to change it to something along the lines outlined above.

Another feature request would be to record the screen depth of each coordinate. Currently, tikz has access to the screen coordinates only. It is, in principle, possible to computed and record the screen depth. However, it is very unlikely that such a feature request will be successful.

However, you could use the fact that functions declared with declare function can also be arrays. So you can access the components and use them for operations such as the computation of a distance.

Screen Shot 2020-08-05 at 8.52.04 PM.png

Answer #2
4 years ago Anonymous 1123

I used \usetikzlibrary{3dtools} and tried

ScreenHunter 791.png

4 years
user 3.14159 replying to Anonymous 1123 — Friday, 11th Dec 2020 15:10

You can use ($ (O)!.5!(A) $) to mark the point in the middle between A and O. But this point will be generated without its 3d coordinates, i.e. you cannot use M in TD("...") expressions.

6 hours
Anonymous 1123 — Friday, 11th Dec 2020 08:47

@marmot, re: your answer, You asked me didnot use syntax midpoint of a segment like this
($ (O)!.5!(A) $) coordinate (M)
full code

Please explaint it to me. I do not understand.

3 months
Anonymous 1123 — Thursday, 10th Sep 2020 09:09

@marmot, re: your answer, Please help me.

Anonymous 1123 — Thursday, 10th Sep 2020 09:08

@marmot, re: your answer, I do not know where is wrong in my code.
`\documentclass[border=2mm,12pt,tikz]{standalone} \usepackage{tikz-3dplot} \usetikzlibrary{calc} \makeatletter \pgfmathdeclarefunction{tddistance}{2}{% \begingroup% \pgfmathparse{% sqrt(({#1}[0]-{#2}[0])({#1}[0]-{#2}[0])+({#1}[1]-{#2}[1])({#1}[1]-{#2}[1])+({#1}[2]-{#2}[2])*({#1}[2]-{#2}[2]))}% \pgfmathsmuggle\pgfmathresult\endgroup% }% \makeatother \tikzset{coorf/.style={insert path={({{#1}[0],{#1}[1],{#1}[2]})}}} \begin{document}

\tdplotsetmaincoords{60}{70} \begin{tikzpicture}[tdplot_main_coords, declare function={a=1;xA=7a;yA=0;zA=0;xB=65a/14;yB=15* sqrt(3)a/14;zB=0;xC=0;yC=0;zC=5a; O={0,0,0};A={xA,yA,zA}; B={xB,yB,zB};C={xC,yC,zC};T={({-((-xCxCyBzA +xBxByCzA + yByB yC* zA - yB* yCyC zA + xCxC yA* zB - xAxA yC zB - yAyA* yC zB + yA yCyC zB - yC zAzA zB + yC zA zBzB - xBxB yA* zC + xAxA yB zC + yAyA yB zC - yA yByB* zC + yB* zAzA zC - yA zBzB zC - yB zA* zCzC + yA zB* zCzC)/(2 (xC* yB* zA - xB* yC* zA - xC* yA zB + xA yC zB + xB yA zC - xA yB* zC)))},{ -((-xBxB xC* zA + xB* xCxC zA - xC* yByB zA + xB* yCyC zA + xAxA xC zB - xA xCxC zB + xC yAyA zB - xA yCyC zB + xC zAzA zB - xC zA zBzB - xAxA xB* zC + xAxBxB* zC - xB* yAyA zC + xA* yByB zC - xB* zAzA zC + xA* zBzB zC + xBzA zCzC - xA zB* zCzC)/(2 (xC yB zA - xB* yC* zA - xC* yA* zB + xA yCzB + xB* yA* zC - xA* yB* zC)))}, {-((xBxB xC* yA - xB* xCxC yA - xAxA xCyB + xA xCxC yB - xC* yAyA yB + xC* yA* yByB + xAxA xByC - xAxBxB yC + xB yAyA yC - xA* yByB yC - xByA yCyC + xA yB yCyC - xC* yB zAzA + xB* yC zAzA + xC* yA zBzB - xA yC zBzB - xB yA zCzC + xA yB zCzC)/(2 (xC* yB* zA - xB* yC* zA - xC* yA* zB + xA* yC zB + xB yA* zC - xA* yB* zC)))})};] \path [coorf=O] coordinate (O) [coorf=T] coordinate (T) [coorf=A] coordinate (A) [coorf=B] coordinate (B) [coorf=A] coordinate © ; \pgfmathsetmacro{\R}{tddistance(“O”,“T”)}; \begin{scope}[tdplot_screen_coords] \draw[blue, thick] (O) circle[radius=\R]; \end{scope} \foreach \p in {O,T} {\draw[fill=black] (\p) circle (1.5pt);} \foreach \p/\g in {O/90,T/90,A/90,B/90,C/90} {\path (\p)+(\g:3mm) node{$\p$}; } \end{tikzpicture} \end{document}`

a month
Anonymous 1123 — Friday, 7th Aug 2020 15:05

@marmot, re: your answer, I used \pgfmathsetmacro{\R}{tddistance("O","T")}; %\shadedraw [ball color=green,tdplot_screen_coords] (O) circle(\R); \draw[tdplot_screen_coords] (O) circle(\R); It works.

2 days
Anonymous 1123 replying to user 3.14159 — Wednesday, 5th Aug 2020 23:08

Thank you very much.

user 3.14159 replying to Anonymous 1123 — Wednesday, 5th Aug 2020 23:04

It does not work because tikz only stores the projections of the coordinates on the screen. (See also the last paragraph of my answer.) It would require major surgery to implement this functionality in TikZ but in principle possible.

Anonymous 1123 — Wednesday, 5th Aug 2020 22:58

@marmot, re: your answer, How can I use your define in \draw[tdplot_screen_coords] (O) let \p1 = ($ (T) - (O) $) in circle ({veclen(\x1,\y1,\z1)});

11 hours
samcarter replying to Anonymous 1123 — Wednesday, 5th Aug 2020 11:28

Nice that you found a workaround! Would you consider posting this as an answer?

33 minutes
Anonymous 1123 — Wednesday, 5th Aug 2020 10:55

\documentclass[border=2mm,12pt,tikz]{standalone} \usepackage{tikz-3dplot} \usetikzlibrary{calc} \usetikzlibrary{3dtools} \begin{document} \tdplotsetmaincoords{60}{70} \begin{tikzpicture}[tdplot_main_coords] \path (0,0,0) coordinate (O) (2,3,6) coordinate (T); \pgfmathsetmacro{\R}{sqrt(TD("(T)-(O)o(T)-(O)")}; \begin{scope}[tdplot_screen_coords] \draw[blue, thick] (O) circle[radius=\R]; \end{scope} \end{tikzpicture} \end{document}

Anonymous 1123 replying to samcarter — Wednesday, 5th Aug 2020 10:54

Thank you. I used \usetikzlibrary{3dtools}

11 minutes
samcarter — Wednesday, 5th Aug 2020 10:43

I don’t think that veclen is defined for 3D, at least all mentions in the manual are only with two coordinates

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.