Author Topic: -={ Challenge }=- Incircle & Circumcircle of a Triangle  (Read 16655 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 #15 on: January 22, 2011, 10:08:24 AM »
To get the distance from a 3d point to an unbounded 3d line defined by 2 points, here's a 'generic' way

Using
Code: [Select]
|a x b| = |a||b|sin θ I like it  :-)

Your previous methods have spurred me on to find the Orthocenter too  :-)

Code: [Select]
(defun Orthocenter ( p1 p2 p3 / v1 v2 n )
  (setq v1 (mapcar '- p2 p1)
        v2 (mapcar '- p3 p1)
        n  (v^v v1 v2)
  ) 
  (inters
    p3 (mapcar '+ p3 (v^v v1 n))
    p2 (mapcar '+ p2 (v^v v2 n)) nil
  )
)

(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)))
  )
)

Code: [Select]
(defun c:test ( / p1 p2 p3 )
  (if
    (and
      (setq p1 (getpoint "\nP1: "))
      (setq p2 (getpoint "\nP2: "))
      (setq p3 (getpoint "\nP3: "))
    )
    (entmakex (list (cons 0 "POINT") (cons 10 (Orthocenter p1 p2 p3))))
  )
  (princ)
)
« Last Edit: January 22, 2011, 10:13:33 AM by Lee Mac »

qjchen

  • Bull Frog
  • Posts: 285
  • Best wishes to all
Re: -={ Challenge }=- Incircle & Circumcircle of a Triangle
« Reply #16 on: January 22, 2011, 10:12:35 AM »

Code: [Select]
;; gc:DistanceTo
;; Returns the distance from pt to p1 p2 line
(defun gc:DistanceTo (pt p1 p2)
  ((lambda (v)
     (/
       (distance '(0. 0. 0.) (gc:CrossProduct (mapcar '- pt p1) v))
       (distance '(0. 0. 0.) v)
     )
   )
    (mapcar '- p2 p1)
  )
)


It is a very good method
It is better than this http://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line

You use |(pt-p1)X(p2-p1)|/|p2-p1|,
very good method, X will produce a sin(theta) and then will get a distance, very good, Thanks~
http://qjchen.mjtd.com
My blog http://chenqj.blogspot.com (Chinese, can be translate into English)

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: -={ Challenge }=- Incircle & Circumcircle of a Triangle
« Reply #17 on: January 22, 2011, 12:03:58 PM »
Simple centroid  :-)

Code: [Select]
(defun Centroid ( p1 p2 p3 )
  (mapcar '(lambda ( a b c ) (/ (+ a b c) 3.)) p1 p2 p3)
)

SOFITO_SOFT

  • Guest
Re: -={ Challenge }=- Incircle & Circumcircle of a Triangle
« Reply #18 on: January 22, 2011, 12:21:54 PM »
Hello swap people:
and the centroid  faster for a list of n 3dpoints?
Regards

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: -={ Challenge }=- Incircle & Circumcircle of a Triangle
« Reply #19 on: January 22, 2011, 12:41:36 PM »
Here's a way to get the average of n points...

Code: [Select]
(defun PointAverage ( l )
  ( (lambda ( n ) (mapcar '/ (apply 'mapcar (cons '+ l)) (list n n n)))
    (float (length l))
  )
)

David Bethel

  • Swamp Rat
  • Posts: 656
Re: -={ Challenge }=- Incircle & Circumcircle of a Triangle
« Reply #20 on: January 22, 2011, 12:58:24 PM »
You could always use the CIRCLE command with the 3Pt input option.  Tangent points for the inside.  -David
R12 Dos - A2K

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: -={ Challenge }=- Incircle & Circumcircle of a Triangle
« Reply #21 on: January 22, 2011, 01:01:10 PM »
You could always use the CIRCLE command with the 3Pt input option.  Tangent points for the inside.  -David

But where's the fun in that...  :lol:  :wink:

SOFITO_SOFT

  • Guest
Re: -={ Challenge }=- Incircle & Circumcircle of a Triangle
« Reply #22 on: January 22, 2011, 02:28:03 PM »
Hello:
THIS IS A VERY GOOD TRICK!
(apply 'mapcar !!! (cons '+ l) !!!  )
Thanks...Greetings

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: -={ Challenge }=- Incircle & Circumcircle of a Triangle
« Reply #23 on: January 22, 2011, 02:40:33 PM »
Hello:
THIS IS A VERY GOOD TRICK!
(apply 'mapcar !!! (cons '+ l) !!!  )
Thanks...Greetings

 :-)

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: -={ Challenge }=- Incircle & Circumcircle of a Triangle
« Reply #24 on: January 22, 2011, 03:32:13 PM »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: -={ Challenge }=- Incircle & Circumcircle of a Triangle
« Reply #25 on: January 22, 2011, 05:28:02 PM »
My math master at school used to say repeatedly " everything is based on circles and triangles "

... I'm sure he was correct.
« Last Edit: January 22, 2011, 05:32:03 PM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

qjchen

  • Bull Frog
  • Posts: 285
  • Best wishes to all
Re: -={ Challenge }=- Incircle & Circumcircle of a Triangle
« Reply #26 on: January 24, 2011, 08:09:29 AM »
To Kerry, it is very cool picture~

To gile

Code: [Select]
;; gc:DistanceTo
;; Returns the distance from pt to p1 p2 line
(defun gc:DistanceTo (pt p1 p2)
  ((lambda (v)
     (/
       (distance '(0. 0. 0.) (gc:CrossProduct (mapcar '- pt p1) v))
       (distance '(0. 0. 0.) v)
     )
   )
    (mapcar '- p2 p1)
  )
)


Hi, gile:)
I learn from your code, and write the following code=> distance from p to three point p1 p2 p3 plane.

Code: [Select]
;; gc:CrossProduct--by gile@theswamp.org
;; Returns the cross product of v1 v2
(defun gc:CrossProduct (v1 v2)
  (list (- (* (cadr v1) (caddr v2)) (* (caddr v1) (cadr v2)))
(- (* (caddr v1) (car v2)) (* (car v1) (caddr v2)))
(- (* (car v1) (cadr v2)) (* (cadr v1) (car v2)))
  )
)

;;qjchen@gmail.com
(defun q:geo:point-dis-to-plane2(p p1 p2 p3)
     ((lambda(a b) (sqrt (- (* a a) (* b b))))
             (distance '(0 0 0) (mapcar '- p p1))
             (/ (distance '(0 0 0)
                  (gc:CrossProduct
                   (gc:CrossProduct (mapcar '- p2 p1) (mapcar '- p3 p1))
                   (mapcar '- p p1)
                  )
                )
                (distance '(0 0 0)
                  (gc:CrossProduct (mapcar '- p2 p1) (mapcar '- p3 p1))
                )
              )
     )
)
test code
Code: [Select]
(setq p1 '(10. 0. 0.) p2 '(0. 10. 0.) p3 '(10. 10. 10.) p '(10. 10. 0.))
  (q:geo:point-dis-to-plane2 p p1 p2 p3)

But the previous code use sqrt(a*a-b*b), and is not a good way.

I have ever write a code based on http://en.wikipedia.org/wiki/Point_on_plane_closest_to_origin
but the code more longer.

Could you help me to shorten it. Thank you~
http://qjchen.mjtd.com
My blog http://chenqj.blogspot.com (Chinese, can be translate into English)

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: -={ Challenge }=- Incircle & Circumcircle of a Triangle
« Reply #27 on: January 24, 2011, 11:13:55 AM »
Hi qjchen,

Go the trans route...

Code: [Select]
(defun DistToPlane3Pts (pt p1 p2 p3)
  ((lambda (n)
     (abs (- (caddr (trans pt 0 n)) (caddr (trans p1 0 n))))
   )
    (gc:CrossProduct (mapcar '- p2 p1) (mapcar '- p3 p1))
  )
)
Speaking English as a French Frog

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: -={ Challenge }=- Incircle & Circumcircle of a Triangle
« Reply #28 on: January 24, 2011, 12:47:29 PM »
Go the trans route...

Really liking that trans method - simplifies things a great deal  :-)

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: -={ Challenge }=- Incircle & Circumcircle of a Triangle
« Reply #29 on: January 24, 2011, 12:58:57 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:
So, here's a simple way

EDIT: wrong code, see Reply #30
Code: [Select]
(defun DistToPlane3Pts (pt p1 p2 p3)
  (abs (caddr (trans pt 0 (gc:CrossProduct (mapcar '- p2 p1) (mapcar '- p3 p1)))))
)
« Last Edit: January 24, 2011, 02:13:25 PM by gile »
Speaking English as a French Frog