我想找到两条路径(一个圆和一个椭圆)的交点。只找到一个交点。为什么?谢谢。
以下是 MWE:
\documentclass[12pt]{article}
\usepackage[pdftex]{graphicx}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{calc,3d,shapes, intersections}
\usepackage{xcolor}
\usepackage{tikz-3dplot}
\begin{document}
\begin{tikzpicture}
\coordinate (O) at (0,0);
\def\R{3cm}
\def\c1{(O) circle (\R)}
\fill[ball color=white!10, opacity=0.3, name path=c1] \c1;
\draw[rotate=42, name path=c3, yscale=0.5, color=red] \c1;
\path [name intersections={of=c1 and c3, by={c131, c132}}];
\node[] at (c131) {c131};
\node[] at (c132) {c132};
\end{tikzpicture}
\end{document}
图表如下:
稍微扩展一下。它在很多情况下都能找到交点,但在这个情况下却找不到。这是我目前的完整代码:
\documentclass[12pt]{article}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{calc,3d,shapes, pgfplots.external, intersections}
\begin{document}
\begin{tikzpicture}[]
\coordinate (O) at (0,0);
\def\R{3cm}
%outside sphere
\def\c1{(O) circle (\R)}
\fill[ball color=white!10, opacity=0.3, name path=c1] \c1;
%one lune side
\draw[rotate=96, name path=c2, yscale=0.5] \c1;
%the other lune side
\draw[rotate=42, name path=c3, yscale=0.5, color=red] \c1;
% find intersections of each lune side with outside circle
\path [name intersections={of=c1 and c2,
by={c121, c122}}];
% perhaps a bug in intersections but I need to reverse the sign of c123
\path [name intersections={of=c1 and c3,
by={c131, c132}}];
% find intersections between c2 and c3
\path [name intersections={of=c2 and c3,
by={c231, c232, c233, c234}}];
% Locate points (a preview) uncomment the following lines
% to better understand the figure
\node[] at (c121) {c121};
\node[] at (c122) {c122};
\node[] at (c131) {c131};
\node[] at (c132) {c132};
\node[] at (c231) {c231};
\node[] at (c232) {c232};
\node[] at (c233) {c233};
\node[] at (c234) {c234};
\path[name path=c4, yscale=0.25 , rotate=42] \c1;
\end{tikzpicture}
\end{document}
为什么它会找到其他几个椭圆中的所有交点,而不是点 c131、c132 中的交点?
答案1
问题是两个椭圆(其中一个可能是圆)的交点有 4 个点(不是两个)。出于某种原因,三个点向上,一个点向下(我预计两个点向上,两个点向下,但此时我不关心这一点)。以下是代码:
\documentclass[12pt]{article}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{calc,3d,shapes, pgfplots.external, intersections}
\begin{document}
\begin{tikzpicture}[]
\coordinate (O) at (0,0);
\def\R{3cm}
%outside sphere
\def\c1{(O) circle (\R)}
\fill[ball color=white!10, opacity=0.3, name path=c1] \c1;
%one lune side
\draw[rotate=96, name path=c2, yscale=0.5] \c1;
%the other lune side
\draw[rotate=42, name path=c3, yscale=0.5, color=red] \c1;
% find intersections of each lune side with outside circle
\path [name intersections={of=c1 and c2,
by={c121, c122}}];
% perhaps a bug in intersections but I need to reverse the sign of c123
\path [name intersections={of=c1 and c3,
by={c131, c132,c133,c134}}];
% find intersections between c2 and c3
\path [name intersections={of=c2 and c3,
by={c231, c232, c233, c234}}];
% Locate points (a preview) uncomment the following lines
% to better understand the figure
\node[] at (c121) {c121};
\node[] at (c122) {c122};
\node[] at (c131) {c131};
\node[] at (c132) {c132};
\node[] at (c133) {c133};
\node[] at (c134) {c134};
\node[] at (c231) {c231};
\node[] at (c232) {c232};
\node[] at (c233) {c233};
\node[] at (c234) {c234};
\path[name path=c4, yscale=0.25 , rotate=42] \c1;
\end{tikzpicture}
\end{document}
如下图所示: