明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2272|回复: 4

[几何作图] [简介] 重心坐标的应用

[复制链接]
发表于 2011-1-27 23:41:57 | 显示全部楼层 |阅读模式
本帖最后由 qjchen 于 2011-1-27 23:41 编辑

最近,为了求一些三角形的内心、外心坐标学习了一下重心坐标,随手记下一些心得~

比如,假如知道了 三角形三个点 (x1,y1,z1) (x2,y2,z2) (x3 y3 z3) 请问,其内心坐标是多少,外心坐标是多少。
乍一看这问题很简单,但真正求起来还颇麻烦。
于是google之,发现了 Barycentric coordinates 这个名词
其定义可参见
中文wiki
http://zh.wikipedia.org/zh/%E9%87%8D%E5%BF%83%E5%9D%90%E6%A0%87
英文wiki(比较详细)
http://en.wikipedia.org/wiki/Barycentric_coordinates_(mathematics)
cut-the-knot(比较简单,有些链接)
http://www.cut-the-knot.org/triangle/glasses.shtml
Mathworld (对各心有一个比较详细的公式,好用)
http://mathworld.wolfram.com/BarycentricCoordinates.html

那么,也就是说,只要按 http://mathworld.wolfram.com/BarycentricCoordinates.html 这里的公式,计算出各点所对应的权重,那么 就可以根据 http://en.wikipedia.org/wiki/Barycentric_coordinates_(mathematics) 的公式
x=λ1x1+λ2x2+λ3x3.....  (其中λ是之前的重心坐标的归一化,也就是λ1:λ2:λ3=重心坐标比,和=1)
就可以得到各种心的坐标了。

公式多数是轮换的,如下图,就很方便用计算软件来进行一下推导验证某些其他性质了。



附上一个
原来发在此处http://www.theswamp.org/index.php?topic=36786.0的LISP代码


  1. ;;;;vec plus
  2. (defun q:vec:+(v1 v2) (mapcar '+ v1 v2))
  3. ;;;;vec substract
  4. (defun q:vec:-(v1 v2) (mapcar '- v1 v2))
  5. ;;;;vec plus constant
  6. (defun q:vec:*c(v a)  (mapcar '(lambda(x) (* x a)) v))
  7. ;;;;vec dot product
  8. (defun q:vec:dot*(v1 v2) (apply '+ (mapcar '* v1 v2)))
  9. ;;;;vec cross product
  10. (defun q:vec:cross*(v1 v2)
  11.   (list (q:det:2 (cadr v1) (caddr v1) (cadr v2) (caddr v2))
  12.         (q:det:2 (caddr v1) (car v1) (caddr v2) (car v2))
  13.         (q:det:2 (car v1) (cadr v1) (car v2) (cadr v2)))
  14. )
  15. ;;;;Normalize a vec
  16. (defun q:vec:Norm(v / l)
  17.   (if (not (zerop (setq l (distance '(0 0 0) v))))
  18.   (mapcar '(lambda(x) (/ x l)) v))
  19. )
  20. ;;;; Vector Length
  21. (defun q:vec:Length(v) (sqrt (apply '+ (mapcar '(lambda(x) (expt x 2)) v))))

  22. ;;;;determinant library
  23. ;;;;cal determinant
  24. ;;;;|a1 a2|
  25. ;;;;|b1 b2|
  26. (defun q:det:2(a1 a2 b1 b2)
  27.   (- (* a1 b2) (* a2 b1))
  28. )


  29. ;;;; Geometry code
  30. ;;;; [color=#476c8e][url=mailto:qjchen@gmail.com]qjchen@gmail.com[/url][/color]
  31. ;;;;[color=#476c8e][url=http://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line]http://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line[/url][/color]
  32. ;;;; distance of point per to line
  33. (defun q:geo:point-dis-to-line(p p1 p2 / n)
  34.   (setq n (q:vec:Norm (q:vec:- p2 p1)))
  35.   (q:vec:Length (q:vec:- (q:vec:+ p1 (q:vec:*c n (q:vec:dot* (q:vec:- p p1) n))) p))

  36. )

  37. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;Use Barycentric Coordinates to calculate multiple center
  38. ;;;[color=#476c8e][url=http://mathworld.wolfram.com/BarycentricCoordinates.html]http://mathworld.wolfram.com/BarycentricCoordinates.html[/url][/color]
  39. ;;;[color=#476c8e][url=http://en.wikipedia.org/wiki/Barycentric_coordinates_(mathematics)#Converting_to_barycentric_coordinates]http://en.wikipedia.org/wiki/Barycentric_coordinates_(mathematics)#Converting_to_barycentric_coordinates[/url][/color]
  40. (defun q:geo:barycentric-normalize(a b c)
  41.   (mapcar '(lambda(x) (/ x (+ a b c))) (list a b c))
  42. )
  43. ;;;;transform from barycentric-to-Cartesian coordinate
  44. (defun q:geo:barycentric-to-Cartesian(tlst P1 P2 P3)
  45. (q:vec:+  (q:vec:+ (q:vec:*c P1 (car tlst)) (q:vec:*c P2 (cadr tlst))) (q:vec:*c P3 (caddr tlst)))
  46. )
  47. ;;Find out the incircle of three point (three distinct, noncollinear WCS points)
  48. ;;;; [color=#476c8e][url=mailto:qjchen@gmail.com]qjchen@gmail.com[/url][/color]
  49. (defun q:geo:incircle3d(p1 p2 p3 / a b c p)
  50.   (setq a (distance p2 p3) b (distance p1 p3) c (distance p1 p2))
  51.   (setq p  (q:geo:barycentric-to-Cartesian (q:geo:barycentric-normalize a b c) P1 P2 P3))
  52.   (list p (q:geo:point-dis-to-line p p1 p2))
  53. )
  54. ;;Find out the circumcircle of three point (three distinct, noncollinear WCS points)
  55. (defun q:geo:circumcircle3d(p1 p2 p3 / a b c p temp)
  56.   (setq a (distance p2 p3) b (distance p1 p3) c (distance p1 p2))
  57.   (defun temp(a b c) (* a a (+ (* b b) (* c c) (* a (- a)))))
  58.   (setq p  (q:geo:barycentric-to-Cartesian (q:geo:barycentric-normalize (temp a b c) (temp b c a) (temp c a b)) P1 P2 P3))
  59.   (list p (distance p1 p))
  60. )
  61. ;;Find out the triangle centroid of three point (three distinct, noncollinear WCS points)
  62. (defun q:geo:centroid3d(p1 p2 p3 / p)
  63.   (q:geo:barycentric-to-Cartesian (q:geo:barycentric-normalize 1.0 1.0 1.0) P1 P2 P3)
  64. )

  65. ;;Find out the symmedian point of three point (three distinct, noncollinear WCS points)
  66. (defun q:geo:symmedianpoint3d(p1 p2 p3 / a b c)
  67.   (setq a (distance p2 p3) b (distance p1 p3) c (distance p1 p2))
  68.   (q:geo:barycentric-to-Cartesian (q:geo:barycentric-normalize (* a a) (* b b) (* c c)) P1 P2 P3)
  69. )

  70. ;;Find out the orthocenter of three point (three distinct, noncollinear WCS points)
  71. (defun q:geo:orthocenterpoint3d(p1 p2 p3 / a b c temp)
  72.   (setq a (distance p2 p3) b (distance p1 p3) c (distance p1 p2))
  73.   (defun temp(a b c) (* (+ (* a a) (* b b) (* c (- c)))(+ (* c c) (* a a) (* b (- b)))))
  74.   (q:geo:barycentric-to-Cartesian (q:geo:barycentric-normalize (temp a b c) (temp b c a) (temp c a b)) P1 P2 P3)
  75. )

  76. ;;Find out the Nagel point of three point (three distinct, noncollinear WCS points)
  77. (defun q:geo:Nagelpoint3d(p1 p2 p3 / a b c temp)
  78.   (setq a (distance p2 p3) b (distance p1 p3) c (distance p1 p2))
  79.   (defun temp(x) (- (/ (+ a b c) 2.0) x))
  80.   (q:geo:barycentric-to-Cartesian (q:geo:barycentric-normalize (temp a) (temp b) (temp c)) P1 P2 P3)
  81. )



  1. (defun c:test1 (/ p1 p2 p3 res1 res2 res3)
  2.   (command "UCS" "W")
  3.   (setvar "OSMODE" 1)
  4.   (setvar "PDMODE" 2)
  5.   (setq p1 (getpoint)
  6.         p2 (getpoint)
  7.         p3 (getpoint)
  8.   )
  9.   (setvar "OSMODE" 0)
  10.   (setq res1 (q:geo:incircle3d p1 p2 p3))
  11.   (setq res2 (q:geo:circumcircle3d p1 p2 p3))
  12.   (setq res3 (q:geo:orthocenterpoint3d p1 p2 p3))
  13.   (command "UCS" "3" p1 p2 p3)
  14.   (command "POINT" (trans (car res1) 0 1))
  15.   (command "CIRCLE" (trans (car res1) 0 1) (cadr res1))
  16.   (command "POINT" (trans (car res2) 0 1))
  17.   (command "CIRCLE" (trans (car res2) 0 1) (cadr res2))
  18.   (command "POINT" (trans res3 0 1))
  19.   (command "UCS" "W")
  20.   (grdraw (list 0 0 0) res3 1)
  21. )

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x

评分

参与人数 1威望 +1 明经币 +1 金钱 +30 收起 理由
highflybir + 1 + 1 + 30 好资源

查看全部评分

发表于 2011-1-27 23:52:43 | 显示全部楼层
支持了!
发表于 2011-2-20 12:19:33 | 显示全部楼层
本帖最后由 Ea 于 2011-2-20 22:45 编辑

内切圆,几何作图法(角平分线)
  1. (defun incir (p1 p2 p3 / an12 an13 an21 an23 d p22 p11 p01 pcen r)
  2.   (setq        an12 (angle p1 p2)
  3.         an13 (angle p1 p3)
  4.         an21 (angle p2 p1)
  5.         an23 (angle p2 p3)
  6.         d    (distance p1 p2)
  7.         p22  (polar p1 an13 d)
  8.         p11  (polar p2 an23 d)
  9.         p00  (list (/ (+ (car p2) (car p22)) 2)
  10.                    (/ (+ (cadr p2) (cadr p22)) 2)
  11.              )
  12.         p01  (list (/ (+ (car p1) (car p11)) 2)
  13.                    (/ (+ (cadr p1) (cadr p11)) 2)
  14.              )
  15.         pcen (inters p1 p00 p01 p2 nil)
  16.         r    (distance pcen
  17.                        (inters p1 p2 pcen (polar pcen (+ an21 (/ pi 2)) d) nil)
  18.              )
  19.   )
  20.   (list pcen r)
  21. )
  22. (defun c:test (/ p1 p2 p3 p)
  23.   (if (and (setq p1 (getpoint "\nFirst Point: "))
  24.            (setq p2 (getpoint p1 "\nSecond Point: "))
  25.            (setq p3 (getpoint p1 "\nThird Point: "))
  26.       )
  27.     (progn
  28.       (vl-cmdf ".pline" "_non" p1 "_non" p2 "_non" p3 "c")
  29.       (setq p (incir p1 p2 p3))
  30.       (vl-cmdf ".circle" (car p) (cadr p))
  31.     )
  32.   )
  33.   (princ)
  34. )
发表于 2011-2-20 17:53:42 | 显示全部楼层
支持了!
 楼主| 发表于 2011-2-20 23:04:05 | 显示全部楼层
本帖最后由 qjchen 于 2011-2-20 23:06 编辑

回复 Ea 的帖子

谢谢Eachy版主~
当时也写过一段角平分线法的,既写了,也发一下,和eachy版主的算法应该是差不多的。那个重心坐标的好处就在于可以求出空间状态下的圆心。

  1. ;;2d angle bisector
  2. (defun q:geo:angle-bisector(p1 p2 p3)
  3.   (list p1 (polar p1 (/ (+ (angle p1 p2) (angle p1 p3)) 2.0) 1.0))
  4. )
  5. ;;2d distance from a point to a line
  6. (defun q:geo:dis-point-to-2dline(p p1 p2)
  7.   (distance p (inters p (polar p (+ (angle p1 p2) (/ pi 2.0)) 1.0) p1 p2 nil))
  8. )
  9. ;;Find out the incircle of three point (three distinct, noncollinear WCS points)
  10. (defun q:geo:incircle(p1 p2 p3 / l1 l2 p)
  11.   (setq l1 (q:geo:angle-bisector p1 p2 p3) l2 (q:geo:angle-bisector p2 p3 p1))
  12.   (setq p (inters (car l1) (cadr l1) (car l2) (cadr l2) nil))
  13.   (list p (q:geo:dis-point-to-2dline p p1 p2))
  14. )



  15. ;;;测试函数
  16. ;;;;;Test function

  17. (defun c:test(/ p1 p2 p3)
  18. (setq p1 (getpoint) p2 (getpoint) p3 (getpoint))
  19. (q:entmake:circle (car (q:geo:incircle p1 p2 p3)) (cadr (q:geo:incircle p1 p2 p3)) (getvar "clayer"))
  20. )
  21. ;;entmake circle
  22. (defun q:entmake:circle (center rad layer)
  23.   (entmake (list (cons 0 "CIRCLE") (cons 8 layer) (cons 10 center) (cons 40 rad)))
  24. )

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-9-28 04:18 , Processed in 0.176374 second(s), 29 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表