Author Topic: -={ Challenge }=- Incircle & Circumcircle of a Triangle  (Read 16662 times)

0 Members and 1 Guest are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: -={ Challenge }=- Incircle & Circumcircle of a Triangle
« Reply #30 on: January 24, 2011, 01:29:14 PM »
There's a superfuous statement in the code I posted: as p1 lies on the plane, its 'caddr' will always be equal to 0. :loco:

Not necessarily, since the points will be transformed relative to the plane through the origin, you'll still need to use the Z-value of a point in the plane to get the correct elevation.

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: -={ Challenge }=- Incircle & Circumcircle of a Triangle
« Reply #31 on: January 24, 2011, 01:32:06 PM »
Another, to practice the method, finding the point in the plane closest to the supplied point:

Code: [Select]
(defun ClosestPointonPlane ( pt p1 p2 p3 )
  (
    (lambda ( n )
      (setq pt (trans pt 0 n)) (trans (list (car pt) (cadr pt) (caddr (trans p1 0 n))) n 0)
    )
    (v^v (mapcar '- p2 p1) (mapcar '- p3 p1))
  )
)

(defun v^v ( u v )
  (list
    (- (* (cadr u) (caddr v)) (* (cadr v) (caddr u)))
    (- (* (car  v) (caddr u)) (* (car  u) (caddr v)))
    (- (* (car  u) (cadr  v)) (* (car  v) (cadr  u)))
  )
)

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: -={ Challenge }=- Incircle & Circumcircle of a Triangle
« Reply #32 on: January 24, 2011, 01:47:20 PM »
There's a superfuous statement in the code I you posted: as p1 lies on the plane, its 'caddr' will always be equal to 0. :loco:

EDIT: wrong code de below...
Code: [Select]
(defun ClosestPointonPlane ( pt p1 p2 p3 )
  (
    (lambda ( n )
      (setq pt (trans pt 0 n)) (trans (list (car pt) (cadr pt) [color=red]0.[/color]) n 0)
    )
    (v^v (mapcar '- p2 p1) (mapcar '- p3 p1))
  )
)
« Last Edit: January 24, 2011, 03:35:31 PM by gile »
Speaking English as a French Frog

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: -={ Challenge }=- Incircle & Circumcircle of a Triangle
« Reply #33 on: January 24, 2011, 01:51:27 PM »
There's a superfuous statement in the code I you posted: as p1 lies on the plane, its 'caddr' will always be equal to 0.

Not sure about that, see #30  :?

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: -={ Challenge }=- Incircle & Circumcircle of a Triangle
« Reply #34 on: January 24, 2011, 02:10:17 PM »
You are absolutely right Lee, it's time I go sleeping... :oops:
Speaking English as a French Frog

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: -={ Challenge }=- Incircle & Circumcircle of a Triangle
« Reply #35 on: January 24, 2011, 02:11:14 PM »
You are absolutely right Lee, it's time I go sleeping... :oops:

Thanks Gile, but I wouldn't worry, you were right with your first code  :-)

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: -={ Challenge }=- Incircle & Circumcircle of a Triangle
« Reply #36 on: January 24, 2011, 02:17:21 PM »
More, there're both part my library (with normal and origin instead of 3 points) :cry:

Code: [Select]
;; gc:elevation
;; Retourne l'ιlιvation du point par rapport au plan
(defun gc:elevation (pt norm org)
  (- (caddr (trans pt 0 norm)) (caddr (trans org 0 norm)))
)

;; gc:ProjectOnPlane
;; Retourne la projection de pt sur le plan
(defun gc:ProjectOnPlane (pt norm org)
  ((lambda (p o)
     (trans (list (car p) (cadr p) (caddr o)) norm 0)
   )
    (trans pt 0 norm)
    (trans org 0 norm)
  )
)

Speaking English as a French Frog

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: -={ Challenge }=- Incircle & Circumcircle of a Triangle
« Reply #37 on: January 24, 2011, 02:22:25 PM »
More, there're both part my library (with normal and origin instead of 3 points) :cry:

It happens to the best of us  :-)

qjchen

  • Bull Frog
  • Posts: 285
  • Best wishes to all
Re: -={ Challenge }=- Incircle & Circumcircle of a Triangle
« Reply #38 on: January 24, 2011, 07:44:10 PM »

Code: [Select]
(defun ClosestPointonPlane ( pt p1 p2 p3 )
  (
    (lambda ( n )
      (setq pt (trans pt 0 n)) (trans (list (car pt) (cadr pt) [color=red]0.[/color]) n 0)
    )
    (v^v (mapcar '- p2 p1) (mapcar '- p3 p1))
  )
)

cool,Gile, and thanks Lee Mac for your beautiful code.

Last night is a sleepless night(my baby wake me up time and time again), I think out I shouldnt use cross *, but should use dot *. And when morning I realize it as follows and shorten a bit. But your trans shock me, it is more short.

It is time for me to think trans over and over. :)

Thank you all, I learn a lot from this post.

Code: [Select]
(defun q:geo:point-dis-to-plane4(p p1 p2 p3)
   ((lambda(n)
      (/ (abs (apply '+ (mapcar '* n (mapcar '- p p1))))
          (distance '(0. 0. 0.) n)
      )
   )
   (gc:CrossProduct (mapcar '- p2 p1) (mapcar '- p3 p1)))
)
« Last Edit: January 24, 2011, 08:05:56 PM by qjchen »
http://qjchen.mjtd.com
My blog http://chenqj.blogspot.com (Chinese, can be translate into English)