Author Topic: Geometrical question: closest orthogonal point  (Read 862 times)

0 Members and 1 Guest are viewing this topic.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1058
  • Marco
Geometrical question: closest orthogonal point
« on: March 17, 2020, 04:57:53 PM »
Maybe the solution is simple, I know : C P1 P2    and I have to calculate: P1o p2o  that is the closest orthogonal point

Stefan

  • Bull Frog
  • Posts: 228
Re: Geometrical question: closest orthogonal point
« Reply #1 on: March 17, 2020, 05:32:34 PM »
In the last picture, isn't P2o = P1o?

Anyway, for P1o alone
Code - Auto/Visual Lisp: [Select]
  1. (setq p01 (polar c (* 0.5 pi (fix (+ 0.5 (/ (angle c p1) pi 0.5)))) (distance c p1)))


Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1058
  • Marco
Re: Geometrical question: closest orthogonal point
« Reply #2 on: March 17, 2020, 05:56:35 PM »
I need to calculate the closest orthogonal point of the closest point to the axis, then the opposite at 90 (sorry for my english).

Stefan

  • Bull Frog
  • Posts: 228
Re: Geometrical question: closest orthogonal point
« Reply #3 on: March 17, 2020, 06:13:08 PM »
What about this

MP

  • Seagull
  • Posts: 17577
Re: Geometrical question: closest orthogonal point
« Reply #4 on: March 17, 2020, 06:55:54 PM »
If you bisect the angles for vectors C->p1 and C->p2 the resulting vector C->P3 lies in one quadrant (3), said quadrant bounded by it's orthogonal points P1o and P2o. Make sense? Or did I miss your intention?

\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

BIGAL

  • Bull Frog
  • Posts: 425
  • 30 + years of using Autocad
Re: Geometrical question: closest orthogonal point
« Reply #5 on: March 17, 2020, 07:59:20 PM »
Like MP goggle which quadrant is point in lsp then 0 1 2 or 3 gives ortho angle.
A man who never made a mistake never made anything

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1058
  • Marco
Re: Geometrical question: closest orthogonal point
« Reply #6 on: March 18, 2020, 04:36:16 AM »
I apologize for the delay (time zone), maybe this:
Code: [Select]
; the angle between the lines never exceeds 180 degrees
(setq CntPnt '(10. 10. 0.) Pnt001 '(208.14 37.20 0.)  Pnt002 '(191.12 -74.84 0.))

Command: (setq Ang001 (angle CntPnt Pnt001)) =>  0.136424
Command: (setq Ang002 (angle CntPnt Pnt002)) =>  5.84512
Command: (setq Deg090 (/ pi 2.))              =>  1.5708

Command: (if (> Ang001 Ang002)
(_>   (setq Ang003 (+ Ang001    (/ (- Ang002 Ang001) 2.00)))
(_>   (setq Ang003 (+ Ang001 pi (/ (- Ang002 Ang001) 2.00)))
(_> )         => 6.13236

(cond
 ( (and (>= Ang003 0)      (>= Deg090        Ang003)) (list 0                   Deg090) )
 ( (and (>= Ang003 Deg090) (>= pi            Ang003)) (list Deg090                  pi) )
 ( (and (>= Ang003 pi)     (>= (+ pi Deg090) Ang003)) (list pi           (+ pi Deg090)) )
 ( T                                                  (list (+ pi Deg090)            0) )
)               =>  (4.71239 0)
the ultimate goal is to draw a clove in the quadrant more occupied.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1058
  • Marco
Re: Geometrical question: closest orthogonal point
« Reply #7 on: March 18, 2020, 11:58:00 AM »
This works in many conditions but not in all:
Code: [Select]
(defun ALE_Math_OrthoAngles (CntPnt Pnt001 Pnt002 / Ang001 Ang002 Ang003 Deg090)
  (setq
    Deg090 (/ pi 2.)
    Ang001 (angle CntPnt Pnt001)
    Ang002 (angle CntPnt Pnt002)
    Ang003 (+ Ang001 (/ (- Ang002 Ang001) 2.00))
  )
  (cond
    ( (and (>= Ang003 0)      (>= Deg090        Ang003)) (cons 0                   Deg090) )
    ( (and (>= Ang003 Deg090) (>= pi            Ang003)) (cons Deg090                  pi) )
    ( (and (>= Ang003 pi)     (>= (+ pi Deg090) Ang003)) (cons pi           (+ pi Deg090)) )
    ( T                                                  (cons (+ pi Deg090)            0) )
  )
)
Code: [Select]
(defun C:Test_OrthoAngles ( / CntPnt Pnt001 Pnt011 Pnt002 Pnt012 OutLst Dst001 Dst002)
  (setq
    CntPnt (GetPoint "\nC: ")
    Pnt001 (GetPoint "\nP: ")
    Pnt002 (GetPoint "\nP: ")
    Dst001 (distance CntPnt Pnt001)
    Dst002 (distance CntPnt Pnt002)
    OutLst (ALE_Math_OrthoAngles CntPnt Pnt001 Pnt002)
    Pnt011 (polar CntPnt (car OutLst) Dst001)
    Pnt012 (polar CntPnt (cdr OutLst) Dst002)
  ) 
  (entmake (list '(0 . "CIRCLE") (cons 40 20) (cons 10 Pnt011)))
  (entmake (list '(0 . "CIRCLE") (cons 40 20) (cons 10 Pnt012)))
)

Dlanor

  • Bull Frog
  • Posts: 215
Re: Geometrical question: closest orthogonal point
« Reply #8 on: March 18, 2020, 12:23:52 PM »
The two failures are caused by you not allowing for angles either side of 0.0

You need something like this

Code - Auto/Visual Lisp: [Select]
  1.     Ang003 (if (or (and (< 0.0 Ang001 Deg090) (< (* pi 1.5) Ang002 (* pi 2.0)))
  2.                    (and (< 0.0 Ang002 Deg090) (< (* pi 1.5) Ang001 (* pi 2.0)))
  3.                )
  4.              (+ Ang001 (/ (+ (* pi 2.0) (- Ang002 Ang001)) 2.00))
  5.              (+ Ang001 (/ (- Ang002 Ang001) 2.00))
  6.            )
  7.  

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1058
  • Marco
Re: Geometrical question: closest orthogonal point
« Reply #9 on: March 18, 2020, 04:16:18 PM »
The two failures are caused by you not allowing for angles either side of 0.0

You need something like this

Code - Auto/Visual Lisp: [Select]
  1.     Ang003 (if (or (and (< 0.0 Ang001 Deg090) (< (* pi 1.5) Ang002 (* pi 2.0)))
  2.                    (and (< 0.0 Ang002 Deg090) (< (* pi 1.5) Ang001 (* pi 2.0)))
  3.                )
  4.              (+ Ang001 (/ (+ (* pi 2.0) (- Ang002 Ang001)) 2.00))
  5.              (+ Ang001 (/ (- Ang002 Ang001) 2.00))
  6.            )
  7.  
Thanks.  :-)   Do you have an idea also for this?

Dlanor

  • Bull Frog
  • Posts: 215
Re: Geometrical question: closest orthogonal point
« Reply #10 on: March 18, 2020, 05:41:01 PM »
The reason is the same. I cannot test but maybe this does both

Code - Auto/Visual Lisp: [Select]
  1.     Ang003 (if (> pi (abs (- Ang002 Ang001)))
  2.              (+ Ang001 (/ (+ (* pi 2.0) (- Ang002 Ang001)) 2.00))
  3.              (+ Ang001 (/ (- Ang002 Ang001) 2.00))
  4.            )

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1058
  • Marco
Re: Geometrical question: closest orthogonal point
« Reply #11 on: March 19, 2020, 05:50:06 AM »
I implemented most of the MP's suggestion to consider the bisect. It is not very elegant but it works. Thank you.
Code: [Select]
(defun ALE_Math_OrthoAngles (CntPnt Pnt001 Pnt002 / Ang001 Ang002 Ang003 AngFlg Deg090 Deg270)
  (setq
    Deg090 (/ pi 2.)
    Deg270 (+ pi Deg090)
    Ang001 (angle CntPnt Pnt001)
    Ang002 (angle CntPnt Pnt002)
    AngFlg (> (abs (- Ang001 Ang002)) pi)
    Ang003 (if (> Ang001 Ang002)
              (+ (/ (- Ang001 Ang002) 2.) Ang002)
              (+ (/ (- Ang002 Ang001) 2.) Ang001)
           )
  )
  (and AngFlg (setq Ang003 (+ Ang003 pi)))
  (and (> Ang003 (+ pi pi) (setq Ang003 (rem Ang003 (+ pi pi)))))
  (cond
    ( (and (>= Ang003      0) (>= Deg090 Ang003)) (cons 0      Deg090) )
    ( (and (>= Ang003 Deg090) (>= pi     Ang003)) (cons Deg090     pi) )
    ( (and (>= Ang003     pi) (>= Deg270 Ang003)) (cons pi     Deg270) )
    ( T                                           (cons Deg270      0) )
  )
)

BIGAL

  • Bull Frog
  • Posts: 425
  • 30 + years of using Autocad
Re: Geometrical question: closest orthogonal point
« Reply #12 on: March 21, 2020, 02:24:14 AM »
Lines must be in two adjacent quadrants ? Else multi answers.
A man who never made a mistake never made anything

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1058
  • Marco
Re: Geometrical question: closest orthogonal point
« Reply #13 on: March 21, 2020, 07:03:03 AM »
Lines must be in two adjacent quadrants ? Else multi answers.
Show me an example. Thanks.

T.Willey

  • Needs a day job
  • Posts: 5237
Re: Geometrical question: closest orthogonal point
« Reply #14 on: March 23, 2020, 03:51:52 PM »
If I understand, this should be what you are looking for.  It will return a list of the quadrant angles.

Code - Lisp: [Select]
  1. (defun test ( cpt pt1 pt2 / ang1 ang2 a1 a2 )
  2.     (defun findClosestQuadrantAngle ( ang exclude / a90 a270 )
  3.         (setq a90 (* pi 0.5))
  4.         (setq a270 (* pi 1.5))
  5.         (setq ang (rem ang (* pi 2.)))
  6.         (cond
  7.             ((<= 0.0 ang a90)
  8.                 (if exclude
  9.                     (if (equal exclude 0. 1e-4) a90 0.)
  10.                     (if (<= ang (* pi 0.25)) 0. a90)
  11.                 )
  12.             )
  13.             ((<= a90 ang pi)
  14.                 (if exclude
  15.                     (if (equal exclude a90 1e-4) pi a90)
  16.                     (if (<= ang (* pi 0.75)) a90 pi)
  17.                 )
  18.             )
  19.             ((<= pi ang a270)
  20.                 (if exclude
  21.                     (if (equal exclude pi 1e-4) a270 pi)
  22.                     (if (<= ang (* pi 1.25)) pi a270)
  23.                 )
  24.             )
  25.             (t
  26.                 (if exclude
  27.                     (if (equal exclude a270 1e-4) 0. a270)
  28.                     (if (<= ang (* pi 1.75)) a270 0.0)
  29.                 )
  30.             )
  31.         )
  32.     )
  33.     (setq ang1 (angle cpt pt1))
  34.     (setq a1 (findClosestQuadrantAngle ang1 nil))
  35.     (setq ang2 (angle cpt pt2))
  36.     (setq a2 (findClosestQuadrantAngle ang2 a1))
  37.     (list a1 a2)
  38. )
  39.  
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.