我想画一个球体,中心在O
,半径为线段OA
。我画不出来。我的代码是
\documentclass[12pt,border=3]{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usepackage{fouriernc}
\usetikzlibrary{calc}
\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{.8}
\pgfmathsetmacro\clen{2}
\pgfmathsinandcos\sint\cost{\AngleFuite}
\begin{scope} [x = {(\coeffReduc*\cost,-\coeffReduc*\sint)},
y = {(1cm,0cm)},
z = {(0cm,1cm)}]
\path coordinate (O) at (0,0,0)
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) ;
\end{scope}
\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$};
}
\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;
\RightAngle{(C)}{(K)}{(A)};
\RightAngle{(S)}{(H)}{(A)};
\end{tikzpicture}
\end{document}
答案1
在扭曲的坐标系中,如果我们在 O 处画一个半径为 1 的圆,它将经过点 A、B、C 和 D。然而,最大距离点(屏幕坐标)出现在点 R。因此球体的外边缘也将经过点 R。
使用 R 和 O 的屏幕坐标可以计算出该半径。通过 A 和 O 的屏幕坐标可以计算出通过 A 的椭圆的 y 半径。
\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}
答案2
我使用平移将点O
作为原点。我得到了相同的结果。我的代码
\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}
另一个代码
\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}