悠闲数学娱乐论坛(第2版)'s Archiver

abababa 发表于 2016-7-16 09:47

请教用tikz怎么画直线相交但线段不相交的点

[code]\coordinate[label=left:A] (A) at (0,0);
\coordinate[label=left:B] (B) at (5,1);
\coordinate[label=left:C] (C) at (1,1);
\coordinate[label=left:D] (D) at (4,0);
\draw [name path=AB] (A) -- (B);
\draw [name path=CD] (C) -- (D);
\path [name intersections={of = AB and CD}];
\coordinate[label=above right:T] (T)  at (intersection-1);[/code][code]\coordinate[label=left:A] (A) at (0,0);
\coordinate[label=left:B] (B) at (2,1);
\coordinate[label=left:C] (C) at (3,1);
\coordinate[label=left:D] (D) at (4,0);
\draw [name path=AB] (A) -- (B);
\draw [name path=CD] (C) -- (D);
\path [name intersections={of = AB and CD}];
\coordinate[label=above right:T] (T)  at (intersection-1);[/code]第一段代码因为线段是相交的,交点就画出来了,第二段代码直线相交但线段不相交,那个交点的位置就不正确了,我知道延长线段可以做到,但我觉得这样不通用,遇到不同的图形就要做不同的延长,特别是直线和曲线相交也不好弄,要想弄一个通用的方法应该怎么做呢?

isee 发表于 2016-7-16 17:56

GGB画交点,实际上也是直线的交点啊,再隐藏直线。

TiKZ也是画出相交线的交点,只画点,不画出线即可呀。

isee 发表于 2016-7-16 17:59

[i=s] 本帖最后由 isee 于 2016-7-19 00:35 编辑 [/i]

我个人处理,如果不复杂,手算出交点,直接画。
如果复杂,就用命令 [precode]($ (a)!0.5! 30:(b) $)[/precode]


其中(a)表起点,(b)表终点,0.5表线段(AB)的中点,30表绕点a逆时针方向转30度,如果不转,则可省略。

如,表(AB)的中点:[precode]($ (a)!0.5!:(b) $)[/precode]






而重要的是[color=Red]0.5可换成任意实数[/color],自己看效果吧。更多,查其对应手册。

abababa 发表于 2016-7-16 18:16

[b]回复 [url=http://kuing.orzweb.net/redirect.php?goto=findpost&pid=18445&ptid=4158]3#[/url] [i]isee[/i] [/b]

直线相交的交点要计算还简单一点,直线和曲线的交点就不好算了,而且延长线段的话,对不同的图延长多少也是不确定的。[code]\draw[name path=ellipse] (0,0) circle[x radius = 3, y radius = 2];
\path[name path=lineAB] (A)--(B);
\path [name intersections={of = ellipse and lineAB}];
[/code]就像上面这段代码,如果AB两点的位置好的话,线段正好和曲线有两个交点,那直接就能画出来了,要是线段非常短,两个端点都在曲线内部,就要延长线段再另外取点、取线段,才能画出交点,但这个延长就不统一了,不同的图里延长的也不一样。我想自定义一个命令能画出交点的,这样自定义里的延长多少就不好办了。

abababa 发表于 2016-7-16 18:21

[b]回复 [url=http://kuing.orzweb.net/redirect.php?goto=findpost&pid=18444&ptid=4158]2#[/url] [i]isee[/i] [/b]

我的第二段代码从意义上就是想表达直线$AB$和直线$CD$的交点,但因为点的坐标使线段$AB$和线段$CD$不相交,所以这个交点$T$的实际位置是不正确的,画出来并不是$AB$和$CD$的交点。

isee 发表于 2016-7-18 21:26

[quote]回复  isee

直线相交的交点要计算还简单一点,直线和曲线的交点就不好算了,而且延长线段的话,对不同的 ...
[size=2][color=#999999]abababa 发表于 2016-7-16 18:16[/color] [url=http://kuing.orzweb.net/redirect.php?goto=findpost&pid=18446&ptid=4158][img]http://kuing.orzweb.net/images/common/back.gif[/img][/url][/size][/quote]

3楼其实表达就是两边手动控制延长。

tikz画图,图肯定是自己预算中的,所以是可行的。

isee 发表于 2016-7-18 21:40

[quote]回复  isee

直线相交的交点要计算还简单一点,直线和曲线的交点就不好算了,而且延长线段的话,对不同的 ...
[size=2][color=#999999]abababa 发表于 2016-7-16 18:16[/color] [url=http://kuing.orzweb.net/redirect.php?goto=findpost&pid=18446&ptid=4158][img]http://kuing.orzweb.net/images/common/back.gif[/img][/url][/size][/quote]


    很久没用tikz,生了不少。

    比如这个,椭圆内两点。(PS:如今, circle 都能画椭圆了哇,其次,新版中3楼的不旋转不能省略,必须加0)[code]\begin{tikzpicture}
\coordinate[label=left:A] (A) at (0,0);
\coordinate[label=left:B] (B) at (1,1);
\draw[name path=e] (0,0) ellipse (3 and 2);
\draw [name path=l]($(A)!5!0:(B)$)--($(A)!5!180:(B)$);   %\path 就是隐藏了
\path [name intersections={of= e and l}];
\coordinate[label=above right:T] (T)  at (intersection-1);
\coordinate[label=above right:R] (R)  at (intersection-2);
\end{tikzpicture}
    [/code]

isee 发表于 2016-7-18 21:47

copy and paste 可能不能执行

xeLaTeX

isee 发表于 2016-7-18 21:54

[i=s] 本帖最后由 isee 于 2016-7-18 21:57 编辑 [/i]

这个是手动控制的。


[precode]($ (a)!0.5! 30:(b) $)[/precode]

是非常灵活的

isee 发表于 2016-7-18 21:57

若自动化,怕得写代码,这个不会了。或者参考其手册,手册很详细且强大的。。。

abababa 发表于 2016-7-19 20:35

[b]回复 [url=http://kuing.orzweb.net/redirect.php?goto=findpost&pid=18465&ptid=4158]10#[/url] [i]isee[/i] [/b]
[quote]\def\tkzInterLE(#1)(#2,#3){
        \begingroup
        \tkzInterLEE(#1)(#2,#3){tkzFirstPointResult}{tkzSecondPointResult}
        \endgroup
}
\def\tkzInterLEE(#1)(#2,#3)#4#5{
        \begingroup      
        \path[name path=tkz@line] (#2)--(#3);
        \path [name intersections={of = #1 and tkz@line}];
        \path[coordinate] (intersection-1) coordinate (#4);
        \path[coordinate] (intersection-2) coordinate (#5);
        \endgroup
}[/quote]
其实就是想照着tkz-euclide里的方法,定义这样一个命令,然后让它画直线和椭圆的交点。上面那个如果是线段和椭圆正好相交,就能得到两个正确的交点,最后用tkz-euclide里的\tkzGetFirstPoint和\tkzGetSecondPoint就取到点了,但如果只是直线和椭圆相交而线段不能相交,这时就会出问题。这里这个图就是不确定的,因为不知道具体画的时候那些点的坐标和椭圆的位置究竟怎样。

abababa 发表于 2016-7-19 20:43

[quote]很久没用tikz,生了不少。

    比如这个,椭圆内两点。(PS:如今, circle 都能画椭圆了哇,其次, ...
[size=2][color=#999999]isee 发表于 2016-7-18 21:40[/color] [url=http://kuing.orzweb.net/redirect.php?goto=findpost&pid=18458&ptid=4158][img]http://kuing.orzweb.net/images/common/back.gif[/img][/url][/size][/quote]

这个用圆来画其实是照着网上的照抄下来的。现在总感觉直接用tikz画得太困难了,Geogebra很方便,但是导出的代码又太乱而且意义也不明显,tkz-euclide包在画圆和直线方面很方便,初中里的平面几何就很好用了。虽然我现在还用不好,画得很慢,但我感觉等到我熟悉之后,用这个包要比用Geogebra画得更好更快。但这个包在画高中的圆锥曲线方面我没找到什么资料,可能是根本画不了。

页: [1]

Powered by Discuz! Archiver 7.2  © 2001-2009 Comsenz Inc.