Forgot password?
 Create new account
View 5522|Reply 13

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

[Copy link]

418

Threads

1627

Posts

110K

Credits

Credits
11885

Show all posts

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

801

Threads

4889

Posts

310K

Credits

Credits
36169

Show all posts

isee Posted at 2016-7-16 17:56:14
GGB画交点,实际上也是直线的交点啊,再隐藏直线。

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

801

Threads

4889

Posts

310K

Credits

Credits
36169

Show all posts

isee Posted at 2016-7-16 17:59:28
Last edited by isee at 2016-7-19 00:35:00我个人处理,如果不复杂,手算出交点,直接画。
如果复杂,就用命令
($ (a)!0.5! 30:(b) $)



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

如,表(AB)的中点:
($ (a)!0.5!:(b) $)







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

418

Threads

1627

Posts

110K

Credits

Credits
11885

Show all posts

 Author| abababa Posted at 2016-7-16 18:16:14
回复 3# isee

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

418

Threads

1627

Posts

110K

Credits

Credits
11885

Show all posts

 Author| abababa Posted at 2016-7-16 18:21:09
回复 2# isee

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

801

Threads

4889

Posts

310K

Credits

Credits
36169

Show all posts

isee Posted at 2016-7-18 21:26:40
回复  isee

直线相交的交点要计算还简单一点,直线和曲线的交点就不好算了,而且延长线段的话,对不同的 ...
abababa 发表于 2016-7-16 18:16
3楼其实表达就是两边手动控制延长。

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

801

Threads

4889

Posts

310K

Credits

Credits
36169

Show all posts

isee Posted at 2016-7-18 21:40:18
回复  isee

直线相交的交点要计算还简单一点,直线和曲线的交点就不好算了,而且延长线段的话,对不同的 ...
abababa 发表于 2016-7-16 18:16

    很久没用tikz,生了不少。

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

801

Threads

4889

Posts

310K

Credits

Credits
36169

Show all posts

isee Posted at 2016-7-18 21:47:41
copy and paste 可能不能执行

xeLaTeX
$type

u-000.tex

755 Bytes, Downloads: 866

801

Threads

4889

Posts

310K

Credits

Credits
36169

Show all posts

isee Posted at 2016-7-18 21:54:41
这个是手动控制的。


($ (a)!0.5! 30:(b) $)


是非常灵活的

801

Threads

4889

Posts

310K

Credits

Credits
36169

Show all posts

isee Posted at 2016-7-18 21:57:46
若自动化,怕得写代码,这个不会了。或者参考其手册,手册很详细且强大的。。。

418

Threads

1627

Posts

110K

Credits

Credits
11885

Show all posts

 Author| abababa Posted at 2016-7-19 20:35:31
回复 10# isee
\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
}

其实就是想照着tkz-euclide里的方法,定义这样一个命令,然后让它画直线和椭圆的交点。上面那个如果是线段和椭圆正好相交,就能得到两个正确的交点,最后用tkz-euclide里的\tkzGetFirstPoint和\tkzGetSecondPoint就取到点了,但如果只是直线和椭圆相交而线段不能相交,这时就会出问题。这里这个图就是不确定的,因为不知道具体画的时候那些点的坐标和椭圆的位置究竟怎样。

418

Threads

1627

Posts

110K

Credits

Credits
11885

Show all posts

 Author| abababa Posted at 2016-7-19 20:43:19
很久没用tikz,生了不少。

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

3150

Threads

8482

Posts

610K

Credits

Credits
66119
QQ

Show all posts

hbghlyj Posted at ereyesterday 19:20

延长线交点用旧语法intersection of被废弃

Last edited by hbghlyj at ereyesterday 19:25github.com/pgf-tikz/pgf/issues/632

虽然(intersection of A--B and 0,2--3,1)这种语法现在还能用,但被TikZ官方废弃了

tikz.dev/base-points#sec-101.5.4
  1. \begin{tikzpicture}
  2.   \draw[help lines] (0,0) grid (2,2);
  3.   \draw (.5,0) -- (2,2);
  4.   \draw (1,2) -- (2,0);
  5.   \pgfpathcircle{%
  6.     \pgfpointintersectionoflines
  7.       {\pgfpointxy{.5}{0}}{\pgfpointxy{2}{2}}
  8.       {\pgfpointxy{1}{2}}{\pgfpointxy{2}{0}}}
  9.     {2pt}
  10.   \pgfusepath{stroke}
  11. \end{tikzpicture}
Copy the Code

github.com/pgf-tikz/pgf/commit/55d882f47e244e … 0ef4bc93f8bddd90199d
\pgf@iflinesintersect可以判断两条线是否相交

3150

Threads

8482

Posts

610K

Credits

Credits
66119
QQ

Show all posts

hbghlyj Posted at ereyesterday 19:26

在Asymptote可以用 extension()

  1. pair A,B,C,D,E;unitsize(1cm);
  2. A=(0,0); C=(5,0); B=(1,1); D=(4,2);
  3. E=extension(A,B,C,D); // returns the intersection of lines AB and CD
  4. draw(B--A--C--D--cycle);
  5. draw(B--E--D,orange);
Copy the Code

手机版Mobile version|Leisure Math Forum

2025-4-19 18:19 GMT+8

Powered by Discuz!

× Quick Reply To Top Return to the list