[latex]PGF and Tikz 求两条直线或曲线的交点

[latex]PGF and Tikz 求两条直线或曲线的交点:

还是看一个简单的例子吧:

\begin{frame}{$Tikz$画出两条直线的交点}
\begin{tikzpicture}
\path [draw,name path=upward line] (1,0) -- (1,1);
\path [draw,name path=sloped line] (0,0) -- (30:1.5cm); % a bit longer, so that there is an 
%
\draw [name intersections={of=upward line and sloped line, by=x}]
[very thick,orange,fill=black]  (x) circle(1pt);
\end{tikzpicture}
\end{frame}
结果如下:

下面的例子较为复杂一点,标注两个圆的交点:

\begin{tikzpicture}
%定义两个坐标,并标注为A和B
\coordinate [label=left:$A$] (A) at (0,0);
\coordinate [label=right:$B$] (B) at (1,0.25);
%定义两个node,分别命名为D和E,其shape的路径命名为pathD(红色)和pathE(蓝色)
\node (D) [name path=pathD,draw,red,circle through=(B),label=left:$D$] at (A) {};
\node (E) [name path=pathE,draw,blue,circle through=(A),label=right:$E$] at (B) {};
% 命名交点坐标,但是不画出来:
\path [name intersections={of=pathD and pathE}];
% 标注第一个交点坐标C
\coordinate [label=above:$C$] (C) at (intersection-1);
% 标注第二个交点坐标F
\node[below] at (intersection-2){$F$};
\end{tikzpicture}

结果如下:

下面的例子简单一点:

\begin{tikzpicture}
%定义坐标,并标注为A B C D
\coordinate [label=left:$A$] (A) at (0,0);
\coordinate [label=right:$B$] (B) at (3,3);
\coordinate [label=left:$C$] (C) at (0.5,2.5);
\coordinate [label=right:$D$] (D) at (4,0.5);
%画直线
\draw [name path=A--B] (A) -- (B);
\draw [name path=C--D] (C) -- (D);
% 使用by=可以命名交点坐标为F,但是不画出来:
\path [name intersections={of = A--B and C--D,by=F}];
%标注交点坐标F
\node [fill=red,inner sep=1pt,label=-45:$F$] at (F) {};
\end{tikzpicture}

结果如下:

下面再来看复杂的交点标注问题:

\begin{tikzpicture}
%定义一个矩形,所有的绘图命令只在矩形内有效
\clip (-2,-2) rectangle (2,2);
%画任意的两条贝赛尔曲线
\draw [name path=curve 1] (-2,-1) .. controls (8,-1) and (-8,1) .. (2,1);
\draw [name path=curve 2] (-1,-2) .. controls (-1,8) and (1,-8) .. (1,2);
%标注每个交点坐标
\fill [name intersections={of=curve 1 and curve 2, name=i, total=\t}]
[red, opacity=0.5, every node/.style={above left, black, opacity=1}]
\foreach \s in {1,...,\t}{(i-\s) circle (2pt) node {\footnotesize\s}};
%name=i设置交点前缀,i-\s为每个交点的名称
%total=\t表示交点总数目
\end{tikzpicture}


其实Tikz还有很多更精彩的例子.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值