提取路径的一部分并将其重新用作新路径的一部分

提取路径的一部分并将其重新用作新路径的一部分

我想将蓝线部分 1-2-3-1 绘制为实线,将蓝线部分 1-4-3 绘制为虚线。蓝线(EllA 路径)的定义由计算节点组成。

我在绘图过程中找不到交叉点,preaction因为 tikz 目前不知道路径的名称。如果在 tikz 的下一个版本中可以实现这一点就太好了。

我需要提取 EllA 路径的一部分(我不知道是否可能,steal 问这个问题?)然后绘制它,但是为了确定交点,必须绘制它(至少没有绘制选项),但如何再次绘制它的一部分甚至将其重新用作新路径的一部分?

这是一个恶性椭圆;-)

PS 剪辑一半的蓝线不是解决方案,因为我事先不知道它的形状。我想要一个仅基于路径本身的动态解决方案。如果使用 tikz 可以实现这样的解决方案。

\documentclass[a4paper]{article}
\usepackage[marginparsep=3pt, top=2cm, bottom=1.5cm, left=3cm, right=1.5cm]{geometry}

\usepackage{tikz}
\usetikzlibrary{calc,intersections}

\tikzset{small dot/.style={fill=black,circle,scale=0.3},}

\newcommand{\EllA}[1]{%
        \pgfmathsetmacro\CX{1*cos(#1)}
        \pgfmathsetmacro\CY{2*sin(#1)}
}

\begin{document}
\begin{tikzpicture}

% Complex computed path
% here an ellipse for the example
\foreach \A in {0,10,...,350} {%
    \EllA{\A} ;         
    \coordinate (EA\A) at (\CX,\CY) ;
}

% The draw option is here to see what it looks like
% but I just want to draw a part of it          
\path[name path=EllA,draw,blue]
    (EA0)
    \foreach \A in {10,20,...,350} {%
        --(EA\A) } --cycle ;

% Another path who may be computed as the first
\path[name path=EllB,draw,xslant=tan(30)] (0,0) circle (1) ;

\fill [red,
name intersections={of=EllA and EllB,
name=i,sort by=EllA,
total=\t}]
[every node/.style={above left, black, opacity=1}]
\foreach \s in {1,...,\t}
    {(i-\s) circle (1pt) node {\footnotesize\s}};

\path[draw] (i-2)--(i-4) ;

\end{tikzpicture}
\end{document}

在此处输入图片描述

答案1

我不确定这些是不是你想要填充的弧线。我假设从 (i-2) 到 (i-4) 画一条线是有原因的。

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{calc,fpu,intersections}

\tikzset{small dot/.style={fill=black,circle,scale=0.3},}

\newlength{\cx}
\newlength{\cy}

\newcommand{\myangle}[2]{% #1 = coordinate name, #2 = macro name
\pgfextractx{\cx}{\pgfpointanchor{#1}{center}}%
\pgfextracty{\cy}{\pgfpointanchor{#1}{center}}%
\pgfmathparse{atan2(\cx,0.5\cy)}%
\let#2=\pgfmathresult}

\newcommand{\myotherangle}[2]{% #1 = coordinate name, #2 = macro name
\pgfextractx{\cx}{\pgfpointanchor{#1}{center}}%
\pgfextracty{\cy}{\pgfpointanchor{#1}{center}}%
\pgfmathparse{atan2(\cx-tan(30)*\cy,\cy)}%
\let#2=\pgfmathresult}

\begin{document}
\begin{tikzpicture}

%first ellipse
\draw[color=blue, name path=EllA] (0,0) circle[x radius=1, y radius=2];

%second ellipse
\draw[name path=EllB,xslant=tan(30)] (0,0) circle(1);

%intersections
\path[name intersections={of=EllA and EllB,
  name=i,sort by=EllA,total=\t}];

\draw (i-2)--(i-4);

%dashed line from i-1 to i-2
\myangle{i-1}{\angleA}%
\myangle{i-2}{\angleB}%
\draw[color=white,dashed] (i-1) arc(\angleA:\angleB:1 and 2);

%dashed line from i-2 to i-3
\myotherangle{i-2}{\angleC}%
\myotherangle{i-3}{\angleD}%
\draw[color=white,dashed,xslant=tan(30)] (i-2) arc(\angleC:\angleD:1);

%fill arc from i-2 to i-4
\myangle{i-2}{\angleA}%
\myangle{i-4}{\angleB}%
\fill[color=blue,opacity=.2] (i-2) arc(\angleA:\angleB+360:1 and 2);

%fill arc from i-1 to i-4
\myangle{i-1}{\angleA}%
\fill[color=blue,opacity=.2] (i-4) arc(\angleB:\angleA:1 and 2);

%unfill arc from i-1 to i-4
\myotherangle{i-4}{\angleC}%
\myotherangle{i-1}{\angleD}%
\path[draw=black,fill=white,xslant=tan(30)] (i-4) arc(\angleC:\angleD:1);

% draw intersections
\fill[color=red, every node/.style={above left, black, opacity=1}]
  \foreach \s in {1,2,3,4}%
    {(i-\s) circle[radius=1pt] node{\footnotesize\s}};

\end{tikzpicture}
\end{document}

椭圆形

答案2

我不完全清楚你想要什么,但我最近开发了使用子路径的能力spath3包裹。

\documentclass[a4paper]{article}
%\url{https://tex.stackexchange.com/q/162687/86}
\usepackage[marginparsep=3pt, top=2cm, bottom=1.5cm, left=3cm, right=1.5cm]{geometry}

\usepackage{tikz}
\usetikzlibrary{calc,intersections,spath3}

\tikzset{small dot/.style={fill=black,circle,scale=0.3},}

\newcommand{\EllA}[1]{%
        \pgfmathsetmacro\CX{1*cos(#1)}
        \pgfmathsetmacro\CY{2*sin(#1)}
}

\begin{document}
\begin{tikzpicture}

% Complex computed path
% here an ellipse for the example
\foreach \A in {0,10,...,350} {%
    \EllA{\A} ;         
    \coordinate (EA\A) at (\CX,\CY) ;
}

% The draw option is here to see what it looks like
% but I just want to draw a part of it          
\path[spath/save=EllA]
    (EA0)
    \foreach \A in {10,20,...,350} {%
        --(EA\A) } --cycle ;

% Another path who may be computed as the first
\path[spath/save=EllB,xslant=tan(30)] (0,0) circle (1) ;

\tikzset{
  spath/split at intersections with={EllA}{EllB},
  spath/get components of={EllA}\cpts
}

\draw[
  blue,
  spath/use=\getComponentOf\cpts{1},
  spath/use={\getComponentOf\cpts{2},weld},
  spath/close=current
];

\draw[
  blue,
  dashed,
  spath/use=\getComponentOf\cpts{3},
  spath/use={\getComponentOf\cpts{4},weld},
];

\draw[spath/use=EllB];

\end{tikzpicture}
\end{document}

椭圆的子路径

相关内容