How can I draw a sphere knowing that centre and radius?
In the warped coordinate system, if we draw a circle at O of radius 1 it will pass through points A, B, C and D. However, the point of maximum distance (screen coordinates) occurs at point R. Therefore the outer edge of a sphere will also pass though point R.
Using the screen coordinates for R and O one can compute this radius. From the screen coordinates of A and O one can compute the y radius of an ellipse passing through A.
\documentclass[12pt,border=3]{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usepackage{fouriernc}
\usetikzlibrary{calc}
\newlength{\radius}
\newcommand{\RightAngle}[4][2.5pt]{%
\draw ($#3!#1!#2$)
--($ #3!2!($($#3!#1!#2$)!.5!($#3!#1!#4$)$) $)
--($#3!#1!#4$) ;
}
\begin{document}
\newcommand\pgfmathsinandcos[3]{%
\pgfmathsetmacro#1{sin(#3)}%
\pgfmathsetmacro#2{cos(#3)}%
}
\begin{tikzpicture}[scale=2.5]
\pgfmathsetmacro\AngleFuite{135}
\pgfmathsetmacro\coeffReduc{.85}
\pgfmathsetmacro\clen{2}
\pgfmathsinandcos\sint\cost{\AngleFuite}
\begin{scope} [x = {(\coeffReduc*\cost,-\coeffReduc*\sint)},
y = {(1cm,0cm)},
z = {(0cm,1cm)}]
\path
coordinate (A) at (0,0,0)
coordinate (B) at (1,0,0)
coordinate (C) at (1,{sqrt(3)},0)
coordinate (D) at (0,{sqrt(3)},0)
coordinate (S) at (0,0,2)
coordinate(H) at (4/5,0,2/5)
coordinate(K) at (0,{4*sqrt(3)/7},6/7)
coordinate(O) at (1/2,{sqrt(3)/2},0)
;
\draw[thick] (C)--(K)
;
\draw[ dashed] (A)--(B) (A)--(D) (A)--(K)
(A)--(S) (A)--(H)
(A)--(C)
(B)--(D) ;
\pgfmathsetmacro{\angle}{0.5*atan2(2*\coeffReduc*\cost, \coeffReduc*\coeffReduc-1)}% find max distance
%\draw[red] (O) +(\angle:-1) -- +(\angle:1);% angle test
\path (O) ++(\angle:1) coordinate (R);
\draw[red] (R) arc[radius=1,start angle={\angle},end angle={\angle+180}];
\draw[red,dashed] (R) arc[radius=1,start angle={\angle},end angle={\angle-180}];
\end{scope}
% comput radius of circle passing through (B)
\pgfpointdiff{\pgfpointanchor{R}{center}}{\pgfpointanchor{O}{center}}%
\pgfgetlastxy{\xRO}{\yRO}% \xRO = radius cos(angle), yBO = radius sin(angle)
\pgfmathsetmacro{\angle}{atan(\yRO/\xRO)}%
\pgfmathsetlength{\radius}{\xRO/cos(\angle)}% with units
\draw (O) circle[radius={\radius}];
% compute radius of ellipse passing through (A)
\pgfpointdiff{\pgfpointanchor{A}{center}}{\pgfpointanchor{O}{center}}%
\pgfgetlastxy{\xAO}{\yAO}% \xAO = x radius * cos(angle), \yAO= y radius * sin(angle)
\pgfmathsetmacro{\angle}{acos(\xAO/\radius)};
\draw (O) ++(0:\radius) arc[x radius={\radius}, y radius={\yAO/sin(\angle)}, start angle=0, end angle=180];
\draw[dashed] (O) ++(0:\radius) arc[x radius={\radius}, y radius={\yAO/sin(\angle)}, start angle=0, end angle=-180];
%
\RightAngle{(C)}{(K)}{(A)};
\RightAngle{(S)}{(H)}{(A)};
\draw [fill opacity=0.4,fill=green!80!blue] (S) -- (B) -- (C) -- cycle;
\draw [fill opacity=0.4,fill=orange!80!blue] (S) -- (C) -- (D) -- cycle;
\shade[ball color=blue, opacity=.5] (O) circle (\radius);% order of shaning is important
\foreach \v/\position in {A/below,B/below,C/below,D/right,S/above,H/left,K/right,O/below} {
\draw[fill=black] (\v) circle (0.7pt) node [\position=0.2mm] {$\v$};
}
\end{tikzpicture}
\end{document}
I used a translation to get the point O
as the origin. I got the same result.
My code
\documentclass[border=2mm,12pt]{standalone}
\usepackage{tikz}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usepackage{tikz-3dplot}
\usetikzlibrary{calc,backgrounds}
%\usetikzlibrary{arrows,calc}
\begin{document}
\tdplotsetmaincoords{60}{110}
\begin{tikzpicture}[scale=2]
\def\R{1}
\coordinate (O) at (0,0,0);
\fill[ball color=cyan!90, opacity=1.0] (O) circle (\R); % 3D lighting effect
\begin{scope}[tdplot_main_coords, shift={(0,0)}, rotate=0]
\path
coordinate (A) at (-1/2,-{sqrt(3)/2},0)
coordinate (B) at (1/2,-{sqrt(3)/2},0)
coordinate (H) at (3/10,-{sqrt(3)/2},2/5)
coordinate (K) at (-1/2,{sqrt(3)/14},6/7)
coordinate (C) at (1/2,{sqrt(3)/2},0)
coordinate (D) at (-1/2,{sqrt(3)/2},0)
coordinate (S) at (-1/2,-{sqrt(3)/2},2);
\draw[ dashed]
(A)--(S) (A)--(B) (A)--(D) (A)--(H) (A)--(K) (A)--(C) (B)--(D) (S)--(O) (H)--(C) (K)--(C)
;
\draw [fill opacity=0.4,fill=green!80!blue] (S) -- (B) -- (C) -- cycle;
\draw [fill opacity=0.4,fill=orange!80!blue] (S) -- (C) -- (D) -- cycle;
\foreach \v/\position in {A/below,B/left,C/below,D/right,S/above,O/{above right},H/left,K/right} {
\draw[fill=black] (\v) circle (0.7pt) node [\position=0.2mm] {$\v$};
}
\end{scope}
\tkzMarkRightAngle[size = 0.1](A,H,C);
\tkzMarkRightAngle[size = 0.1](A,K,C);
\end{tikzpicture}
\end{document}
Another code
\documentclass[border=2mm,12pt]{standalone}
\usepackage{tikz}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usepackage{tikz-3dplot}
\usepackage{fouriernc}
\usetikzlibrary{calc,backgrounds}
\usetikzlibrary{intersections,calc,backgrounds}
\begin{document}
\tdplotsetmaincoords{60}{120}
\begin{tikzpicture}[tdplot_main_coords,scale=1.5]
\pgfmathsetmacro\a{3}
\pgfmathsetmacro\b{4}
\pgfmathsetmacro\h{5}
\pgfmathsetmacro\r{sqrt(\a^2 + \b^2)/2}
% definitions
\path
coordinate(A) at (0,0,0)
coordinate (B) at (\a,0,0)
coordinate (C) at (\a,\b,0)
coordinate (D) at (0,\b,0)
coordinate (S) at (0,0,\h)
coordinate (E) at ({\a*\h^2/(\a^2+\h^2)}, 0, {\a^2*\h/(\a^2+\h^2)})
coordinate (F) at (0, {\b*\h^2/(\b^2+\h^2)}, {\b^2*\h/(\b^2+\h^2)})
coordinate (K) at ({\a*\h^2/(\a^2+\b^2+\h^2)}, {\b*\h^2/(\a^2+\b^2+\h^2)}, {(\a^2+\b^2)*\h/(\a^2+\b^2+\h^2)});
\begin{scope}
\draw [dashed, thick, name path=B--D] (B) -- (D);
\draw [dashed, thick, name path=C--A] (C) -- (A);
\path [name intersections={of=B--D and C--A,by=O}];
\end{scope}
\begin{scope}
\draw [dashed, thick, name path=S--O] (S) -- (O);
\draw [dashed, thick, name path=E--F] (E) -- (F);
\path [name intersections={of=S--O and E--F,by=I}];
\end{scope}
\begin{scope}
\draw[dashed, thick]
(A) -- (B) (D)--(A) (S)--(A);
\draw[dashed, thick]
(E) --(A) -- (F);
\draw[ultra thick]
(S) -- (B) -- (C) -- (D)--cycle (S)--(C) (E) -- (K) --(F);
\draw [thick, dashed] (A) -- (K) (E) -- (F) ;
\tkzMarkRightAngle(S,A,D)
\tkzMarkRightAngle(S,A,B)
\tkzMarkRightAngle(A,B,C)
\tkzMarkRightAngle(B,A,D)
\tkzMarkRightAngle(A,F,D)
\tkzMarkRightAngle(A,E,B)
\tkzMarkRightAngle(A,K,C)
\end{scope}
\begin{scope}[tdplot_screen_coords, on background layer]
\fill[ball color=cyan!90, opacity=1.0] (O) circle (\r); % 3D lighting effect
\end{scope}
\foreach \point/\position in {A/left,B/below,C/below,S/above,D/right,E/left,D/right,F/right,K/above right,O/below,I/below}
{
\fill (\point) circle (1.5pt);
\node[\position=3pt] at (\point) {$\point$};
}
\end{tikzpicture}
\end{document}