Forgot password?
 Create new account
View 79|Reply 3

TikZ中计算三角形面积并标在其重心

[Copy link]

3148

Threads

8489

Posts

610K

Credits

Credits
66148
QQ

Show all posts

hbghlyj Posted at 2025-4-9 00:46:12 |Read mode
用行列式计算三角形面积 = |A_x*(B_y-C_y) + B_x*(C_y-A_y) + C_x*(A_y-B_y)|/2
下面是一个完整的代码:
  1. \def\area#1#2#3{
  2.     \newdimen\Ax
  3.     \pgfextractx{\Ax}{\pgfpointanchor{#1}{center}}
  4.     \newdimen\Ay
  5.     \pgfextracty{\Ay}{\pgfpointanchor{#1}{center}}
  6.     \newdimen\Bx
  7.     \pgfextractx{\Bx}{\pgfpointanchor{#2}{center}}
  8.     \newdimen\By
  9.     \pgfextracty{\By}{\pgfpointanchor{#2}{center}}
  10.     \newdimen\Cx
  11.     \pgfextractx{\Cx}{\pgfpointanchor{#3}{center}}
  12.     \newdimen\Cy
  13.     \pgfextracty{\Cy}{\pgfpointanchor{#3}{center}}
  14.     \pgfmathsetmacro{\area}{(1pt/1cm)*(1pt/1cm)*abs((\Ax*(\By-\Cy) + \Bx*(\Cy-\Ay) + \Cx*(\Ay-\By)))/2}
  15.    
  16.     % Mark the centroid
  17.     \pgfmathsetmacro{\Gx}{(\Ax+\Bx+\Cx)/3}
  18.     \pgfmathsetmacro{\Gy}{(\Ay+\By+\Cy)/3}
  19.     \fill[red] (\Gx pt, \Gy pt) circle (2pt);
  20.    
  21.     % Output the area value at the centroid
  22.     \node[below right] at (\Gx pt, \Gy pt) {$\area$};
  23. }
Copy the Code

3148

Threads

8489

Posts

610K

Credits

Credits
66148
QQ

Show all posts

 Author| hbghlyj Posted at 2025-4-9 01:08:38

3148

Threads

8489

Posts

610K

Credits

Credits
66148
QQ

Show all posts

 Author| hbghlyj Posted at 2025-4-9 03:25:38

3148

Threads

8489

Posts

610K

Credits

Credits
66148
QQ

Show all posts

 Author| hbghlyj Posted at 2025-4-9 07:21:46
Last edited by hbghlyj at 2025-4-9 07:28:20例如forum.php?mod=redirect&goto=findpost& … =25701&ptid=3810

手机版Mobile version|Leisure Math Forum

2025-4-20 12:14 GMT+8

Powered by Discuz!

× Quick Reply To Top Return to the list